;lib: intervalFromRawOpts: replace undefined with an error message

This commit is contained in:
Simon Michael 2019-07-25 10:46:45 +01:00
parent 030a409dd3
commit 02ed4f5d04
2 changed files with 9 additions and 2 deletions

View File

@ -892,7 +892,11 @@ lastthisnextthing = do
return ("", T.unpack r, T.unpack p)
-- |
-- | Parse a period expression, specifying a date span and optionally
-- a reporting interval. Requires a reference "today" date for
-- resolving any relative start/end dates (only; it is not needed for
-- parsing the reporting interval).
--
-- >>> let p = parsePeriodExpr (parsedate "2008/11/26")
-- >>> p "from Aug to Oct"
-- Right (NoInterval,DateSpan 2008/08/01-2008/09/30)
@ -944,6 +948,7 @@ periodexprp rdate = do
(,) NoInterval <$> periodexprdatespanp rdate
]
-- Parse a reporting interval and a date span.
intervalanddateperiodexprp :: Day -> TextParser m (Interval, DateSpan)
intervalanddateperiodexprp rdate = do
i <- reportingintervalp

View File

@ -296,7 +296,9 @@ intervalFromRawOpts = lastDef NoInterval . catMaybes . map intervalfromrawopt
either
(\e -> usageError $ "could not parse period option: "++customErrorBundlePretty e)
extractIntervalOrNothing $
parsePeriodExpr undefined (stripquotes $ T.pack v) -- reference date does not affect the interval
parsePeriodExpr
(error' "intervalFromRawOpts: did not expect to need today's date here") -- should not happen; we are just getting the interval, which does not use the reference date
(stripquotes $ T.pack v)
| n == "daily" = Just $ Days 1
| n == "weekly" = Just $ Weeks 1
| n == "monthly" = Just $ Months 1