parseCalendarTime

Bjorn Bringert d00bring at dtek.chalmers.se
Thu Mar 25 19:20:29 EST 2004


System.Time has

formatCalendarTime :: TimeLocale -> String -> CalendarTime -> String

but no parseCalendarTime. After writing a few inflexible single purpose 
date parsing functions I decided that it would be easier to just write 
one that takes a formatting string. I have written a

parseCalendarTime :: TimeLocale -> String -> String
                      -> Maybe CalendarTime

which accepts all format specifiers that formatCalendarTime accepts. It 
is far from perfect (19 FIXMEs last time I checked), but it should work 
for most common cases. The output is not neccessarily a valid date, as 
the date format used may not contain enough information, and no attempt 
is made to calculate or validate, for example, the day of the week or 
the number of days in a month. A CalendarTime is used here as a 
"slightly more tractable representation of a date/time string" [1].

The code is available at: 
http://www.dtek.chalmers.se/~d00bring/misc/ParseDate.hs

The code is extremely untested. All comments, bug reports, flames and 
suggestions for improvement are welcome.

/Bjorn Bringert

[1] http://www.haskell.org/pipermail/haskell-cafe/2002-December/003758.html



More information about the Libraries mailing list