@@ -324,17 +324,22 @@ tabFilter tabStop =
324324-- Date/time
325325--
326326
327−-- | Parse a date and convert (if possible) to "YYYY-MM-DD" format.
327+-- | Parse a date and convert (if possible) to "YYYY-MM-DD" format. We
328+-- 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.
328330normalizeDate :: String -> Maybe String
329−normalizeDate s = fmap (formatTime defaultTimeLocale "%F")
330− (msum $ map (\fs -> parsetimeWith fs s) formats :: Maybe Day)
331− where parsetimeWith =
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)
336+ parsetimeWith =
332337#if MIN_VERSION_time(1,5,0)
333338 parseTimeM True defaultTimeLocale
334339#else
335340 parseTime defaultTimeLocale
336341#endif
337− formats = ["%x","%m/%d/%Y", "%D","%F", "%d %b %Y",
342+ formats = ["%x","%m/%d/%Y", "%D","%F", "%d %b %Y",
338343 "%d %B %Y", "%b. %d, %Y", "%B %d, %Y",
339344 "%Y%m%d", "%Y%m", "%Y"]
340345