4 ms·
Correct handling of dates and times in the general case (i.e, arbitrary time zones and arbitrary dates in the past, including calendar and time zone changes) is
by camccann 17y ago
Correct handling of dates and times in the general case (i.e, arbitrary time zones and arbitrary dates in the past, including calendar and time zone changes) is one of those things that I have tentatively filed under "too complicated for me to hope to get right", along with "correct handling of Unicode"[0] and "concurrency with fully shared mutable state"[1].
In practice, my rule is that if you can avoid dealing with the full complexity of date/time, such as by working in absolute time as much as possible and explicitly restricting the allowed date range, then do so; anywhere you have to work with dates/times as non-opaque values, always prefer library functions that explicitly say they conceptually do what you want, not ones that provide low level operations that let you do what you want, probably, at least in your own locale, for now. If your platform provides only a broken date/time implementation, use a third-party library.
Fun anecdote time! When an international group pushed for a standardized, absolute time, the English and French both wanted it to be named in their own language, "coordinated universal time" vs. "temps universel coordonné". The compromise of UTC provided an "acronym" that, by design, didn't make sense to anyone, which I think is somewhat telling about the whole issue. The blog post here gives a good overview of fundamental difficulties, though doesn't really convey the true horror of the subject; I often suspect that a full and complete description of the proper handling for date/times can be found only in an appendix of the Necronomicon, serving as a final deathblow to any last scraps of the reader's sanity.
[0] cf. Michael Kaplan's MSDN blog for a glimpse at all the ways Unicode can go wrong. See how many entries you can read successively until starting to doubt whether written communication was ever actually a good idea! I think my personal record is 14 or so.
[1] cf. anyone who's ever tried. I don't think I need to justify this one.