Tugger the SLUGger!SLUG Mailing List Archives

Re: [SLUG] Best API/abstraction?


I second Perl's DateTime module.

It is by far the best time API I've ever seen, if only because it
utterly refuses to give you an answer that isn't strictly valid, and
throws exceptions if you blink at it wrong.

This results in a very rapid learning process where by you are forced
to learn how to phrase the question you REALLY want answered instead
of just asking it naively and getting garbage-in garbage-out problems
later.

Once you've adapted to things like always giving it timezones (because
there's lots of things it won't answer with floating timezones) and
understanding that it's going to answer "How long from 2:30am today
until 2:30am tomorrow" with simultaneous answers in days, hours and
seconds (all three of which won't divide into each other necessarily)
you really appreciate it.

I've yet to see anything else that is even close.

Adam K

On 7 April 2010 15:14, Daniel Pittman <daniel@xxxxxxxxxxxx> wrote:
> Jeff Waugh <jdub@xxxxxxxxxxxxxx> writes:
>> <quote who="Jamie Wilkinson">
>>
>>> I for one am glad such pages exist.  I wish the inventors of time_t had
>>> read it.
>>
>> So which language / library has a great abstraction for time and date stuff,
>> helping you deal with the intricacies of this craziness?
>
> None of them.  Even the good languages have nasty side-bits like a "don't be
> broken" switch, and even a perfect language would still have the pain of
> dealing with political, not technical, issues like timezone-associated dates.
>
> Oh, and the fact that date math is *not* simple, since you can't convert
> between various durations; a question such as "how many seconds in a week" can
> only be answered "it varies..."
>
>
> FWIW, the link I posted earlier was about time handling in Common Lisp, which
> gets this less wrong than most platforms ... but that document was written
> because the standard was imperfect.
>
> Perl, meanwhile, has good support in various non-core library modules, but
> many of those have things like a "$Class::Date::DST_ADJUST" value to determine
> which behaviour you want for math involving DST and/or leap-seconds.
>
>
> As an example of a well-documented set of complications and how they are
> handled, the DateTime module does well:
>
> http://search.cpan.org/~drolsky/DateTime-0.55/lib/DateTime.pm#How_Datetime_Math_is_Done
>
> After you read through the 250 lines of warnings, complications, caveats, and
> examples of how you can have two completely correct, valid, sensible results
> that are absolutely in contradiction with each other...
>
> Heh.
>
> Time.  Boy, does it suck. :)
>        Daniel
>
> --
> ✣ Daniel Pittman            ✉ daniel@xxxxxxxxxxxx            ☎ +61 401 155 707
>               ♽ made with 100 percent post-consumer electrons
> --
> SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
> Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html
>