parsing: show a better error for illegal month/day numbers in dates
This commit is contained in:
parent
cd8dffc485
commit
b2c8933af4
@ -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
|
||||
|
||||
15
tests/parse-dates.test
Normal file
15
tests/parse-dates.test
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user