Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Year 2038

by ruoso (Curate)
on Dec 28, 2005 at 13:00 UTC ( [id://519535]=note: print w/replies, xml ) Need Help??


in reply to Year 2038

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

Replies are listed 'Best First'.
Re^2: Year 2038
by trammell (Priest) on Dec 28, 2005 at 15:19 UTC
      That one! Thanks
      daniel
Re^2: Year 2038
by Celada (Monk) on Dec 29, 2005 at 21:37 UTC

    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
Re^2: Year 2038
by DrHyde (Prior) on Jan 06, 2006 at 10:15 UTC
    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:>*

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://519535]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found