Saturday 15 May 2010

How to parse milliseconds using Data.Time in Haskell -



How to parse milliseconds using Data.Time in Haskell -

i have formatted time strings log file of form "08:14:59,012" , parse them utctime (to able create time difference , comparing operations).

i'm unable find way parse milliseconds. here's have far

import system.locale (defaulttimelocale) import data.time (utctime) import data.time.format (readtime) readhms :: string -> utctime readhms = readtime defaulttimelocale "%h:%m:%s" -- ^^ how parse milis? ""%h:%m:%s,%q" doesn't work test = readhms "08:14:59,012"

please suggest way parse milliseconds test above contains them.

even though there isn't format milliseconds, can utilize format picoseconds %q if scale milliseconds correctly. luckily, can done appending fixed number of zeros, resulting string has 12 characters after comma:

readhms = readtime defaulttimelocale "%h:%m:%s,%q" -- ^^^ -- vvvvvvvvvvvvvvvvvv test = readhms $ "08:14:59,012" ++ replicate 9 '0'

haskell

No comments:

Post a Comment