cleanup smartdate
This commit is contained in:
parent
3e1a615dbf
commit
49a84957a9
@ -493,27 +493,16 @@ and maybe some others:
|
|||||||
> 21
|
> 21
|
||||||
> october, oct
|
> october, oct
|
||||||
> yesterday, today, tomorrow
|
> yesterday, today, tomorrow
|
||||||
> this/next/last week/day/month/quarter/year
|
> (not yet) this/next/last week/day/month/quarter/year
|
||||||
|
|
||||||
|
Returns a triple of possibly empty strings for year, month and day
|
||||||
|
(defaults are supplied later in the IO layer.)
|
||||||
Note: only recognises month names in lowercase.
|
Note: only recognises month names in lowercase.
|
||||||
-}
|
-}
|
||||||
smartdate :: Parser (String,String,String)
|
smartdate :: Parser (String,String,String)
|
||||||
smartdate = do
|
smartdate = do
|
||||||
(y,m,d) <- choice [
|
let dateparsers = [ymd, ym, md, y, d, month, mon, today', yesterday, tomorrow]
|
||||||
try ymd
|
(y,m,d) <- choice $ map try dateparsers
|
||||||
,try ym
|
|
||||||
,try md
|
|
||||||
,try y
|
|
||||||
,try d
|
|
||||||
,try month
|
|
||||||
,try mon
|
|
||||||
,try today'
|
|
||||||
,try yesterday
|
|
||||||
,try tomorrow
|
|
||||||
-- ,try thiswhatever
|
|
||||||
-- ,try nextwhatever
|
|
||||||
-- ,try lastwhatever
|
|
||||||
]
|
|
||||||
return $ (y,m,d)
|
return $ (y,m,d)
|
||||||
|
|
||||||
datesepchar = oneOf "/-."
|
datesepchar = oneOf "/-."
|
||||||
@ -550,7 +539,6 @@ d = do
|
|||||||
guard (read d <= 31)
|
guard (read d <= 31)
|
||||||
return ("","",d)
|
return ("","",d)
|
||||||
|
|
||||||
-- | Parse a M/D string as ("",M,D), year will be filled in later
|
|
||||||
md :: Parser (String,String,String)
|
md :: Parser (String,String,String)
|
||||||
md = do
|
md = do
|
||||||
m <- many1 digit
|
m <- many1 digit
|
||||||
@ -584,8 +572,8 @@ tomorrow = string "tomorrow" >> return ("","","tomorrow")
|
|||||||
|
|
||||||
type TransactionMatcher = Transaction -> Bool
|
type TransactionMatcher = Transaction -> Bool
|
||||||
|
|
||||||
-- | Parse a --display expression which is a simple date predicate,
|
-- | Parse a --display expression which is a simple date predicate, like
|
||||||
-- like "d>[DATE]" or "d<=[DATE]".
|
-- "d>[DATE]" or "d<=[DATE]", and return a transaction-matching predicate.
|
||||||
datedisplayexpr :: Parser TransactionMatcher
|
datedisplayexpr :: Parser TransactionMatcher
|
||||||
datedisplayexpr = do
|
datedisplayexpr = do
|
||||||
char 'd'
|
char 'd'
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user