New APIs to allow conversion of times in arbitrary zones

lennox at cs.columbia.edu lennox at cs.columbia.edu
Tue May 26 19:36:27 UTC 2009


I did some similar work back in 2001.  See
http://article.gmane.org/gmane.comp.time.tz/81 for a 2004 repost of my
patches, or download the full tz mailing list history for the discussion
from June of 2001.

On Tuesday, May 26 2009, "Guy Harris" wrote to "tz at lecserver.nci.nih.gov" saying:

> 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.
> 
> 
> 
> 



More information about the tz mailing list