SLUG Mailing List Archives
Re: [SLUG] Best API/abstraction?
- To: slug@xxxxxxxxxxx
- Subject: Re: [SLUG] Best API/abstraction?
- From: Adam Kennedy <adamkennedybackup@xxxxxxxxx>
- Date: Thu, 15 Apr 2010 13:44:41 +1000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:reply-to:in-reply-to :references:date:received:message-id:subject:from:to:content-type :content-transfer-encoding; bh=aW+mPDI/S7GyXy8mixb6VE/p1ukoisutWVbHLFMsMsI=; b=PKZA9+YKm9edYCPiReDPGxM3mArGGhvJl+COD1Z7vHnxhhROe2VXAlvKyu0IH1A7/x DCW9kKT3C9FCrgAFhCxVmRT1/SpwUh0IGKwye9NV7oxvQlP0nfZioJaoOLQ9eVIQBWt5 DMfKhfAOV8W1SmyjBhcwtg9ncoRjnzWdL3zF0=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:reply-to:in-reply-to:references:date:message-id :subject:from:to:content-type:content-transfer-encoding; b=Hr/FhbzWnWcjTBaQQ5KQYHBh1E2EK/mwPR2PzPsywxF3a4LIRuWsheQwZO23RHBTVa C2uwi7uyQoPfMrUosW8Wf6QDqlP5Q6UMJ1xVjWcZzGhjpcQOjxDyn/LJDqVYFHqdelaN 4df/2Zx81GiGPQD+fiEt+Rv7iSJ8slgyK9CFc=
- Reply-to: adam@xxxxxx
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
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.
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:
> 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...
> Time. Boy, does it suck. :)
> ✣ 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