From 593ee39284d02ccffa5cc641a64cbcdfe80cb18c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakob=20Sch=C3=B6ttl?= Date: Tue, 16 Apr 2019 21:48:45 +0200 Subject: [PATCH] Fix behavior of options like -Mp2019 This fixes the issue #1008 --- hledger-lib/Hledger/Reports/ReportOptions.hs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index d33ac8e2b..1746e5db1 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -274,13 +274,16 @@ endDatesFromRawOpts d = catMaybes . map (enddatefromrawopt d) -- | Get the report interval, if any, specified by the last of -p/--period, -- -D/--daily, -W/--weekly, -M/--monthly etc. options. +-- An interval from --period counts only if it is explicitly defined. intervalFromRawOpts :: RawOpts -> Interval intervalFromRawOpts = lastDef NoInterval . catMaybes . map intervalfromrawopt where intervalfromrawopt (n,v) | n == "period" = - either (\e -> usageError $ "could not parse period option: "++customErrorBundlePretty e) (Just . fst) $ - parsePeriodExpr nulldate (stripquotes $ T.pack v) -- reference date does not affect the interval + either + (\e -> usageError $ "could not parse period option: "++customErrorBundlePretty e) + extractIntervalOrNothing $ + parsePeriodExpr nulldate (stripquotes $ T.pack v) -- reference date does not affect the interval | n == "daily" = Just $ Days 1 | n == "weekly" = Just $ Weeks 1 | n == "monthly" = Just $ Months 1 @@ -288,6 +291,12 @@ intervalFromRawOpts = lastDef NoInterval . catMaybes . map intervalfromrawopt | n == "yearly" = Just $ Years 1 | otherwise = Nothing +-- | Extract the interval from the parsed -p/--period expression. +-- Return Nothing if an interval is not explicitly defined. +extractIntervalOrNothing :: (Interval, DateSpan) -> Maybe Interval +extractIntervalOrNothing (NoInterval, _) = Nothing +extractIntervalOrNothing (interval, _) = Just interval + -- | Get any statuses to be matched, as specified by -U/--unmarked, -- -P/--pending, -C/--cleared flags. -UPC is equivalent to no flags, -- so this returns a list of 0-2 unique statuses.