From b2c8933af43ccc929662e880ee63b8f6b0baf8f1 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Tue, 6 Apr 2010 02:31:47 +0000 Subject: [PATCH] parsing: show a better error for illegal month/day numbers in dates --- hledger-lib/Ledger/Dates.hs | 5 ++--- tests/parse-dates.test | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/parse-dates.test diff --git a/hledger-lib/Ledger/Dates.hs b/hledger-lib/Ledger/Dates.hs index c62773cd1..eb7c054fa 100644 --- a/hledger-lib/Ledger/Dates.hs +++ b/hledger-lib/Ledger/Dates.hs @@ -262,11 +262,10 @@ ymd = do y <- many1 digit datesepchar m <- try (count 2 digit) <|> count 1 digit - guard (read m >= 1 && (read m <= 12)) - -- when (read m < 1 || (read m > 12)) $ fail "bad month number specified" + when (read m < 1 || (read m > 12)) $ error $ "bad month number: " ++ m datesepchar d <- try (count 2 digit) <|> count 1 digit - when (read d < 1 || (read d > 31)) $ fail "bad day number specified" + when (read d < 1 || (read d > 31)) $ error $ "bad day number: " ++ d return $ (y,m,d) ym :: GenParser Char st SmartDate diff --git a/tests/parse-dates.test b/tests/parse-dates.test new file mode 100644 index 000000000..59dc4b6f4 --- /dev/null +++ b/tests/parse-dates.test @@ -0,0 +1,15 @@ +# dates with bad month or day numbers should be rejected +-f- print +<<< +2010/31/12 x + a 1 + b +>>>2 /bad month number: 31/ +>>>= 1 +-f- print +<<< +2010/12/32 x + a 1 + b +>>>2 /bad day number: 32/ +>>>= 1