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 +