haskell / time

A time library
http://hackage.haskell.org/package/time
Other
119 stars 79 forks source link

Read instance for strings w/o timezone has unclear fatal error message #207

Closed jmtd closed 2 years ago

jmtd commented 2 years ago

With time-1.8.0.2:

λ> read "2013-01-01 00:00:00" :: UTCTime
2013-01-01 00:00:00 UTC

With time 1.9:

λ> read "2013-01-01 00:00:00" :: UTCTime
*** Exception: Prelude.read: no parse

There was nothing obvious in the changelog, except

adding a TZ specifier works:

λ> read "2013-01-01 00:00:00 +0000" :: UTCTime
2013-01-01 00:00:00 UTC

But since I'm not - directly - using the parsing function (indirectly via Read), this wasn't immediately obvious. The runtime error "no parse" is also not helpful. Is there any chance this can be improved?

AshleyYakeley commented 2 years ago

This is already fixed in 1.11.1.1. (Not sure which version fixed it.)

ghci> read "2013-01-01 00:00:00" :: UTCTime
2013-01-01 00:00:00 UTC
jmtd commented 2 years ago

Thank you: Sorry, it didn't occur to me to check the latest version (It should have). I had been thinking, in my case, these are basically static instances of UTCTime used for testing purposes. More ideal -- in my code base -- than relying on read would perhaps be hard-coding the UTCTime instance using constructors, but that proved complex enough to unwind that I gave up. I should look at that again.