Sunday, November 6, 2011

Fun Times: Happy Daylight Savings (US)

Here in the US we're ending daylight savings time ("spring ahead, fall back") and to honor this, this post will be about all of those tricky things about time that affect programming.

There are already some good posts about this issue, but here are some fun facts:

  • In the US west coast, the two time zones uses (yes, there are two) are Pacific Daylight Time (PDT, during the summer) and Pacific Standard Time (PST, during the winter).  When it changes time zones in the fall 1:59 AM PDT is followed by 1:00 AM PST.  This also causes the day to have 25 hours.
  • The US state of Arizona does not observe daylight savings time.
  • Some time zones are not on even hour increments from GMT (i.e. -8 or +3), but can involve minutes as well (GMT +5:30 for Mumbai and GMT +5:45 for Kathmandu).
  • In Java, Calendars are important (but the standard one is the Gregorian Calendar, as far as I know).
  • Time zones are decided by the nation's government, as when Venezuela changed it's time zone in 2007.
  • Usage of GMT is depreciated in technical contexts, and can refer to UTC or UTC1.
  • Windows XP references GMT, but Windows 7 references UTC.
  • UTC and UTC1 are different, but always by less than a second (when it's more there is a leap second).
  • Leap seconds can cause some minutes to have 59 or 61 seconds in them.
  • java.util.Date is really a time stamp from the Epoch, and I find it useful to subclass a "TimeStamp" object for clarity.
  • XKCD has a hilarious comic related to all of this.
  • Birthdays should not be related to the java.util.Date object.  If someone is born on at 11:30 PM and later goes east to another time zone their birthday does not change.
  • When mankind starts doing serious space travel relativity is going to make all of this much worse.
  • I'm sure that there are more things that escape my memory right now, so do not consider this list complete.
All in all, time is one of those "tricky" things.

There are also some libraries that aim to replace the core java.util.Date classes: Date4j and Joda Time.

No comments:

Post a Comment