check: ordereddates: test --date2, clarify --unique and QUERY dropped
This commit is contained in:
parent
bb1d49c573
commit
2ffed3aec7
@ -8,26 +8,27 @@ import Hledger.Cli.CliOptions
|
|||||||
import Text.Printf
|
import Text.Printf
|
||||||
|
|
||||||
journalCheckOrdereddates :: CliOpts -> Journal -> Either String ()
|
journalCheckOrdereddates :: CliOpts -> Journal -> Either String ()
|
||||||
journalCheckOrdereddates CliOpts{rawopts_=rawopts,reportspec_=rspec} j = do
|
journalCheckOrdereddates CliOpts{reportspec_=rspec} j = do
|
||||||
let ropts = (rsOpts rspec){accountlistmode_=ALFlat}
|
let ropts = (rsOpts rspec){accountlistmode_=ALFlat}
|
||||||
let ts = filter (rsQuery rspec `matchesTransaction`) $
|
let ts = filter (rsQuery rspec `matchesTransaction`) $
|
||||||
jtxns $ journalSelectingAmountFromOpts ropts j
|
jtxns $ journalSelectingAmountFromOpts ropts j
|
||||||
let unique = boolopt "--unique" rawopts
|
let checkunique = False -- boolopt "unique" rawopts XXX was supported by checkdates command
|
||||||
let date = transactionDateFn ropts
|
let getdate = transactionDateFn ropts
|
||||||
let compare a b =
|
let compare a b =
|
||||||
if unique
|
if checkunique
|
||||||
then date a < date b
|
then getdate a < getdate b
|
||||||
else date a <= date b
|
else getdate a <= getdate b
|
||||||
case checkTransactions compare ts of
|
case checkTransactions compare ts of
|
||||||
FoldAcc{fa_previous=Nothing} -> return ()
|
FoldAcc{fa_previous=Nothing} -> return ()
|
||||||
FoldAcc{fa_error=Nothing} -> return ()
|
FoldAcc{fa_error=Nothing} -> return ()
|
||||||
FoldAcc{fa_error=Just error, fa_previous=Just previous} -> do
|
FoldAcc{fa_error=Just error, fa_previous=Just previous} -> do
|
||||||
let
|
let
|
||||||
uniquestr = if unique then " and/or not unique" else ""
|
uniquestr = if checkunique then " and/or not unique" else ""
|
||||||
positionstr = showGenericSourcePos $ tsourcepos error
|
positionstr = showGenericSourcePos $ tsourcepos error
|
||||||
txn1str = linesPrepend " " $ showTransaction previous
|
txn1str = linesPrepend " " $ showTransaction previous
|
||||||
txn2str = linesPrepend2 "> " " " $ showTransaction error
|
txn2str = linesPrepend2 "> " " " $ showTransaction error
|
||||||
Left $ printf "transaction date is out of order%s\nat %s:\n\n%s"
|
Left $ printf "transaction date%s is out of order%s\nat %s:\n\n%s"
|
||||||
|
(if date2_ ropts then "2" else "")
|
||||||
uniquestr
|
uniquestr
|
||||||
positionstr
|
positionstr
|
||||||
(txn1str ++ txn2str)
|
(txn1str ++ txn2str)
|
||||||
|
|||||||
@ -14,7 +14,32 @@ $ hledger -f- check ordereddates
|
|||||||
$ hledger -f- check ordereddates
|
$ hledger -f- check ordereddates
|
||||||
>2 /transaction date is out of order/
|
>2 /transaction date is out of order/
|
||||||
>=1
|
>=1
|
||||||
# XXX
|
|
||||||
# With --date2, it checks secondary dates instead.
|
# With --date2, it checks secondary dates instead
|
||||||
# With --strict, dates must also be unique.
|
<
|
||||||
# With a query, only matched transactions' dates are checked.
|
2020-01-02
|
||||||
|
2020-01-01=2020-01-03
|
||||||
|
$ hledger -f- check ordereddates --date2
|
||||||
|
|
||||||
|
#
|
||||||
|
<
|
||||||
|
2020-01-01=2020-01-03
|
||||||
|
2020-01-02
|
||||||
|
$ hledger -f- check ordereddates --date2
|
||||||
|
>2 /transaction date2 is out of order/
|
||||||
|
>=1
|
||||||
|
|
||||||
|
# XXX not supported: With a query, only matched transactions' dates are checked.
|
||||||
|
# <
|
||||||
|
# 2020-01-01 a
|
||||||
|
# 2020-01-03 b
|
||||||
|
# 2020-01-02 a
|
||||||
|
# $ hledger -f- check ordereddates
|
||||||
|
|
||||||
|
# XXX not supported: With --unique, dates must also be unique.
|
||||||
|
# <
|
||||||
|
# 2020-01-01
|
||||||
|
# 2020-01-01
|
||||||
|
# $ hledger -f- check ordereddates --unique
|
||||||
|
# >2 /transaction date is out of order and/or not unique/
|
||||||
|
# >=1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user