refactor fixSmartDate*
This commit is contained in:
parent
931c64221e
commit
c24609f468
@ -169,12 +169,18 @@ 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
|
-- | Convert a smart date string to an explicit yyyy\/mm\/dd string using
|
||||||
-- the provided reference date, or raise an error.
|
-- the provided reference date, or raise an error.
|
||||||
fixSmartDateStr :: Day -> String -> String
|
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.
|
-- | A safe version of fixSmartDateStr.
|
||||||
fixSmartDateStrEither :: Day -> String -> Either ParseError String
|
fixSmartDateStrEither :: Day -> String -> Either ParseError String
|
||||||
fixSmartDateStrEither t s = case parsewith smartdateonly (lowercase s) of
|
fixSmartDateStrEither d = either Left (Right . showDate) . fixSmartDateStrEither' d
|
||||||
Right sd -> Right $ showDay $ fixSmartDate t sd
|
|
||||||
|
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
|
Left e -> Left e
|
||||||
|
|
||||||
-- | Convert a SmartDate to an absolute date using the provided reference date.
|
-- | Convert a SmartDate to an absolute date using the provided reference date.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user