Friday, 27 July 2007

Bug: Dates after 2038-01-19 in Diet Calculator and elsewhere

Arghhh! Perl 5.8 relies upon the underlying C library's {\tt gmtime} function for the Perl {\tt gmtime} function. This means that on a 32-bit platform the Perl function is limited to dates between the start of 1970 and ``doomsday'', 2038-01-19. (I understand that this problem does not exist on native 64-bit platforms and will be fixed in Perl 6.) Even though we have some time to go until the tick of doom, it is easily possible to generate dates beyond 2038 by entering small calorie balance values in the diet calculator. I added a new \verb+Julian::unix_time_to_civil_date_time+ function which uses the Julian day functions to convert a Unix {\tt time()} value to a list of year, month, day of month, hour, minute, seconds (actual values, not the crazy offsets returned by {\tt gmtime}, so this is not a drop-in replacement). I replaced all references to {\tt gmtime} in the program to calls on \verb+unix_time_to_civil_date_time+, which corrects the original problem reported in the diet calculator. There are a few calls on {\tt localtime} left in the code, but these are all in {\tt describe} methods for various objects (used only for administrator debugging output, and all representing times close to the present) and in the generation of log entries, which are also obviously in the present. Since these won't break for more than thirty years, it's likely we'll be on a version of Perl with the truncation fixed before then or, failing that, there's plenty of time to fix them before the dawn of the dreaded day. (Reported by Jim Hollcraft.)

No comments: