8 static char *tz_orig
; /* Copy of original TZ variable */
11 /* Convert UTF-8 @string representation of ISO 8601 date to @time.
12 * XXX: Not all ISO formats are supported */
13 _hidden isds_error
_isds_datestring2tm(const xmlChar
*string
, struct tm
*time
) {
15 if (!string
|| !time
) return IE_INVAL
;
17 /* xsd:date is ISO 8601 string, thus ASCII */
18 offset
= strptime((char*)string
, "%Y-%m-%d", time
);
19 if (offset
&& *offset
== '\0')
22 offset
= strptime((char*)string
, "%Y%m%d", time
);
23 if (offset
&& *offset
== '\0')
26 offset
= strptime((char*)string
, "%Y-%j", time
);
27 if (offset
&& *offset
== '\0')
34 /* Switches time zone to UTC.
35 * XXX: This is not reentrant and not thread-safe */
36 static void _isds_switch_tz_to_utc(void) {
43 PANIC("Can not back original time zone up");
48 if (setenv("TZ", "", 1))
49 PANIC("Can not change time zone to UTC temporarily");
55 /* Switches time zone to original value.
56 * XXX: This is not reentrant and not thread-safe */
57 static void _isds_switch_tz_to_native(void) {
59 if (setenv("TZ", tz_orig
, 1))
60 PANIC("Can not restore time zone by setting TZ variable");
65 PANIC("Can not restore time zone by unsetting TZ variable");
70 /* Convert UTC broken time to time_t.
71 * @broken_utc it time in UTC in broken format. Despite its content is not
72 * touched, it'sw not-const because underlying POSIX function has non-const
74 * @return (time_t) -1 in case of error */
75 _hidden
time_t _isds_timegm(struct tm
*broken_utc
) {
78 _isds_switch_tz_to_utc();
79 ret
= mktime(broken_utc
);
80 _isds_switch_tz_to_native();