diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 9fc13e6c7..2038d7890 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -45,9 +45,9 @@ module Hledger.Data.Dates ( spansSpan, spanIntersect, spansIntersect, + spanDefaultsFrom, spanUnion, spansUnion, - orDatesFrom, smartdate, splitSpan, fixSmartDate, @@ -169,14 +169,6 @@ spanContainsDate (DateSpan Nothing (Just e)) d = d < e spanContainsDate (DateSpan (Just b) Nothing) d = d >= b spanContainsDate (DateSpan (Just b) (Just e)) d = d >= b && d < e --- | Combine two datespans, filling any unspecified dates in the first --- with dates from the second. Not a clip operation, just uses the --- second's start/end dates as defaults when the first does not --- specify them. -orDatesFrom (DateSpan a1 b1) (DateSpan a2 b2) = DateSpan a b - where a = if isJust a1 then a1 else a2 - b = if isJust b1 then b1 else b2 - -- | Calculate the intersection of a number of datespans. spansIntersect [] = nulldatespan spansIntersect [d] = d @@ -188,6 +180,12 @@ spanIntersect (DateSpan b1 e1) (DateSpan b2 e2) = DateSpan b e b = latest b1 b2 e = earliest e1 e2 +-- | Fill any unspecified dates in the first span with the dates from +-- the second one. Sort of a one-way spanIntersect. +spanDefaultsFrom (DateSpan a1 b1) (DateSpan a2 b2) = DateSpan a b + where a = if isJust a1 then a1 else a2 + b = if isJust b1 then b1 else b2 + -- | Calculate the union of a number of datespans. spansUnion [] = nulldatespan spansUnion [d] = d diff --git a/hledger-lib/Hledger/Reports/PostingsReport.hs b/hledger-lib/Hledger/Reports/PostingsReport.hs index b4e44bf49..10b29d32e 100644 --- a/hledger-lib/Hledger/Reports/PostingsReport.hs +++ b/hledger-lib/Hledger/Reports/PostingsReport.hs @@ -85,7 +85,7 @@ postingsReport opts q j = -- trace ("q: "++show q++"\nq': "++show q') $ displayspan = postingsDateSpan ps where (_,ps,_) = postingsMatchingDisplayExpr displayexpr opts $ journalPostings j' matchedspan = postingsDateSpan displayableps - reportspan | empty = requestedspan `orDatesFrom` journalspan + reportspan | empty = requestedspan `spanDefaultsFrom` journalspan | otherwise = requestedspan `spanIntersect` matchedspan startbal = sumPostings precedingps runningcalcfn | average_ opts = \i avg amt -> avg + (amt - avg) `divideMixedAmount` (fromIntegral i) diff --git a/hledger/Hledger/Cli/Histogram.hs b/hledger/Hledger/Cli/Histogram.hs index c61a0dc50..48fb515c7 100644 --- a/hledger/Hledger/Cli/Histogram.hs +++ b/hledger/Hledger/Cli/Histogram.hs @@ -45,7 +45,7 @@ showHistogram opts q j = concatMap (printDayWith countBar) spanps i = intervalFromOpts opts interval | i == NoInterval = Days 1 | otherwise = i - span = queryDateSpan (date2_ opts) q `orDatesFrom` journalDateSpan j + span = queryDateSpan (date2_ opts) q `spanDefaultsFrom` journalDateSpan j spans = filter (DateSpan Nothing Nothing /=) $ splitSpan interval span spanps = [(s, filter (isPostingInDateSpan s) ps) | s <- spans] -- same as Register diff --git a/hledger/Hledger/Cli/Stats.hs b/hledger/Hledger/Cli/Stats.hs index be9738588..4c274bc92 100644 --- a/hledger/Hledger/Cli/Stats.hs +++ b/hledger/Hledger/Cli/Stats.hs @@ -41,7 +41,7 @@ stats CliOpts{reportopts_=reportopts_} j = do d <- getCurrentDay let q = queryFromOpts d reportopts_ l = ledgerFromJournal q j - reportspan = (ledgerDateSpan l) `orDatesFrom` (queryDateSpan False q) + reportspan = (ledgerDateSpan l) `spanDefaultsFrom` (queryDateSpan False q) intervalspans = splitSpan (intervalFromOpts reportopts_) reportspan showstats = showLedgerStats l d s = intercalate "\n" $ map showstats intervalspans