parsing: use actual (ie, first) date's year as a default for the effective (ie, second) date

This commit is contained in:
Simon Michael 2010-02-03 21:19:01 +00:00
parent 86020e8f4a
commit c08bccb158
2 changed files with 12 additions and 6 deletions

View File

@ -310,7 +310,7 @@ ledgerDefaultYear = do
ledgerTransaction :: GenParser Char LedgerFileCtx Transaction
ledgerTransaction = do
date <- ledgerdate <?> "transaction"
edate <- try (ledgereffectivedate <?> "effective date") <|> return Nothing
edate <- try (ledgereffectivedate date <?> "effective date") <|> return Nothing
status <- ledgerstatus
code <- ledgercode
description <- many1 spacenonewline >> liftM rstrip (many1 (noneOf ";\n") <?> "description")
@ -352,10 +352,17 @@ ledgerdatetime = do
let tod = TimeOfDay (read h) (read m) (maybe 0 (fromIntegral.read) s)
return $ LocalTime day tod
ledgereffectivedate :: GenParser Char LedgerFileCtx (Maybe Day)
ledgereffectivedate = do
ledgereffectivedate :: Day -> GenParser Char LedgerFileCtx (Maybe Day)
ledgereffectivedate actualdate = do
char '='
edate <- ledgerdate
-- kludgily use actual date for default year
let withDefaultYear d p = do
y <- getYear
let (y',_,_) = toGregorian d in setYear y'
r <- p
when (isJust y) $ setYear $ fromJust y
return r
edate <- withDefaultYear actualdate ledgerdate
return $ Just edate
ledgerstatus :: GenParser Char st Bool

View File

@ -1,8 +1,6 @@
#
-f - print --effective
<<<
Y 2009
2009/1/1=1/2 x
a 1
b
@ -11,3 +9,4 @@ Y 2009
a 1
b -1
>>>2