Looking for advices regarding tzdata

Dmitri Pal dpal at redhat.com
Fri Oct 24 18:49:32 UTC 2008


I am new to tzdata and advanced time zone conversion technics that it 
I read couple articles about tzdata on wikipedia and in man pages.
So far I do not see what I am looking for so may be it just does not exist.

Here is what I am trying to accomplish.

YYYYMMDDHHMMSS - date or some other date format that can be easily 
broken into tm structure.
TZ information - I was hoping to use some kind of meaningful string so 
time zone names. Names from zone.dat would work perfectly.


Number of seconds since 1 Jan 1970 in UTC time that corresponds to the 
time stamp

* The function that would do the conversion needs to parse and validate 
the format before conversion can happen. That includes validating the TZ 
* Would be nice to use standard libc functions to do this conversion as 
much as possible

What is missing:
I am currently on Red Hat Enterprise Linux 5.1. It has 
/usr/share/zoneinfo and there I found zone.dat.
Is there any function or set of functions that allow me to interact with 
this database like:
get_next_timezone_name - to iterate through the list and get the 
timezone. Is there any abstraction around this file?
In different distributions it can be in different places and under 
different names. But libc functions hide this complexity so is there any 
API that will let me to enumerate timezones and or check if the 
XXXX/YYYY is the correct valid time zone name without dealing with the 
file myself?

Also the other part is determining the daylight savings at the moment of 
conversion in the specified time zone?
Would it be something like breaking the input I have into the tm 
structure , calling tzset(timezonename) and then  call mktime?
              #include <time.h>
              #include <stdlib.h>

              time_t my_time (struct tm *tm, char *timezonename) {
                  time_t ret;
                  char *tz;

                  tz = getenv("TZ");
                  setenv("TZ", timezonename, 1);
                  ret = mktime(tm);
                  if (tz)
                      setenv("TZ", tz, 1);
                  return ret;
This example is based on the timegm example but seems to contradict 
mktime man page that states that mktime sets the timezone variable itself.
In other words I can populate a part of the tm from the data I have but 
I need to populate the tm_isdst based on the timezone.
Would the code above accomplish the task?

I feel like something might be wrong with this but I am not sure what.
So this is where I am and I am bit lost. Please advise.

Thank you
Dmitri Pal

More information about the tz mailing list