From c24609f46892edce8a71a6da0694d9fded28c2b0 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 14 Aug 2011 22:39:48 +0000 Subject: [PATCH] refactor fixSmartDate* --- hledger-lib/Hledger/Data/Dates.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 6b80b3073..32ead08a4 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -169,13 +169,19 @@ showDay day = printf "%04d/%02d/%02d" y m d where (y,m,d) = toGregorian day -- | Convert a smart date string to an explicit yyyy\/mm\/dd string using -- the provided reference date, or raise an error. fixSmartDateStr :: Day -> String -> String -fixSmartDateStr d s = either (\e->error' $ printf "could not parse date %s %s" (show s) (show e)) id $ fixSmartDateStrEither d s +fixSmartDateStr d s = either + (\e->error' $ printf "could not parse date %s %s" (show s) (show e)) + id + $ fixSmartDateStrEither d s -- | A safe version of fixSmartDateStr. fixSmartDateStrEither :: Day -> String -> Either ParseError String -fixSmartDateStrEither t s = case parsewith smartdateonly (lowercase s) of - Right sd -> Right $ showDay $ fixSmartDate t sd - Left e -> Left e +fixSmartDateStrEither d = either Left (Right . showDate) . fixSmartDateStrEither' d + +fixSmartDateStrEither' :: Day -> String -> Either ParseError Day +fixSmartDateStrEither' d s = case parsewith smartdateonly (lowercase s) of + Right sd -> Right $ fixSmartDate d sd + Left e -> Left e -- | Convert a SmartDate to an absolute date using the provided reference date. fixSmartDate :: Day -> SmartDate -> Day