mirror of
https://github.com/simonmichael/hledger.git
synced 2024-09-19 10:17:35 +03:00
default report dates come from secondary dates with --date2
This commit is contained in:
parent
3ed82bd231
commit
eeb48c86d1
@ -545,32 +545,32 @@ journalMixedAmounts = map pamount . journalPostings
|
||||
journalAmounts :: Journal -> [Amount]
|
||||
journalAmounts = concatMap flatten . journalMixedAmounts where flatten (Mixed as) = as
|
||||
|
||||
-- | The fully specified date span enclosing the primary dates of all
|
||||
-- this journal's transactions and postings, or DateSpan Nothing Nothing
|
||||
-- | The fully specified date span enclosing the dates (primary or secondary)
|
||||
-- of all this journal's transactions and postings, or DateSpan Nothing Nothing
|
||||
-- if there are none.
|
||||
journalDateSpan :: Journal -> DateSpan
|
||||
journalDateSpan j
|
||||
journalDateSpan :: Bool -> Journal -> DateSpan
|
||||
journalDateSpan secondary j
|
||||
| null ts = DateSpan Nothing Nothing
|
||||
| otherwise = DateSpan (Just earliest) (Just $ addDays 1 latest)
|
||||
where
|
||||
earliest = minimum dates
|
||||
latest = maximum dates
|
||||
dates = pdates ++ tdates
|
||||
tdates = map tdate ts
|
||||
pdates = concatMap (catMaybes . map pdate . tpostings) ts
|
||||
tdates = map (if secondary then transactionDate2 else tdate) ts
|
||||
pdates = concatMap (catMaybes . map (if secondary then (Just . postingDate2) else pdate) . tpostings) ts
|
||||
ts = jtxns j
|
||||
|
||||
-- #ifdef TESTS
|
||||
test_journalDateSpan = do
|
||||
"journalDateSpan" ~: do
|
||||
assertEqual "" (DateSpan (Just $ fromGregorian 2014 1 10) (Just $ fromGregorian 2014 10 11))
|
||||
(journalDateSpan j)
|
||||
(journalDateSpan True j)
|
||||
where
|
||||
j = nulljournal{jtxns = [nulltransaction{tdate = parsedate "2014/02/01"
|
||||
,tpostings = [posting{pdate=Just (parsedate "2014/01/10")}]
|
||||
}
|
||||
,nulltransaction{tdate = parsedate "2014/09/01"
|
||||
,tpostings = [posting{pdate=Just (parsedate "2014/10/10")}]
|
||||
,tpostings = [posting{pdate2=Just (parsedate "2014/10/10")}]
|
||||
}
|
||||
]}
|
||||
-- #endif
|
||||
|
@ -74,7 +74,7 @@ multiBalanceReport opts q j = MultiBalanceReport (displayspans, items, totals)
|
||||
datelessq = dbg "datelessq" $ filterQuery (not . queryIsDate) q
|
||||
precedingq = dbg "precedingq" $ And [datelessq, Date $ DateSpan Nothing (spanStart reportspan)]
|
||||
requestedspan = dbg "requestedspan" $ queryDateSpan (date2_ opts) q -- span specified by -b/-e/-p options and query args
|
||||
requestedspan' = dbg "requestedspan'" $ requestedspan `spanDefaultsFrom` journalDateSpan j -- if open-ended, close it using the journal's end dates
|
||||
requestedspan' = dbg "requestedspan'" $ requestedspan `spanDefaultsFrom` journalDateSpan (date2_ opts) j -- if open-ended, close it using the journal's end dates
|
||||
intervalspans = dbg "intervalspans" $ splitSpan (intervalFromOpts opts) requestedspan' -- interval spans enclosing it
|
||||
reportspan = dbg "reportspan" $ DateSpan (maybe Nothing spanStart $ headMay intervalspans) -- the requested span enlarged to a whole number of intervals
|
||||
(maybe Nothing spanEnd $ lastMay intervalspans)
|
||||
|
@ -56,7 +56,7 @@ postingsReport opts q j = (totallabel, items)
|
||||
dateless = filterQuery (not . queryIsDate)
|
||||
-- precedingq = dbg "precedingq" $ And [datelessq, Date $ DateSpan Nothing (spanStart reportspan)]
|
||||
requestedspan = dbg "requestedspan" $ queryDateSpan (date2_ opts) q -- span specified by -b/-e/-p options and query args
|
||||
requestedspan' = dbg "requestedspan'" $ requestedspan `spanDefaultsFrom` journalDateSpan j -- if open-ended, close it using the journal's end dates
|
||||
requestedspan' = dbg "requestedspan'" $ requestedspan `spanDefaultsFrom` journalDateSpan (date2_ opts) j -- if open-ended, close it using the journal's end dates
|
||||
intervalspans = dbg "intervalspans" $ splitSpan (intervalFromOpts opts) requestedspan' -- interval spans enclosing it
|
||||
reportspan = dbg "reportspan" $ DateSpan (maybe Nothing spanStart $ headMay intervalspans) -- the requested span enlarged to a whole number of intervals
|
||||
(maybe Nothing spanEnd $ lastMay intervalspans)
|
||||
|
@ -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 `spanDefaultsFrom` journalDateSpan j
|
||||
span = queryDateSpan (date2_ opts) q `spanDefaultsFrom` journalDateSpan (date2_ opts) j
|
||||
spans = filter (DateSpan Nothing Nothing /=) $ splitSpan interval span
|
||||
spanps = [(s, filter (isPostingInDateSpan s) ps) | s <- spans]
|
||||
-- same as Register
|
||||
|
Loading…
Reference in New Issue
Block a user