From e9f04d5ed688c4b04f9b3e90787ae54fbb7018bf Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Wed, 3 Mar 2021 06:44:50 -0800 Subject: [PATCH] check: ordereddates now checks each file separately (fix #1493) --- .../Cli/Commands/Check/Ordereddates.hs | 39 +++++++++++-------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Check/Ordereddates.hs b/hledger/Hledger/Cli/Commands/Check/Ordereddates.hs index 1a39150d5..e3721f8fc 100755 --- a/hledger/Hledger/Cli/Commands/Check/Ordereddates.hs +++ b/hledger/Hledger/Cli/Commands/Check/Ordereddates.hs @@ -11,30 +11,37 @@ import Data.Semigroup ((<>)) import qualified Data.Text as T import Hledger import Hledger.Cli.CliOptions +import Control.Monad (forM) +import Data.List (groupBy) journalCheckOrdereddates :: CliOpts -> Journal -> Either String () journalCheckOrdereddates CliOpts{reportspec_=rspec} j = do let ropts = (rsOpts rspec){accountlistmode_=ALFlat} - ts = filter (rsQuery rspec `matchesTransaction`) $ - jtxns $ journalSelectingAmountFromOpts ropts j + -- check date ordering within each file, not across files + filets = + groupBy (\t1 t2 -> transactionFile t1 == transactionFile t2) $ + filter (rsQuery rspec `matchesTransaction`) $ + jtxns $ journalSelectingAmountFromOpts ropts j checkunique = False -- boolopt "unique" rawopts XXX was supported by checkdates command compare a b = if checkunique then getdate a < getdate b else getdate a <= getdate b where getdate = transactionDateFn ropts - case checkTransactions compare ts of - FoldAcc{fa_previous=Nothing} -> return () - FoldAcc{fa_error=Nothing} -> return () - FoldAcc{fa_error=Just error, fa_previous=Just previous} -> do - let - datestr = if date2_ ropts then "2" else "" - uniquestr = if checkunique then " and/or not unique" else "" - positionstr = showGenericSourcePos $ tsourcepos error - txn1str = T.unpack . linesPrepend (T.pack " ") $ showTransaction previous - txn2str = T.unpack . linesPrepend2 (T.pack "> ") (T.pack " ") $ showTransaction error - Left $ - "transaction date" <> datestr <> " is out of order" - <> uniquestr <> "\nat " <> positionstr <> ":\n\n" - <> txn1str <> txn2str + either Left (const $ Right ()) $ + forM filets $ \ts -> + case checkTransactions compare ts of + FoldAcc{fa_previous=Nothing} -> Right () + FoldAcc{fa_error=Nothing} -> Right () + FoldAcc{fa_error=Just error, fa_previous=Just previous} -> do + let + datestr = if date2_ ropts then "2" else "" + uniquestr = if checkunique then " and/or not unique" else "" + positionstr = showGenericSourcePos $ tsourcepos error + txn1str = T.unpack . linesPrepend (T.pack " ") $ showTransaction previous + txn2str = T.unpack . linesPrepend2 (T.pack "> ") (T.pack " ") $ showTransaction error + Left $ + "transaction date" <> datestr <> " is out of order" + <> uniquestr <> "\nat " <> positionstr <> ":\n\n" + <> txn1str <> txn2str data FoldAcc a b = FoldAcc { fa_error :: Maybe a