Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

schwern (1528)

  (email not shown publicly)
AOL IM: MichaelSchwern (Add Buddy, Send Message)

Schwern can destroy CPAN at his whim.

Journal of schwern (1528)

Monday September 15, 2008
10:36 PM

Y2038: How Does It Work?

[ #37456 ]

The y2038 project is unique amongst the 32 bit fixes for the 2038 bug in that it does all three of these:

A) Is compatible with the standard time.h C library
b) Handles time zones
3) Does not ship its own time zone database

For example, libtai is awesome, but it doesn't support time zones and doesn't look much like time.h.

The decision not to ship its own time zone database is important. They contain not only time zones but daylight savings time. They are bizarre and archaic and a job best left to somebody else. When they fail to be updated, bad things happen. Things I do not want to be responsible for. Time zone databases are part of your system and get updated, quietly, with your system. I don't want the user to have to update a second time zone database.

The C interfaces for talking to the time zone interface are very poor and not very standardized. localtime() and mktime() are about all you can rely on. But localtime() was the start of the whole problem in the first place!

y2038's implementation of localtime() relies on the fact that you can map any calendar year to another calendar year. Once you realize that, you can map a date after 2038 to a date before 2038 and take advantage of the 32 bit system functions!

Of course, it's not quite so easy. The calendar cycle is 400 years long. The range of 32 bit localtime() is 138 years. But I came up with an algorithm to account for that and map 400 years into just 28. You can read about it here.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.