Date and Time libraries in various languages
Can a correct, or even sensible Date, Time and Calendar library be designed, for any programming language at all, ever, by anybody, genius, time expert, or not? Certainly Java’s Date API isn’t very inspiring, but some systems do manage to do better: here’s a quick survey of the state of Date/Time/Calendar libraries in a few different languages.
Scheme’s SRFI 19 is, overall, an excellent library at its core (i.e. the specification of Time objects), but suffers from a number of bugs in its reference implementation, some quite serious, and lacks support for the timezone database.
Things may be looking up for Time processing in Java: the Joda Time library looks like it’s designed around the key separation of Instants, Intervals, and Durations from Calendar-related notions such as Dates, Times, and human-readable representations of time. The evidence suggests it may even deal with timezones properly.
Even C’s venerable time implementation (it’s an int! Everything’s an int!) is better than that provided by many languages. At least it’s correct and reasonably simple. The main flaw in it is the way that the current timezone is not even a global variable - it’s an environment variable. Trying to treat it as a parameter is an exercise in frustration, making timezone calculations far, far more difficult than they need to be.
Squeak currently has two major libraries: Chronology, the incumbent, and the comprehensive-looking newcomer Chronos. I’ve only ever used Chronology, but I can definitely say it was a very pleasant experience compared to every other language and date/time library I’ve ever used. Chronology doesn’t really do timezones (or leap seconds), and from that point of view Chronos is a significant improvement. Chronos looks very promising, but loading it broke my image (timestamping doits broke during save and quit) so I’ve not explored it in any detail.
3 comments May 5th, 2006 tonyg