Re-entrant, any-zone mktime()-equivalent?

Jonathan Lennox lennox at cs.columbia.edu
Wed Nov 15 22:41:18 UTC 2000


Has anyone ever developed patches for tzcode to support a function that is
the equivalent of timelocal()/mktime() and timegm() for arbitrary time zones?

What I'm looking for is something that would be the rough equivalent of:

time_t timetz(struct tm *tm, char *tz) {
  time_t t;

  char *oldTZ = getenv("TZ");

  setenv("TZ", tz, 1);
  tzset();

  t = mktime(tm);

  if (oldTZ != NULL) {
    setenv("TZ", oldTZ, 1);
  }
  else {
    unsetenv("TZ");
  }
  tzset();

  return t;
}

However, I'd like to have a function which a) worked correctly in
multi-threaded environments, and b) reported an error message if the
timezone string was invalid, rather than just falling back to GMT.

I need this for a Internet Telephony server which needs to support
time-of-day routing for users in arbitrary timezones, and I want to use the
TZ database names to identify these timezones.  (This is for an
implementation of the Call Processing Language, soon (pending IESG approval)
to be an IETF Proposed Standard.
<http://www.cs.columbia.edu/~lennox/draft-ietf-iptel-cpl-04.txt>.)

Obviously, writing such a function would require some fairly intrusive
hacking on tzcode -- especially since tzcode uses static variables rather
liberally.  Before I start bashing on the code, I'd appreciate any advice
anyone else has, especially if the work's already been done.

Thanks for any advice or pointers anyone can give!

-- 
Jonathan Lennox
lennox at cs.columbia.edu



More information about the tz mailing list