New APIs to allow conversion of times in arbitrary zones
Guy Harris
guy at alum.mit.edu
Tue May 26 18:00:03 UTC 2009
For the benefit of programs such as world clocks and any other program
that would need to convert times in an arbitrary zone specified by a
TZ setting, I've added some APIs to load time zone information for a
specified zone, free that time zone information, and convert between
time_t and struct tm in specified zones:
zoneinfo_t loadzone(const char *zonename)
Attempts to allocate and fill in a structure to hold information for
the time zone specified by "zonename"; returns a pointer to the time
zone information on success and NULL on failure.
void freezone(zoneinfo_t zoneinfo)
Frees zone information returned by loadzone().
struct tm *localtime_zr(const time *clock, struct tm *result,
zoneinfo_t zoneinfo)
Like localtime_r(), but does the conversion in the time zone specified
by zoneinfo.
time_t mktime_z(struct tm *timeptr)
Like mktime(), but does the conversion in the time zone specified by
zoneinfo.
zoneinfo_t is implemented, internally, as a pointer to a "struct
state", but it's opaque to the callers.
I'm not committed to any of the names, or the order of the arguments;
for example, "loadzone()" doesn't necessarily load information from a
file - it might parse a POSIX-style TZ string - so that might not be
the right name.
The new functions are declared in an "xtime.h" public header (the name
was inspired by the BSD "xlocale.h" header that declares functions
such as printf_l() which take a locale information pointer as an
argument).
See the attached patch and "xtime.h" file.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: patch
Type: application/octet-stream
Size: 16699 bytes
Desc: not available
Url : http://mm.icann.org/pipermail/tz/attachments/20090526/44ccb2e0/patch-0001.obj
-------------- next part --------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xtime.h
Type: application/octet-stream
Size: 742 bytes
Desc: not available
Url : http://mm.icann.org/pipermail/tz/attachments/20090526/44ccb2e0/xtime-0001.h
-------------- next part --------------
More information about the tz
mailing list