mirror of
https://github.com/simonmichael/hledger.git
synced 2024-12-28 04:46:31 +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
|
withJournalDo copts' $ \j -> do
|
||||||
today <- getCurrentDay
|
today <- getCurrentDay
|
||||||
menddate <- specifiedEndDate ropts
|
|
||||||
let
|
let
|
||||||
|
menddate = reportPeriodLastDay ropts
|
||||||
args = words' $ query_ ropts
|
args = words' $ query_ ropts
|
||||||
q = queryFromOpts today ropts
|
q = queryFromOpts today ropts
|
||||||
acct = T.pack $ headDef (error' "Please provide an account name argument") args
|
acct = T.pack $ headDef (error' "Please provide an account name argument") args
|
||||||
|
@ -30,9 +30,6 @@ module Hledger.Reports.ReportOptions (
|
|||||||
reportSpan,
|
reportSpan,
|
||||||
reportStartDate,
|
reportStartDate,
|
||||||
reportEndDate,
|
reportEndDate,
|
||||||
specifiedStartEndDates,
|
|
||||||
specifiedStartDate,
|
|
||||||
specifiedEndDate,
|
|
||||||
reportPeriodStart,
|
reportPeriodStart,
|
||||||
reportPeriodOrJournalStart,
|
reportPeriodOrJournalStart,
|
||||||
reportPeriodLastDay,
|
reportPeriodLastDay,
|
||||||
@ -457,39 +454,19 @@ queryFromFlags ReportOpts{..} = simplifyQuery $ And flagsq
|
|||||||
-- options or queries, or otherwise the earliest and latest transaction or
|
-- options or queries, or otherwise the earliest and latest transaction or
|
||||||
-- posting dates in the journal. If no dates are specified by options/queries
|
-- posting dates in the journal. If no dates are specified by options/queries
|
||||||
-- and the journal is empty, returns the null date span.
|
-- and the journal is empty, returns the null date span.
|
||||||
-- Needs IO to parse smart dates in options/queries.
|
reportSpan :: Journal -> ReportOpts -> DateSpan
|
||||||
reportSpan :: Journal -> ReportOpts -> IO DateSpan
|
reportSpan j ropts = dbg3 "reportspan" $ DateSpan mstartdate menddate
|
||||||
reportSpan j ropts = do
|
where
|
||||||
(mspecifiedstartdate, mspecifiedenddate) <-
|
|
||||||
dbg3 "specifieddates" <$> specifiedStartEndDates ropts
|
|
||||||
let
|
|
||||||
DateSpan mjournalstartdate mjournalenddate =
|
DateSpan mjournalstartdate mjournalenddate =
|
||||||
dbg3 "journalspan" $ journalDateSpan False j -- ignore secondary dates
|
dbg3 "journalspan" $ journalDateSpan False j -- ignore secondary dates
|
||||||
mstartdate = mspecifiedstartdate <|> mjournalstartdate
|
mstartdate = queryStartDate False (query_ ropts) <|> mjournalstartdate
|
||||||
menddate = mspecifiedenddate <|> mjournalenddate
|
menddate = queryEndDate False (query_ ropts) <|> mjournalenddate
|
||||||
return $ dbg3 "reportspan" $ DateSpan mstartdate menddate
|
|
||||||
|
|
||||||
reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day)
|
reportStartDate :: Journal -> ReportOpts -> Maybe Day
|
||||||
reportStartDate j ropts = spanStart <$> reportSpan j ropts
|
reportStartDate j ropts = spanStart $ reportSpan j ropts
|
||||||
|
|
||||||
reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day)
|
reportEndDate :: Journal -> ReportOpts -> Maybe Day
|
||||||
reportEndDate j ropts = spanEnd <$> reportSpan j ropts
|
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
|
|
||||||
|
|
||||||
-- Some pure alternatives to the above. XXX review/clean up
|
-- Some pure alternatives to the above. XXX review/clean up
|
||||||
|
|
||||||
|
@ -119,7 +119,19 @@ data WebOpts = WebOpts
|
|||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
defwebopts :: WebOpts
|
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
|
instance Default WebOpts where def = defwebopts
|
||||||
|
|
||||||
|
@ -310,8 +310,8 @@ balance opts@CliOpts{rawopts_=rawopts,reportopts_=ropts@ReportOpts{..}} j = do
|
|||||||
fmt = outputFormatFromOpts opts
|
fmt = outputFormatFromOpts opts
|
||||||
|
|
||||||
if budget then do -- single or multi period budget report
|
if budget then do -- single or multi period budget report
|
||||||
reportspan <- reportSpan j ropts
|
let reportspan = reportSpan j ropts
|
||||||
let budgetreport = dbg4 "budgetreport" $ budgetReport ropts assrt reportspan j
|
budgetreport = dbg4 "budgetreport" $ budgetReport ropts assrt reportspan j
|
||||||
where
|
where
|
||||||
assrt = not $ ignore_assertions_ $ inputopts_ opts
|
assrt = not $ ignore_assertions_ $ inputopts_ opts
|
||||||
render = case fmt of
|
render = case fmt of
|
||||||
|
@ -128,8 +128,7 @@ journalAddForecast CliOpts{inputopts_=iopts, reportopts_=ropts} j =
|
|||||||
forecastbeginDefault = dbg2 "forecastbeginDefault" $ fromMaybe today mjournalend
|
forecastbeginDefault = dbg2 "forecastbeginDefault" $ fromMaybe today mjournalend
|
||||||
|
|
||||||
-- "They end on or before the specified report end date, or 180 days from today if unspecified."
|
-- "They end on or before the specified report end date, or 180 days from today if unspecified."
|
||||||
mspecifiedend <- snd . dbg2 "specifieddates" <$> specifiedStartEndDates ropts
|
mspecifiedend = dbg2 "specifieddates" $ reportPeriodLastDay ropts
|
||||||
let
|
|
||||||
forecastendDefault = dbg2 "forecastendDefault" $ fromMaybe (addDays 180 today) mspecifiedend
|
forecastendDefault = dbg2 "forecastendDefault" $ fromMaybe (addDays 180 today) mspecifiedend
|
||||||
|
|
||||||
forecastspan = dbg2 "forecastspan" $
|
forecastspan = dbg2 "forecastspan" $
|
||||||
|
Loading…
Reference in New Issue
Block a user