3 #include <stdlib.h> /* for getenv */
9 static char *tz_orig
; /* Copy of original TZ variable */
12 /* Convert UTF-8 @string representation of ISO 8601 date to @time.
13 * XXX: Not all ISO formats are supported */
14 _hidden isds_error
_isds_datestring2tm(const xmlChar
*string
, struct tm
*time
) {
16 if (!string
|| !time
) return IE_INVAL
;
18 /* xsd:date is ISO 8601 string, thus ASCII */
19 offset
= strptime((char*)string
, "%Y-%m-%d", time
);
20 if (offset
&& *offset
== '\0')
23 offset
= strptime((char*)string
, "%Y%m%d", time
);
24 if (offset
&& *offset
== '\0')
27 offset
= strptime((char*)string
, "%Y-%j", time
);
28 if (offset
&& *offset
== '\0')
35 /* Switches time zone to UTC.
36 * XXX: This is not reentrant and not thread-safe */
37 static void _isds_switch_tz_to_utc(void) {
44 PANIC("Can not back original time zone up");
49 if (setenv("TZ", "", 1))
50 PANIC("Can not change time zone to UTC temporarily");
56 /* Switches time zone to original value.
57 * XXX: This is not reentrant and not thread-safe */
58 static void _isds_switch_tz_to_native(void) {
60 if (setenv("TZ", tz_orig
, 1))
61 PANIC("Can not restore time zone by setting TZ variable");
66 PANIC("Can not restore time zone by unsetting TZ variable");
71 /* Convert UTC broken time to time_t.
72 * @broken_utc it time in UTC in broken format. Despite its content is not
73 * touched, it'sw not-const because underlying POSIX function has non-const
75 * @return (time_t) -1 in case of error */
76 _hidden
time_t _isds_timegm(struct tm
*broken_utc
) {
79 _isds_switch_tz_to_utc();
80 ret
= mktime(broken_utc
);
81 _isds_switch_tz_to_native();