Any way to read in a time?

David Roundy droundy@jdj5.mit.edu
Fri, 18 Oct 2002 15:15:44 -0400


I've been looking at the standard Time module, and it seems pretty easy to
convert a date into a string (using either calendarTimeToString or
formatCalendarTime), but there doesn't seem to be any way to reverse the
process.

I understand that there are so many date and time formats that it may be
hard to parse, and that for many formats there may be no unambiguous
translation back into a CalendarTime (e.g. if the time zone isn't included
in the string), but it seems like a pretty fundamental (and commonly
needed) ability to be able to output a human-readable date and then read it
back in.

Does anyone have a suggestion how best to go about this? I guess the
easiest way might be to just convert to UTC and then use formatCalendarTime
to choose what formatting I want and then write my own parser to reverse
the process.  But this seems like a process with a relatively high
probability of introducing rarely seen bugs, which ought to be dealt with
by a standard library.

Of course, there are also a couple of other workarounds I could use.
CalendarTime derives from Show, so I could just output the result of show,
but that's an awfully verbose format.  I could also give up on comparing
dates (which I don't necesarily need, although it is nice) and just treat
dates as strings.

Any ideas or commentary would be welcome.
-- 
David Roundy
http://civet.berkeley.edu/droundy/