mirror of
https://github.com/simonmichael/hledger.git
synced 2024-11-08 15:14:49 +03:00
parsing: use actual (ie, first) date's year as a default for the effective (ie, second) date
This commit is contained in:
parent
86020e8f4a
commit
c08bccb158
@ -310,7 +310,7 @@ ledgerDefaultYear = do
|
|||||||
ledgerTransaction :: GenParser Char LedgerFileCtx Transaction
|
ledgerTransaction :: GenParser Char LedgerFileCtx Transaction
|
||||||
ledgerTransaction = do
|
ledgerTransaction = do
|
||||||
date <- ledgerdate <?> "transaction"
|
date <- ledgerdate <?> "transaction"
|
||||||
edate <- try (ledgereffectivedate <?> "effective date") <|> return Nothing
|
edate <- try (ledgereffectivedate date <?> "effective date") <|> return Nothing
|
||||||
status <- ledgerstatus
|
status <- ledgerstatus
|
||||||
code <- ledgercode
|
code <- ledgercode
|
||||||
description <- many1 spacenonewline >> liftM rstrip (many1 (noneOf ";\n") <?> "description")
|
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)
|
let tod = TimeOfDay (read h) (read m) (maybe 0 (fromIntegral.read) s)
|
||||||
return $ LocalTime day tod
|
return $ LocalTime day tod
|
||||||
|
|
||||||
ledgereffectivedate :: GenParser Char LedgerFileCtx (Maybe Day)
|
ledgereffectivedate :: Day -> GenParser Char LedgerFileCtx (Maybe Day)
|
||||||
ledgereffectivedate = do
|
ledgereffectivedate actualdate = do
|
||||||
char '='
|
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
|
return $ Just edate
|
||||||
|
|
||||||
ledgerstatus :: GenParser Char st Bool
|
ledgerstatus :: GenParser Char st Bool
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
#
|
#
|
||||||
-f - print --effective
|
-f - print --effective
|
||||||
<<<
|
<<<
|
||||||
Y 2009
|
|
||||||
|
|
||||||
2009/1/1=1/2 x
|
2009/1/1=1/2 x
|
||||||
a 1
|
a 1
|
||||||
b
|
b
|
||||||
@ -11,3 +9,4 @@ Y 2009
|
|||||||
a 1
|
a 1
|
||||||
b -1
|
b -1
|
||||||
|
|
||||||
|
>>>2
|
Loading…
Reference in New Issue
Block a user