From ad3c5dfb4d6202f6794906e1e45c47bbd0bc14be Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 27 May 2016 08:06:53 -0700 Subject: [PATCH] lib: fix ghc 8-related date issues (#352) Our null date is now 0000/01/01 instead of 0000/00/00. --- hledger-lib/Hledger/Data/Dates.hs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 945fa5c57..9711a4f3b 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -550,13 +550,25 @@ parsedateM s = firstJust [ -- -- >>> parsedate "2008/02/03" -- 2008-02-03 --- >>> parsedate "2008/02/03/" --- *** Exception: could not parse date "2008/02/03/" --- >>> parsedate "2008/02/30" -- invalid dates may get silently adjusted --- 2008-02-29 parsedate :: String -> Day parsedate s = fromMaybe (error' $ "could not parse date \"" ++ s ++ "\"") (parsedateM s) +-- doctests I haven't been able to make compatible with both GHC 7 and 8 +-- -- >>> parsedate "2008/02/03/" +-- -- *** Exception: could not parse date "2008/02/03/" +-- #if MIN_VERSION_base(4,9,0) +-- -- ... +-- #endif +-- #if MIN_VERSION_time(1,6,0) +-- -- >>> parsedate "2008/02/30" -- with time >= 1.6, invalid dates are rejected +-- -- *** Exception: could not parse date "2008/02/30" +-- #if MIN_VERSION_base(4,9,0) +-- -- ... +-- #endif +-- #else +-- -- >>> parsedate "2008/02/30" -- with time < 1.6, they are silently adjusted +-- -- 2008-02-29 +-- #endif -- | Parse a time string to a time type using the provided pattern, or -- return the default. @@ -855,4 +867,4 @@ nulldatespan :: DateSpan nulldatespan = DateSpan Nothing Nothing nulldate :: Day -nulldate = parsedate "0000/00/00" +nulldate = fromGregorian 0 1 1