diff --git a/Ledger/Dates.hs b/Ledger/Dates.hs index d09930619..5565b693f 100644 --- a/Ledger/Dates.hs +++ b/Ledger/Dates.hs @@ -229,7 +229,7 @@ Assumes any text in the parse stream has been lowercased. -} smartdate :: GenParser Char st SmartDate smartdate = do - let dateparsers = [ymd, ym, md, y, d, month, mon, today', yesterday, tomorrow, + let dateparsers = [yyyymmdd, ymd, ym, md, y, d, month, mon, today', yesterday, tomorrow, lastthisnextthing ] (y,m,d) <- choice $ map try dateparsers @@ -237,6 +237,15 @@ smartdate = do datesepchar = oneOf "/-." +yyyymmdd :: GenParser Char st SmartDate +yyyymmdd = do + y <- count 4 digit + m <- count 2 digit + guard (read m <= 12) + d <- count 2 digit + guard (read d <= 31) + return (y,m,d) + ymd :: GenParser Char st SmartDate ymd = do y <- many1 digit diff --git a/Tests.hs b/Tests.hs index 46c60e919..13732511e 100644 --- a/Tests.hs +++ b/Tests.hs @@ -104,6 +104,7 @@ misc_tests = TestList [ "1999-12-02" `gives` "1999/12/02" "1999.12.02" `gives` "1999/12/02" "1999/3/2" `gives` "1999/03/02" + "19990302" `gives` "1999/03/02" "2008/2" `gives` "2008/02/01" "20/2" `gives` "0020/02/01" "1000" `gives` "1000/01/01"