;bin: smooth: note/warn about date-order requirement (#1171)

[ci skip]
This commit is contained in:
Simon Michael 2020-01-23 12:40:25 -08:00
parent 4589ec51ba
commit 21fec478d4

View File

@ -8,7 +8,8 @@
-} -}
-- --package hledger-lib -- --package hledger-lib
-- Experimental; not guaranteed to work or be useful. -- Experimental; not guaranteed to work or be useful.
-- Requires latest hledger/hledger-lib from master. -- Requires a contemporaneous version of the hledger package.
-- Requires journal entries to be sorted by date.
-- Run it inside an up to date hledger source tree, eg: bin/hledger-smooth.hs ACCT -- Run it inside an up to date hledger source tree, eg: bin/hledger-smooth.hs ACCT
-- Or add bin/ to $PATH and [stack ghc bin/hledger-smooth;] hledger smooth ACCT -- Or add bin/ to $PATH and [stack ghc bin/hledger-smooth;] hledger smooth ACCT
@ -105,9 +106,10 @@ splitPosting acct dates p@Posting{paccount,pamount}
start = dbg4 "start" $ postingDate p start = dbg4 "start" $ postingDate p
(end, dates') = (end, dates') =
case dbg4 "dates" dates of case dbg4 "dates" dates of
(d1:d2:ds) -> if d1==start then (d2, d2:ds) else error' "splitPosting got wrong date, should not happen" -- XXX fragile, breaks if transactions are not date-ordered
(d1:d2:ds) -> if d1==start then (d2, d2:ds) else error' "splitPosting got wrong date, should not happen (maybe sort your transactions by date)"
[d] -> (d, []) [d] -> (d, [])
[] -> error' "splitPosting ran out of dates, should not happen" [] -> error' "splitPosting ran out of dates, should not happen (maybe sort your transactions by date)"
days = initSafe [start..end] days = initSafe [start..end]
amt = (fromIntegral $ length days) `divideMixedAmount` pamount amt = (fromIntegral $ length days) `divideMixedAmount` pamount
-- give one of the postings an exact balancing amount to ensure the transaction is balanced -- give one of the postings an exact balancing amount to ensure the transaction is balanced