From 869ff2528af920ac011a47b7baec48c4530af00a Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Thu, 6 Dec 2012 03:23:56 +0000 Subject: [PATCH] accept normal simple date syntax in posting dates, give an error on bad date syntax here --- MANUAL.md | 13 +++++++------ hledger-lib/Hledger/Read/JournalReader.hs | 16 ++++++++-------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/MANUAL.md b/MANUAL.md index a1d3d94b9..39e7b3c85 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -411,13 +411,14 @@ NAME=EXACTVALUE` on the command line. ### Posting dates You can give individual postings a different date from their parent -transaction, by adding posting tag `date:ACTUALDATE`. The effective date -can be set similarly: `date2:EFFECTIVEDATE`. If present, these dates will -take precedence in register and balance reports. +transaction, by adding a [posting tag]("tags") like `date:DATE` where +DATE is a [simple date](#simple-dates). The effective date can be set +with `date2:DATE`. If present, these dates will take precedence in +reports. -For compatibility, ledger's posting date syntax is also supported -(`[ACTUALDATE]`, `[ACTUALDATE=EFFECTIVEDATE]` or `[=EFFECTIVEDATE]` in a -posting comment) and treated as an alterate spelling of the date tags. +Ledger's posting date syntax is also supported (`[ACTUALDATE]`, +`[ACTUALDATE=EFFECTIVEDATE]` or `[=EFFECTIVEDATE]` in a posting comment) +and treated as an alternate spelling of the date tags. ### Including other files diff --git a/hledger-lib/Hledger/Read/JournalReader.hs b/hledger-lib/Hledger/Read/JournalReader.hs index eccb1cdce..b401f3db8 100644 --- a/hledger-lib/Hledger/Read/JournalReader.hs +++ b/hledger-lib/Hledger/Read/JournalReader.hs @@ -511,11 +511,13 @@ postingp = do _ <- balanceassertion _ <- fixedlotprice many spacenonewline + ctx <- getState comment <- try followingcomment <|> (newline >> return "") let tags = tagsInComment comment - date = dateFromTags tags - date2 = date2FromTags tags - return posting{pdate=date, pdate2=date2, pstatus=status, paccount=account', pamount=amount, pcomment=comment, ptype=ptype, ptags=tags} + -- oh boy + d <- maybe (return Nothing) (either (fail.show) (return.Just)) (parseWithCtx ctx date `fmap` dateValueFromTags tags) + d2 <- maybe (return Nothing) (either (fail.show) (return.Just)) (parseWithCtx ctx date `fmap` date2ValueFromTags tags) + return posting{pdate=d, pdate2=d2, pstatus=status, paccount=account', pamount=amount, pcomment=comment, ptype=ptype, ptags=tags} #ifdef TESTS test_postingp = do @@ -886,11 +888,9 @@ test_ledgerDateSyntaxToTags = do assertEqual "date2:2012/11/28, " $ ledgerDateSyntaxToTags "[=2012/11/28]" #endif -dateFromTags :: [Tag] -> Maybe Day -dateFromTags = maybe Nothing parsedateM . fmap snd . find ((=="date").fst) - -date2FromTags :: [Tag] -> Maybe Day -date2FromTags = maybe Nothing parsedateM . fmap snd . find ((=="date2").fst) +dateValueFromTags, date2ValueFromTags :: [Tag] -> Maybe String +dateValueFromTags ts = maybe Nothing (Just . snd) $ find ((=="date") . fst) ts +date2ValueFromTags ts = maybe Nothing (Just . snd) $ find ((=="date2") . fst) ts {- old hunit tests