From 19ab2225996fcd8061d13ae34e98d67d44d00af6 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Fri, 11 Sep 2020 17:16:07 +1000 Subject: [PATCH] lib,cli: Remove old impure ReportOpts date functions. --- bin/hledger-smooth.hs | 2 +- hledger-lib/Hledger/Reports/ReportOptions.hs | 41 +++++--------------- hledger-web/Hledger/Web/WebOptions.hs | 14 ++++++- hledger/Hledger/Cli/Commands/Balance.hs | 4 +- hledger/Hledger/Cli/Utils.hs | 11 +++--- 5 files changed, 30 insertions(+), 42 deletions(-) diff --git a/bin/hledger-smooth.hs b/bin/hledger-smooth.hs index 499a9cc2c..3059c9b00 100755 --- a/bin/hledger-smooth.hs +++ b/bin/hledger-smooth.hs @@ -61,8 +61,8 @@ main = do } withJournalDo copts' $ \j -> do today <- getCurrentDay - menddate <- specifiedEndDate ropts let + menddate = reportPeriodLastDay ropts args = words' $ query_ ropts q = queryFromOpts today ropts acct = T.pack $ headDef (error' "Please provide an account name argument") args diff --git a/hledger-lib/Hledger/Reports/ReportOptions.hs b/hledger-lib/Hledger/Reports/ReportOptions.hs index 25a34689b..d4f635c6c 100644 --- a/hledger-lib/Hledger/Reports/ReportOptions.hs +++ b/hledger-lib/Hledger/Reports/ReportOptions.hs @@ -30,9 +30,6 @@ module Hledger.Reports.ReportOptions ( reportSpan, reportStartDate, reportEndDate, - specifiedStartEndDates, - specifiedStartDate, - specifiedEndDate, reportPeriodStart, reportPeriodOrJournalStart, reportPeriodLastDay, @@ -457,39 +454,19 @@ queryFromFlags ReportOpts{..} = simplifyQuery $ And flagsq -- options or queries, or otherwise the earliest and latest transaction or -- posting dates in the journal. If no dates are specified by options/queries -- and the journal is empty, returns the null date span. --- Needs IO to parse smart dates in options/queries. -reportSpan :: Journal -> ReportOpts -> IO DateSpan -reportSpan j ropts = do - (mspecifiedstartdate, mspecifiedenddate) <- - dbg3 "specifieddates" <$> specifiedStartEndDates ropts - let +reportSpan :: Journal -> ReportOpts -> DateSpan +reportSpan j ropts = dbg3 "reportspan" $ DateSpan mstartdate menddate + where DateSpan mjournalstartdate mjournalenddate = dbg3 "journalspan" $ journalDateSpan False j -- ignore secondary dates - mstartdate = mspecifiedstartdate <|> mjournalstartdate - menddate = mspecifiedenddate <|> mjournalenddate - return $ dbg3 "reportspan" $ DateSpan mstartdate menddate + mstartdate = queryStartDate False (query_ ropts) <|> mjournalstartdate + menddate = queryEndDate False (query_ ropts) <|> mjournalenddate -reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day) -reportStartDate j ropts = spanStart <$> reportSpan j ropts +reportStartDate :: Journal -> ReportOpts -> Maybe Day +reportStartDate j ropts = spanStart $ reportSpan j ropts -reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day) -reportEndDate j ropts = spanEnd <$> reportSpan 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 - let - q = query_ 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 +reportEndDate :: Journal -> ReportOpts -> Maybe Day +reportEndDate j ropts = spanEnd $ reportSpan j ropts -- Some pure alternatives to the above. XXX review/clean up diff --git a/hledger-web/Hledger/Web/WebOptions.hs b/hledger-web/Hledger/Web/WebOptions.hs index b700778a0..2825ded2b 100644 --- a/hledger-web/Hledger/Web/WebOptions.hs +++ b/hledger-web/Hledger/Web/WebOptions.hs @@ -119,7 +119,19 @@ data WebOpts = WebOpts } deriving (Show) defwebopts :: WebOpts -defwebopts = WebOpts def def Nothing def def def def [CapView, CapAdd] Nothing def Nothing +defwebopts = WebOpts + { serve_ = False + , serve_api_ = False + , cors_ = Nothing + , host_ = "" + , port_ = def + , base_url_ = "" + , file_url_ = Nothing + , capabilities_ = [CapView, CapAdd] + , capabilitiesHeader_ = Nothing + , cliopts_ = def + , socket_ = Nothing + } instance Default WebOpts where def = defwebopts diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index 2f85200b7..9fb83d1b3 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -310,8 +310,8 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do fmt = outputFormatFromOpts opts if budget then do -- single or multi period budget report - reportspan <- reportSpan j ropts - let budgetreport = dbg4 "budgetreport" $ budgetReport ropts assrt reportspan j + let reportspan = reportSpan j ropts + budgetreport = dbg4 "budgetreport" $ budgetReport ropts assrt reportspan j where assrt = not $ ignore_assertions_ $ inputopts_ opts render = case fmt of diff --git a/hledger/Hledger/Cli/Utils.hs b/hledger/Hledger/Cli/Utils.hs index e5a9a9f84..4a2842d81 100644 --- a/hledger/Hledger/Cli/Utils.hs +++ b/hledger/Hledger/Cli/Utils.hs @@ -123,20 +123,19 @@ journalAddForecast CliOpts{inputopts_=iopts, reportopts_=ropts} j = today <- getCurrentDay -- "They can start no earlier than: the day following the latest normal transaction in the journal (or today if there are none)." - let + let mjournalend = dbg2 "journalEndDate" $ journalEndDate False j -- ignore secondary dates forecastbeginDefault = dbg2 "forecastbeginDefault" $ fromMaybe today mjournalend - -- "They end on or before the specified report end date, or 180 days from today if unspecified." - mspecifiedend <- snd . dbg2 "specifieddates" <$> specifiedStartEndDates ropts - let + -- "They end on or before the specified report end date, or 180 days from today if unspecified." + mspecifiedend = dbg2 "specifieddates" $ reportPeriodLastDay ropts forecastendDefault = dbg2 "forecastendDefault" $ fromMaybe (addDays 180 today) mspecifiedend - + forecastspan = dbg2 "forecastspan" $ spanDefaultsFrom (fromMaybe nulldatespan $ dbg2 "forecastspan flag" $ forecast_ ropts) (DateSpan (Just forecastbeginDefault) (Just forecastendDefault)) - + forecasttxns = [ txnTieKnot t | pt <- jperiodictxns j , t <- runPeriodicTransaction pt forecastspan