[Haskell-cafe] string to date?

Bjorn Bringert bringert at cs.chalmers.se
Thu Nov 9 19:27:32 EST 2006


On 10 nov 2006, at 00.29, Magnus Therning wrote:

> On Thu, Nov 09, 2006 at 20:43:36 +0100, Björn Bringert wrote:
>> Dougal Stanton wrote:
>>> Quoth Magnus Therning, nevermore,
>>>> I've been staring my eyes out trying to find a function that  
>>>> converts a
>>>> string into a ClockTime or CalendarTime.  Basically something  
>>>> like C's
>>>> strptime(3).  I can't seem to find anything like it in System.Time,
>>>> there are function that convert _to_ a string, but nothing that  
>>>> converts
>>>> _from_ a string it seems.  Where should I look?
>>> The MissingH.Time.ParseDate [1] module might be what you want.  
>>> There's
>>> also one from Bjorn Bringert [2]. I haven't used either though, so I
>>> can't recommend anything between them.
>>> Cheers,
>>> D.
>>> [1]: <http://quux.org:70/devel/missingh/html/MissingH-Time- 
>>> ParseDate.html>
>>> [2]: <http://www.cs.chalmers.se/~bringert/darcs/parsedate/>
>>
>> Those two are the same code. I have a preliminary new version  
>> which can also
>> parse most of the types from the time package (Data.Time.*)  
>> available at:
>>
>> http://www.cs.chalmers.se/~bringert/darcs/parsedate-2/
>
> I noticed one thing when playing around with  
> ParseDate.parseCalendarTime
> in ghci:
>
>> parseCalendarTime System.Locale.defaultTimeLocale "%Y" "2006"
>  Just (CalendarTime {ctYear = 2006, ctMonth = January, ctDay = 1,  
> ctHour = 0, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay = Thursday,  
> ctYDay = 1, ctTZName = "UTC", ctTZ = 0, ctIsDST = False})
>> parseCalendarTime System.Locale.defaultTimeLocale "%Y%m%d" "20061109"
>  Nothing
>> parseCalendarTime System.Locale.defaultTimeLocale "%C%y%m%d"  
>> "20061109"
>  Just (CalendarTime {ctYear = 2006, ctMonth = November, ctDay = 9,  
> ctHour = 0, ctMin = 0, ctSec = 0, ctPicosec = 0, ctWDay = Thursday,  
> ctYDay = 1, ctTZName = "UTC", ctTZ = 0, ctIsDST = False})

Hi Magnus,

thanks for the bug report. I have fixed this now in the version of  
the library available from
http://www.cs.chalmers.se/~bringert/darcs/parsedate/

I intend to retire that version, and instead switch to the new  
implementation available at
http://www.cs.chalmers.se/~bringert/darcs/parsedate-2/
This supports both CalendarTime and the new much nicer Data.Time  
types. However, the implementation is still incomplete (about as  
complete as the old version I think). It is missing support for week  
date formats and the like, and there is no test suite or QuickCheck  
properties (and thus there are surely lots of bugs).

By the way, if you want to be sure that I see your bug reports about  
any of the libraries I maintain, please to cc the reports to me, or  
send them to me directly.

/Björn


More information about the Haskell-Cafe mailing list