diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index 8f18c535d..dcbd569b1 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -24,9 +24,12 @@ module Hledger.Reports.ReportOptions ( queryOptsFromOpts, transactionDateFn, postingDateFn, + reportStartEndDates, reportStartDate, reportEndDate, - reportStartEndDates, + specifiedStartEndDates, + specifiedStartDate, + specifiedEndDate, tests_Hledger_Reports_ReportOptions ) @@ -399,33 +402,42 @@ tests_queryOptsFromOpts = [ }) ] --- | The effective report start date is the one specified by options or queries, --- otherwise the earliest transaction or posting date in the journal, +-- | The effective report start/end dates are the dates specified by options or queries, +-- otherwise the earliest/latest transaction or posting date in the journal, -- otherwise (for an empty journal) nothing. -- Needs IO to parse smart dates in options/queries. -reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day) -reportStartDate j ropts = (fst <$>) <$> reportStartEndDates j ropts - --- | The effective report end date is the one specified by options or queries, --- otherwise the latest transaction or posting date in the journal, --- otherwise (for an empty journal) nothing. --- Needs IO to parse smart dates in options/queries. -reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day) -reportEndDate j ropts = (snd <$>) <$> reportStartEndDates j ropts - reportStartEndDates :: Journal -> ReportOpts -> IO (Maybe (Day,Day)) reportStartEndDates j ropts = do - today <- getCurrentDay - let - q = queryFromOpts today ropts - mrequestedstartdate = queryStartDate False q - mrequestedenddate = queryEndDate False q + (mspecifiedstartdate, mspecifiedenddate) <- specifiedStartEndDates ropts return $ case journalDateSpan False j of -- don't bother with secondary dates DateSpan (Just journalstartdate) (Just journalenddate) -> - Just (fromMaybe journalstartdate mrequestedstartdate, fromMaybe journalenddate mrequestedenddate) + Just (fromMaybe journalstartdate mspecifiedstartdate, fromMaybe journalenddate mspecifiedenddate) _ -> Nothing +reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day) +reportStartDate j ropts = (fst <$>) <$> reportStartEndDates j ropts + +reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day) +reportEndDate j ropts = (snd <$>) <$> reportStartEndDates j ropts + +-- | The specified report start/end dates are the dates specified by options or queries, if any. +-- Needs IO to parse smart dates in options/queries. +specifiedStartEndDates :: ReportOpts -> IO (Maybe Day, Maybe Day) +specifiedStartEndDates ropts = do + today <- getCurrentDay + let + q = queryFromOpts today ropts + mspecifiedstartdate = queryStartDate False q + mspecifiedenddate = queryEndDate False q + return (mspecifiedstartdate, mspecifiedenddate) + +specifiedStartDate :: ReportOpts -> IO (Maybe Day) +specifiedStartDate ropts = fst <$> specifiedStartEndDates ropts + +specifiedEndDate :: ReportOpts -> IO (Maybe Day) +specifiedEndDate ropts = snd <$> specifiedStartEndDates ropts + tests_Hledger_Reports_ReportOptions :: Test tests_Hledger_Reports_ReportOptions = TestList $ diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index 92fc7ce4f..4c1bb615d 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -117,12 +117,11 @@ anonymise j -- and seems to have the same effect as doing it last on the reported values. journalApplyValue :: ReportOpts -> Journal -> IO Journal journalApplyValue ropts j = do - mvaluedate <- reportEndDate j ropts - let convert | value_ ropts - , Just d <- mvaluedate - = overJournalAmounts (amountValue j d) - | otherwise - = id + today <- getCurrentDay + mspecifiedenddate <- specifiedEndDate ropts + let d = fromMaybe today mspecifiedenddate + convert | value_ ropts = overJournalAmounts (amountValue j d) + | otherwise = id return $ convert j -- | Run PeriodicTransactions from journal from today or journal end to requested end day. diff --git a/tests/journal/market-prices.test b/tests/journal/market-prices.test index 216d09ade..780ece898 100644 --- a/tests/journal/market-prices.test +++ b/tests/journal/market-prices.test @@ -28,7 +28,7 @@ P 2011/01/01 GBP $1.35 $135.00 expenses:foreign >>>=0 -# 3. Market prices in the future are not ignored. #453 +# 3. Market prices in the future are ignored. #453, #683 hledger -f- bal -N -V <<< P 2000/1/1 $ €1.20 @@ -37,7 +37,7 @@ P 3000/1/1 $ €1.30 3000/01/02 (a) $100 >>> - €130.00 a + €120.00 a >>>=0 # 4. The market prices in effect at the report end date are used.