@@ -326,13 +326,13 @@ tabFilter tabStop =
326326
327327-- | Parse a date and convert (if possible) to "YYYY-MM-DD" format. We
328328-- limit years to the range 1601-9999 (ISO 8601 accepts greater than
329−-- or equal to 1583, but MS Word only accepts dates starting 1601.
329+-- or equal to 1583, but MS Word only accepts dates starting 1601).
330330normalizeDate :: String -> Maybe String
331−normalizeDate s = case toGregorian <$> day of
332− Just (y, _, _) | y >= 1601 && y <= 9999 ->
333− fmap (formatTime defaultTimeLocale "%F") day
334− _ -> Nothing
335− where day = (msum $ map (\fs -> parsetimeWith fs s) formats :: Maybe Day)
331+normalizeDate s = fmap (formatTime defaultTimeLocale "%F")
332+ (msum $ map (\fs -> parsetimeWith fs s >>= rejectBadYear) formats :: Maybe Day)
333+ where rejectBadYear day = case toGregorian day of
334+ (y, _, _) | y >= 1601 && y <= 9999 -> Just day
335+ _ -> Nothing
336336 parsetimeWith =
337337#if MIN_VERSION_time(1,5,0)
338338 parseTimeM True defaultTimeLocale