Time zone confusion and implementation hints

Yves Goergen nospam.list at unclassified.de
Thu Jul 1 19:22:37 UTC 2010


Hi,

I'm currently implementing an API for the tz database that should look
like .NET's TimeZoneInfo class to replace that in my application. The
API includes:

* Convert a date and time from UTC to a time zone
* Convert a date and time from a time zone to UTC
* Return the base UTC offset of a time zone for a date and time
* Return the save offset of a time zone for a date and time
* Determine whether a date and time is ambiguous in a time zone
* Determine whether a date and time is invalid in a time zone

It will come with a code generator that "compiles" the text files into
C# code so that there's no need to deploy additional files with the
application. The API's internal data structures are very similar to the
tz database records, these are already coded.

Currently I'm stuck because of the flexibility of the tz rules. These
can define transition times either in local, standard or universal time.
Additionally, the caller of my API passes a date and time that is either
local or universal. All this needs to be matched correctly. The right
rule needs to be selected and there can be ambiguous or invalid times
all along the way. It's not only hard to implement, it's also hard to
describe, it's very confusing not to have a common base [zone] you can
hold on to.

I have now read about any manpage and code file from the tzcode
distribution, starting with zic.c and going backwards in the list. I
think the file localtime.c does the actual conversion but it's hard to
read because it contains only few comments and uses short all-lowercase
global variable names. I couldn't follow it to its core where the magic
happens.

I have analysed .NET's TimeZoneInfo implementation with .NET Reflector
but it's not half as mighty as what the tz database can express. I also
looked at the C# library ZoneInfo, but it uses an incompatible license,
reads the text files at runtime and last but not least is quite inexact
around transition times which it inacceptable for a calendar
application. Also I think it's a good idea to write my own API for it
because I'll need a Java port later as well, working on the exact same data.

Could somebody assist me in this, please? Are there helpful thoughts to
use when implementing such a programme? Right now my biggest problem is
the transition times and in consequence finding the right rule to use
for a given date and time.

-- 
Yves Goergen "LonelyPixel" <nospam.list at unclassified.de>
Visit my web laboratory at http://beta.unclassified.de




More information about the tz mailing list