File: unix.c

package info (click to toggle)
libisds 0.9-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,348 kB
  • ctags: 1,659
  • sloc: ansic: 24,898; sh: 11,772; makefile: 393; xml: 375; sed: 16
file content (26 lines) | stat: -rw-r--r-- 807 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#define _XOPEN_SOURCE   /* for strptime */
#include "../test-tools.h"
#include <time.h>
#include "http.h"

/* Convert UTF-8 @string representation of ISO 8601 date to @time.
 * XXX: Not all ISO formats are supported */
_hidden http_error _server_datestring2tm(const char *string, struct tm *time) {
    char *offset;
    if (!string || !time) return HTTP_ERROR_SERVER;

    /* xsd:date is ISO 8601 string, thus ASCII */
    offset = strptime(string, "%Y-%m-%d", time);
    if (offset && *offset == '\0')
        return HTTP_ERROR_SUCCESS;

    offset = strptime(string, "%Y%m%d", time);
    if (offset && *offset == '\0')
        return HTTP_ERROR_SUCCESS;

    offset = strptime(string, "%Y-%j", time);
    if (offset && *offset == '\0')
        return HTTP_ERROR_SUCCESS;

    return HTTP_ERROR_SERVER;
}