smart dates: also accept yyyymmdd with no separators

This commit is contained in:
Simon Michael 2009-01-17 20:07:24 +00:00
parent 91f3b7faac
commit ebdf67a5ab
2 changed files with 11 additions and 1 deletions

View File

@ -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

View File

@ -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"