From ef9c4a29c4ca56c01b240a2fefce841a01dc2c57 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 24 Apr 2019 08:25:55 -0700 Subject: [PATCH] lib: save the current date in ReportOpts We need this for choosing a valuation date, otherwise, report functions would have to be in IO or we'd have to pass in yet another argument. It's optional because it's useful to be able to create report opts purely (I think ?) This is not ideal but maybe not a problem. --- hledger-lib/Hledger/Reports/ReportOptions.hs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index f9b77e4f8..ad151ad49 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -77,12 +77,15 @@ instance Default AccountListMode where def = ALDefault -- or query arguments, but not all. Some are used only by certain -- commands, as noted below. data ReportOpts = ReportOpts { - period_ :: Period + today_ :: Maybe Day -- ^ The current date. A late addition to ReportOpts. + -- Optional, but when set it may affect some reports: + -- Reports use it when picking a -V valuation date. + ,period_ :: Period ,interval_ :: Interval ,statuses_ :: [Status] -- ^ Zero, one, or two statuses to be matched ,cost_ :: Bool ,depth_ :: Maybe Int - ,display_ :: Maybe DisplayExp + ,display_ :: Maybe DisplayExp -- XXX unused ? ,date2_ :: Bool ,empty_ :: Bool ,no_elide_ :: Bool @@ -146,6 +149,7 @@ defreportopts = ReportOpts def def def + def rawOptsToReportOpts :: RawOpts -> IO ReportOpts rawOptsToReportOpts rawopts = checkReportOpts <$> do @@ -153,7 +157,8 @@ rawOptsToReportOpts rawopts = checkReportOpts <$> do d <- getCurrentDay color <- hSupportsANSI stdout return defreportopts{ - period_ = periodFromRawOpts d rawopts' + today_ = Just d + ,period_ = periodFromRawOpts d rawopts' ,interval_ = intervalFromRawOpts rawopts' ,statuses_ = statusesFromRawOpts rawopts' ,cost_ = boolopt "cost" rawopts'