1 #include "../../config.h"
2 #define _XOPEN_SOURCE XOPEN_SOURCE_LEVEL_FOR_STRDUP
3 #include "../test-tools.h"
9 static void yday2mday(struct tm
*time
) {
10 static int mtab
[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
11 int i
, year
= 1900 + time
->tm_year
;
13 mtab
[1] = (!(year
% 4) && ((year
% 100) || !(year
%400))) ? 29 : 28;
14 time
->tm_mday
= time
->tm_yday
+ 1;
16 for (i
= 0; i
< 12; i
++) {
17 if (time
->tm_mday
> mtab
[i
]) {
18 time
->tm_mday
-= mtab
[i
];
27 /* Convert UTF-8 @string representation of ISO 8601 date to @time.
28 * XXX: Not all ISO formats are supported */
29 http_error
_server_datestring2tm(const char *string
, struct tm
*time
) {
32 if (!string
|| !time
) return HTTP_ERROR_SERVER
;
34 memset(time
, 0, sizeof(*time
));
36 if (sscanf(string
, "%d-%d-%d%n",
37 &time
->tm_year
, &time
->tm_mon
, &time
->tm_mday
, &tmp
) >= 3
38 && tmp
== strlen(string
)) {
40 time
->tm_year
-= 1900;
41 return HTTP_ERROR_SUCCESS
;
44 memset(time
, 0, sizeof(*time
));
46 if (sscanf(string
, "%d-%d%n",
47 &time
->tm_year
, &time
->tm_yday
, &tmp
) >= 2
48 && tmp
== strlen(string
)) {
50 time
->tm_year
-= 1900;
52 return HTTP_ERROR_SUCCESS
;
55 memset(time
, 0, sizeof(*time
));
59 return HTTP_ERROR_SERVER
;
64 if (sscanf(ptr
+ len
- 2, "%d%n", &time
->tm_mday
, &tmp
) < 1 || tmp
< 2) {
66 return HTTP_ERROR_SERVER
;
71 if (sscanf(ptr
+ len
- 4, "%d%n", &time
->tm_mon
, &tmp
) < 1 || tmp
< 2) {
73 return HTTP_ERROR_SERVER
;
78 if (sscanf(ptr
, "%d%n", &time
->tm_year
, &tmp
) < 1 || tmp
< len
- 4) {
80 return HTTP_ERROR_SERVER
;
85 time
->tm_year
-= 1900;
86 return HTTP_ERROR_SUCCESS
;