From 2edb9e4a79714c4a294aed5121f80a1ec87f3746 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Mon, 21 Dec 2009 06:03:34 +0000 Subject: [PATCH] register: make reporting intervals honour a display expression (#18) --- Commands/Register.hs | 2 +- Ledger/Ledger.hs | 6 +----- Ledger/Posting.hs | 7 +++++++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Commands/Register.hs b/Commands/Register.hs index d6619e6fc..da985d7dd 100644 --- a/Commands/Register.hs +++ b/Commands/Register.hs @@ -33,7 +33,7 @@ showRegisterReport opts filterspec l summaryps = concatMap summarisespan spans summarisespan s = summarisePostingsInDateSpan s depth empty (postingsinspan s) postingsinspan s = filter (isPostingInDateSpan s) displayedps - spans = splitSpan interval (ledgerDateSpan l) + spans = splitSpan interval (postingsDateSpan displayedps) interval = intervalFromOpts opts empty = Empty `elem` opts depth = depthFromOpts opts diff --git a/Ledger/Ledger.hs b/Ledger/Ledger.hs index 942cbe5f3..7890df474 100644 --- a/Ledger/Ledger.hs +++ b/Ledger/Ledger.hs @@ -138,11 +138,7 @@ ledgerAccountTreeAt l acct = subtreeat acct $ ledgerAccountTree 9999 l -- | The (fully specified) date span containing all the ledger's (filtered) transactions, -- or DateSpan Nothing Nothing if there are none. ledgerDateSpan :: Ledger -> DateSpan -ledgerDateSpan l - | null ps = DateSpan Nothing Nothing - | otherwise = DateSpan (Just $ postingDate $ head ps) (Just $ addDays 1 $ postingDate $ last ps) - where - ps = sortBy (comparing postingDate) $ ledgerPostings l +ledgerDateSpan = postingsDateSpan . ledgerPostings -- | Convenience aliases. accountnames :: Ledger -> [AccountName] diff --git a/Ledger/Posting.hs b/Ledger/Posting.hs index d59d17499..662d1ebc5 100644 --- a/Ledger/Posting.hs +++ b/Ledger/Posting.hs @@ -86,3 +86,10 @@ isPostingInDateSpan (DateSpan (Just b) (Just e)) p = d >= b && d < e where d = p isEmptyPosting :: Posting -> Bool isEmptyPosting = isZeroMixedAmount . pamount +-- | Get the minimal date span which contains all the postings, or +-- DateSpan Nothing Nothing if there are none. +postingsDateSpan :: [Posting] -> DateSpan +postingsDateSpan [] = DateSpan Nothing Nothing +postingsDateSpan ps = DateSpan (Just $ postingDate $ head ps') (Just $ addDays 1 $ postingDate $ last ps') + where ps' = sortBy (comparing postingDate) ps +