LWN.net Logo

not using zoneinfo

not using zoneinfo

Posted Mar 10, 2007 1:36 UTC (Sat) by nix (subscriber, #2304)
In reply to: not using zoneinfo by ldo
Parent article: Switching your Linux systems to the new DST (Linux-Watch)

They do use the standard C runtime API calls: but if you want to ask what
the time is in something other than the current locale, or if you want to
make any query of the timezone database other than `what time is it now'
(perhaps `when does the time change next' or `will the time jump in the
next day') then POSIX provides no interfaces that will help (and neither
does glibc, nor will it ever, apparently).

So in that situation you must either locate and directly access the system
timezone database, or ship your own and suitable query code. (PostgreSQL
does the latter so that it can implement timestamps, WITH TIME ZONE types,
and so forth.)


(Log in to post comments)

not using zoneinfo

Posted Mar 11, 2007 1:36 UTC (Sun) by ldo (subscriber, #40946) [Link]

All the things you mentioned can be determined from the standard zoneinfo database. I could probably even calculate them all just by using the standard POSIX API calls.

Repeat after me: "Always use zoneinfo! Never try to roll-your-own!"

Blame POSIX

Posted Mar 11, 2007 10:53 UTC (Sun) by kleptog (subscriber, #1183) [Link]

PostgreSQL does use the zoneinfo database, they just modified the code to make it more usable. Until recently the zoneinfo database was 100% compatable so you could symlink them with the version supplied by the OS. (Upstream added support for leap-seconds, which changed the disk format). The reasons why PostgreSQL uses its own are:

1. Access to multiple timezones. The only way to do that in POSIX is to set the TZ environment variable. Which means that if you run a query using two timezones, the C library would reload the timezone file twice for every row in your query. Say goodbye to performance.

2. Cross-platform support. Not every OS uses zoneinfo (*cough*Windows*cough*), so if you want consistant query results across 11 OSes, you need to manage it yourself.

3. Stability. Not every C library was memory-leak free when faced with hundreds of timezone changes per second.

If the writers of POSIX had simply from the beginning decided to allow the timezone as an argument to the time functions, this would be much less of an issue. Recently I looked at glib, figuring it might handle this. But no, it also assumes your whole program only wants to work in one timezone. Ugh.

I made a plugin to Gaim to display the times of other users. I also copied the zoneinfo code into that, because it's a big no-no for plugins to start playing with environment variables, especialy those with such a wide effect as TZ... Yes, Glibc can do it, but there's always the *but it doesn't work on Windows* crew...

Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds