mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-27 12:24:43 +03:00
lib,cli: Remove old impure ReportOpts date functions.
This commit is contained in:
parent
2aaab4b1b7
commit
19ab222599
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -128,8 +128,7 @@ journalAddForecast CliOpts{inputopts_=iopts, reportopts_=ropts} j =
|
||||
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
|
||||
mspecifiedend = dbg2 "specifieddates" $ reportPeriodLastDay ropts
|
||||
forecastendDefault = dbg2 "forecastendDefault" $ fromMaybe (addDays 180 today) mspecifiedend
|
||||
|
||||
forecastspan = dbg2 "forecastspan" $
|
||||
|
Loading…
Reference in New Issue
Block a user