smart dates: also accept yyyymmdd with no separators
This commit is contained in:
		
							parent
							
								
									91f3b7faac
								
							
						
					
					
						commit
						ebdf67a5ab
					
				@ -229,7 +229,7 @@ Assumes any text in the parse stream has been lowercased.
 | 
				
			|||||||
-}
 | 
					-}
 | 
				
			||||||
smartdate :: GenParser Char st SmartDate
 | 
					smartdate :: GenParser Char st SmartDate
 | 
				
			||||||
smartdate = do
 | 
					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
 | 
					                     lastthisnextthing
 | 
				
			||||||
                    ]
 | 
					                    ]
 | 
				
			||||||
  (y,m,d) <- choice $ map try dateparsers
 | 
					  (y,m,d) <- choice $ map try dateparsers
 | 
				
			||||||
@ -237,6 +237,15 @@ smartdate = do
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
datesepchar = oneOf "/-."
 | 
					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 :: GenParser Char st SmartDate
 | 
				
			||||||
ymd = do
 | 
					ymd = do
 | 
				
			||||||
  y <- many1 digit
 | 
					  y <- many1 digit
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										1
									
								
								Tests.hs
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								Tests.hs
									
									
									
									
									
								
							@ -104,6 +104,7 @@ misc_tests = TestList [
 | 
				
			|||||||
    "1999-12-02"   `gives` "1999/12/02"
 | 
					    "1999-12-02"   `gives` "1999/12/02"
 | 
				
			||||||
    "1999.12.02"   `gives` "1999/12/02"
 | 
					    "1999.12.02"   `gives` "1999/12/02"
 | 
				
			||||||
    "1999/3/2"     `gives` "1999/03/02"
 | 
					    "1999/3/2"     `gives` "1999/03/02"
 | 
				
			||||||
 | 
					    "19990302"     `gives` "1999/03/02"
 | 
				
			||||||
    "2008/2"       `gives` "2008/02/01"
 | 
					    "2008/2"       `gives` "2008/02/01"
 | 
				
			||||||
    "20/2"         `gives` "0020/02/01"
 | 
					    "20/2"         `gives` "0020/02/01"
 | 
				
			||||||
    "1000"         `gives` "1000/01/01"
 | 
					    "1000"         `gives` "1000/01/01"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user