Skip to content

Commit

Permalink
;lib: intervalFromRawOpts: replace undefined with an error message
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael committed Jul 25, 2019
1 parent 030a409 commit 02ed4f5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion hledger-lib/Hledger/Data/Dates.hs
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion hledger-lib/Hledger/Reports/ReportOptions.hs
Expand Up @@ -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
Expand Down

0 comments on commit 02ed4f5

Please sign in to comment.