Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Year 2038

by InfiniteLoop (Hermit)
on Dec 27, 2005 at 21:39 UTC ( [id://519428]=perlquestion: print w/replies, xml ) Need Help??

InfiniteLoop has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I bring to you yet another date manipulation query. Recently, one of my modules was acting strangely when the user entered some date in year 2038 and beyond. After some reading, I found that this is an issue with the unix epoch date time calculation (my system runs on Linux + Apache).


I have seen the Gnome calendar (gnome 2.10), display calendar/dates beyond 2038, so Im sure that this can be handled. I seek your guidance on this issue.


P.S: I use Date::Time and Time::Piece modules

Replies are listed 'Best First'.
Re: Year 2038
by esskar (Deacon) on Dec 27, 2005 at 22:30 UTC
Re: Year 2038
by adrianh (Chancellor) on Dec 28, 2005 at 01:47 UTC
    I have seen the Gnome calendar (gnome 2.10), display calendar/dates beyond 2038, so Im sure that this can be handled. I seek your guidance on this issue.

    Use modules like Datetime that don't have 2038 issues.

Re: Year 2038
by rinceWind (Monsignor) on Dec 28, 2005 at 01:14 UTC

    Yep, my colleagues who look after the repo system encountered this one last year, as a result of the introduction of 50 year French Bonds. When they were introduced, the Excel add-on that is used for analysis, fell over. This has since been corrected, and the main repo system does not need to project forward 50 years.

    The long term step expected to fix this problem, will be the upgrading of our Sybase databases to 64 bit, including migration of the date fields to 64 bits, which is largely complete.

    We also were asked to look into the impact on other systems, such as swaps (my area). Swaps run for a maximum of 30 years, but it has been noted that we could have an issue in February 2008 that we need to plan for. This has been deemed "low priority" compared with much other work that is happening, but it's probably worth reminding my business users that we _should_ do a full regression test with the date moved forward to Feb 2008 and beyond, so that we don't get any nasty surprises.

    --

    Oh Lord, won’t you burn me a Knoppix CD ?
    My friends all rate Windows, I must disagree.
    Your powers of persuasion will set them all free,
    So oh Lord, won’t you burn me a Knoppix CD ?
    (Missquoting Janis Joplin)

      will be the upgrading of our Sybase databases to 64 bit, including migration of the date fields to 64 bits
      Don't you use a DATETIME column for those dates? (datetime handles dates up to the year 9999...)

      And if you're going to 64bit ints in the database I assume you're moving to ASE 15.0? (ASE 15.0 has the BIGINT datatype, though I suppose you could be using a NUMERIC() for this as well)

      Michael

Re: Year 2038
by ruoso (Curate) on Dec 28, 2005 at 13:00 UTC

    Well, That's the reason I did stop using epoch numbers when manipulating dates. I'd prefer to stick with a date format like ISO$SomeNumberIDontRemember8601 (YYYY-MM-DD HH:MM:SS TZ). This way you won't fall into this type of weirdness, but you won't fall into some common hard-to-track miscalculations like:

    • Not everyday has 24 hours, some have 23 and some have 25... so adding 86400 seconds is not really increasing one day...
    • Epoch numbers can't care about timezone. When you have your system running on different timezones, you really want to keep the date and time given by the user and save his timeone...(1)
    • You'll end using a module that does implement everything you really should care about... please take a look at DateTime...

    (1) Well, just to illustrate: Imagine the accounts department of company X in Japan uses the same machine the accounts departament in US. What would happen if you forget about the timezone and convert to epoch numbers?

    Well, you will see 2006-01-01 6:00am (Japan TZ), You will convert it to epoch number in that TZ... When people in Japan look the register and will see 2006-01-01 6:00am, but the guys in US will see 2005-12-31 6:00pm (US TZ). Looking by one side, it's correct, because 2006-01-01 6:00am on Japan really was 2005-12-31 6:00pm in US, but that can cause a HUGE confusion...

    So, my recommendation is to ALWAYS store the date in a format that allows you to store the TZ, and ALWAYS display the date in the format it was entered, displaying the TZ on which it was entered.

    daniel
        That one! Thanks
        daniel

      Well, you will see 2006-01-01 6:00am (Japan TZ), You will convert it to epoch number in that TZ... When people in Japan look the register and will see 2006-01-01 6:00am, but the guys in US will see 2005-12-31 6:00pm (US TZ). Looking by one side, it's correct, because 2006-01-01 6:00am on Japan really was 2005-12-31 6:00pm in US, but that can cause a HUGE confusion...

      I agree with you that storing the local timezone of an event along with the event is a good idea: it can yield some useful additional information about the event. But what's far more important is the time when the event actually occured. You can store enough information to know both the local time and the normalized time if you want but by default you should present information about the normalized time to the user since times that may or may not be in the user's local timezone are useless for knowing when an event occured. I disagree that your example could cause HUGE confusion. In fact, I think that your proposal can cause HUGE confusion! If different users in the accounts department in different local timezones entered several transactions in the same day, how can you make sense of what happened in what order unless the times are all presented in the same time zone (be it the local timezone for you, the observer, UTC, or any other chosen timezone)? What about triggered events that automatically occured on the account. What timezone should they be presented in, if not the same, normalized, timezone as everything else?

      Maybe I've dealt with too many trouble tickets involving a customer, a callcentre, myself, all in different timezones, with the trouble itself being on a WAN spanning multiple timezones, and the monitoring systems not all in the same time zone, but I have a great need to have information presented to me in a standard timezone in order to make sense of any of it!

      Not everyday has 24 hours, some have 23 and some have 25... so adding 86400 seconds is not really increasing one day...

      I think you are talking about daylight savings time. I hope you are lucky enough to live in an area that does not practice this stupid ritual because it causes problems no matter what you do. If you use "epoch numbers" then adding 86400 may give you a different time of day on the next day however it is guaranteed to give you the time 24 hours away. On the other hand when using a time format like ISO8601 you can do arithmetic on the date portion (carefully, because of leap years and such), but adding one to the hour may yield an impossible, ambiguous, or duplicate time.

        I disagree that your example could cause HUGE confusion. In fact, I think that your proposal can cause HUGE confusion! If different users in the accounts department in different local timezones entered several transactions in the same day, how can you make sense of what happened in what order unless the times are all presented in the same time zone (be it the local timezone for you, the observer, UTC, or any other chosen timezone)?

        I agree, in part, to what you said. It is needed to show the complete information to the user, we need one step further in the user interfaces. The display of dates should include the information about the timezone and should provide a way to the user easily see that time in his timezone.

        I mean, in some activities, the day of the year represents much information (like, it's on this fiscal year or the next?) but you still want to store the hour and the timezone, right?...

        What about triggered events that automatically occured on the account. What timezone should they be presented in, if not the same, normalized, timezone as everything else?

        This is, certainly, a problem. But you can still do some tricks, like, setting the timezone to UTC for system events and always you have UTC display as the local timezone. And setting to WET when the date is triggered by a user on the GMT timezone, for example.

        On the other hand when using a time format like ISO8601 you can do arithmetic on the date portion (carefully, because of leap years and such), but adding one to the hour may yield an impossible, ambiguous, or duplicate time.

        That's the reason you should use a module like DateTime to do such arithmetics. It takes care about this type of issues. And if it doesn't for some issues, that's the place to implement such things...

        daniel
      In my not-particularly-humble opinion, times and dates should always be stored in UTC. Then whatever program it is that uses those times and dates - your automagic bill payment thingy, your user interface etc - should convert to and from the local timezone as necessary.

      Having everything stored in UTC makes it easier to figure out what's going wrong when you make the inevitable mistakes.

        Nah, UTC is too complicated - it's linked to the earth rotation, both around its axis and around a well known star. You'll have to deal with leap seconds and such - and, if the Americans have their way, leap hours.

        Anyone serious about time keeping will use TAI.

        Perl --((8:>*
Re: Year 2038
by blue_cowdawg (Monsignor) on Dec 27, 2005 at 21:56 UTC
        when the user entered some date in year 2038 and beyond.

    Hmmmm... In 2038 I'll be 83 years old.... not sure I'll be doing any programming then... :-)

      I'm sure that's what a lot of old programmers were saying about Y2K. :)
      Yeah, but the OP's module might be used by your pension fund...
      Perl --((8:>*
Re: Year 2038
by kulls (Hermit) on Dec 28, 2005 at 04:57 UTC
    The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer).

    I guess this may help you some extend.
    -kulls
Re: Year 2038
by zentara (Archbishop) on Dec 28, 2005 at 12:49 UTC
    Hi! I guess you will have to work out a way of testing for dates past 2037 and making adjustments. Here are a few snippets that shows you the problem and a work around fix. (Not tested to government standards :-) )
    #!/usr/bin/perl #this shows where you run out of seconds and the #signed 32 goes negative. $secs_non_leap = 60 * 60 * 24 * 365; # seconds per non-leap year $secs_leap = 60 * 60 * 24 * 366; # seconds per leap year $secs = hex "7FFFFFFF"; # max number a signed 32 can hold foreach $year (1970 .. 2040) { $leap = $year % 4 ? 0 : 1; $secs -= $leap ? $secs_leap : $secs_non_leap; print "$year $secs\n"; }
    -----And a fix------------------------------------------------
    #!/usr/bin/perl use warnings; use strict; use Date::Manip; my $far_date = UnixDate(ParseDate("40 years 20 minutes"),"%s"); print "40 years and 20 minutes from now is: ", $far_date,"\n"; print "epoch $far_date seconds translate to: ", UnixDate(ParseDate("epoch $far_date"),"%m/%d/%Y %H:%M:%S"),"\n";

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://519428]
Approved by saberworks
Front-paged by tye
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-16 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found