Time

Andrew Pimlott andrew at pimlott.net
Mon Jan 24 11:50:44 EST 2005


On Mon, Jan 24, 2005 at 02:16:16PM +0100, Marcin 'Qrczak' Kowalczyk wrote:
> Keith Wansbrough <Keith.Wansbrough at cl.cam.ac.uk> writes:
> 
> > In particular, people often want to compute with time differences:
> > next week, next month, next year, etc. These are calendar operations,
> > and defining precisely what they mean in edge cases is often tricky.
> > Even discounting leap seconds and the like, "next month" is sometimes
> > 28 days into the future, sometimes 29, sometimes 30, and sometimes
> > 31 - and sometimes makes little sense: when is "31 January 2005 plus
> > one month"?
> 
> We should look how other languages solve that.

The best time library I've used is Perl's DateTime.  (Anyone who thinks
that everything in Perl is a bad hack, please suspend judgement for a
minute!)  It has DateTime, DateTime::Duration, and DateTime::TimeZone
classes (along with a host of supporting players, such as the handy
DateTime::Span), and addresses the various ambiguities.  (Another
example not yet discussed here:  The difference between two times can be
expressed in years, days, hours, or seconds, so the library lets you
choose.)  I believe it gets all the date math right, including leap
seconds.  It is the result of considerable development, use, and
experience with other time libraries.

The project is at

    http://datetime.perl.org/

and if you click the modules link, you can read the documentation.  (As
I write, search.cpan.org seems to be dead, so you'll have to wait for
the documentation.  The FAQ might be useful in the mean time.)

Andrew


More information about the Libraries mailing list