lib: fix reportStartEndDates, rename to reportSpan
This commit is contained in:
parent
17ce3d8329
commit
ebaac2866b
@ -25,7 +25,7 @@ module Hledger.Reports.ReportOptions (
|
|||||||
queryOptsFromOpts,
|
queryOptsFromOpts,
|
||||||
transactionDateFn,
|
transactionDateFn,
|
||||||
postingDateFn,
|
postingDateFn,
|
||||||
reportStartEndDates,
|
reportSpan,
|
||||||
reportStartDate,
|
reportStartDate,
|
||||||
reportEndDate,
|
reportEndDate,
|
||||||
specifiedStartEndDates,
|
specifiedStartEndDates,
|
||||||
@ -36,6 +36,7 @@ module Hledger.Reports.ReportOptions (
|
|||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
|
import Control.Applicative ((<|>))
|
||||||
import Data.Data (Data)
|
import Data.Data (Data)
|
||||||
#if !MIN_VERSION_base(4,8,0)
|
#if !MIN_VERSION_base(4,8,0)
|
||||||
import Data.Functor.Compat ((<$>))
|
import Data.Functor.Compat ((<$>))
|
||||||
@ -410,24 +411,25 @@ tests_queryOptsFromOpts = [
|
|||||||
})
|
})
|
||||||
]
|
]
|
||||||
|
|
||||||
-- | The effective report start/end dates are the dates specified by options or queries,
|
-- | The effective report span is the start and end dates specified by
|
||||||
-- otherwise the earliest/latest transaction or posting date in the journal,
|
-- options or queries, or otherwise the earliest and latest transaction or
|
||||||
-- otherwise (for an empty journal) nothing.
|
-- 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.
|
-- Needs IO to parse smart dates in options/queries.
|
||||||
reportStartEndDates :: Journal -> ReportOpts -> IO (Maybe (Day,Day))
|
reportSpan :: Journal -> ReportOpts -> IO DateSpan
|
||||||
reportStartEndDates j ropts = do
|
reportSpan j ropts = do
|
||||||
(mspecifiedstartdate, mspecifiedenddate) <- specifiedStartEndDates ropts
|
(mspecifiedstartdate, mspecifiedenddate) <- specifiedStartEndDates ropts
|
||||||
return $
|
let
|
||||||
case journalDateSpan False j of -- don't bother with secondary dates
|
DateSpan mjournalstartdate mjournalenddate = journalDateSpan False j -- don't bother with secondary dates
|
||||||
DateSpan (Just journalstartdate) (Just journalenddate) ->
|
mstartdate = mspecifiedstartdate <|> mjournalstartdate
|
||||||
Just (fromMaybe journalstartdate mspecifiedstartdate, fromMaybe journalenddate mspecifiedenddate)
|
menddate = mspecifiedenddate <|> mjournalenddate
|
||||||
_ -> Nothing
|
return $ DateSpan mstartdate menddate
|
||||||
|
|
||||||
reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day)
|
reportStartDate :: Journal -> ReportOpts -> IO (Maybe Day)
|
||||||
reportStartDate j ropts = (fst <$>) <$> reportStartEndDates j ropts
|
reportStartDate j ropts = spanStart <$> reportSpan j ropts
|
||||||
|
|
||||||
reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day)
|
reportEndDate :: Journal -> ReportOpts -> IO (Maybe Day)
|
||||||
reportEndDate j ropts = (snd <$>) <$> reportStartEndDates 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.
|
-- | 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.
|
-- Needs IO to parse smart dates in options/queries.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user