[Haskell-cafe] Can't do basic time operations with System.Time

John Goerzen jgoerzen at complete.org
Thu Jan 20 17:11:55 EST 2005


I have a simple desire.  I have a string that I need to parse as a
date/time string in the local timezone, then convert it to standard
seconds-since-epoch format.  This is trivial in C, Perl, Python, etc.
but seems impossible to do reliably in Haskell.  I'm hoping someone can
tell me where I've gone wrong.

My initial idea was to parse the string, generate a CalendarTime object,
use toClockTime to convert it to seconds-since-epoch, and then grab the
value out of that.  There were some problems, though: what to put in
ctTZ and ctIsDST?  I initially loaded them with 0 and False, though that
turned out to be clearly wrong.

My next idea was to take the ctTZ result from toCalendarTime, then use
that for all the CalendarTime objects I'd generate.  That was wrong,
too, during daylight savings time.  I don't think I should have to
re-implement the algorithms for determining whether a given date is
under DST worldwide.

What I really need is just a wrapper around mktime() that just calls
mktime and doesn't do anything else.  All the post-processing that
System.Time is doing is what's causing me trouble.  I'd just like it to
ignore ctTZ, ctTZName, and ctIsDST.  That would yield behavior identical
to the C library.

-- John

More information about the Haskell-Cafe mailing list