haskell / time

A time library

Home Page:http://hackage.haskell.org/package/time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Parsing of `Day` changed in time-1.11

ChickenProp opened this issue · comments

I realize this is over two years ago now, but we just ran into this while trying to update our stackage LTS to the GHC 9.2 series.

Between 1.10 and 1.11, parsing behavior changed for some format strings. The ones I've noticed all had %-d%-m or similar. For example:

ghci> :set -package time-1.10
package flags have changed, resetting and loading new packages...
ghci> import Data.Time
ghci> parseTimeM True defaultTimeLocale "%-d%-m%0Y" "2122012" :: Maybe Day
Nothing
ghci> parseTimeM True defaultTimeLocale "%-d%-m%0Y" "2132012" :: Maybe Day
Just 2012-03-21

We see that in 1.10, "2122012" refuses to parse, presumably because it's ambiguous where to split the day and month. It could be either (2)(12)(2012) or (21)(2)(2012). But for "2132012", only one of those options is a real date, and we settle on splitting it as (21)(3)(2012).

In 1.11 through 1.12.2, both of these return Nothing. I speculate that we now see that it's ambiguous where to split, and give up before checking date validity.

I don't have a strong opinion on whether this is better or worse, either behavior seems reasonable to me and I assume this isn't something that'll come up often. But it might be worth retroactively adding it to the changelog - that would have helped me track down what was going on.