diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 95193f325..597b8aafb 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -21,10 +21,8 @@ module Hledger.Data.Journal ( commodityStylesFromAmounts, journalCommodityStyles, journalConvertAmountsToCost, - journalFinalise, journalReverse, - journalSetTime, - journalSetFilePath, + journalSetLastReadTime, journalPivot, -- * Filtering filterJournalTransactions, @@ -522,6 +520,9 @@ filterJournalTransactionsByAccount apats j@Journal{jtxns=ts} = j{jtxns=filter tm -} +-- | Reverse parsed data to normal order. This is used for post-parse +-- processing, since data is added to the head of the list during +-- parsing. journalReverse :: Journal -> Journal journalReverse j = j {jfiles = reverse $ jfiles j @@ -532,31 +533,9 @@ journalReverse j = ,jmarketprices = reverse $ jmarketprices j } -journalSetTime :: ClockTime -> Journal -> Journal -journalSetTime t j = j{ jlastreadtime = t } - -journalSetFilePath :: FilePath -> Text -> Journal -> Journal -journalSetFilePath path txt j = j {jfiles = (path,txt) : jfiles j} - - --- | Do post-parse processing on a parsed journal to make it ready for --- use. Reverse parsed data to normal order, standardise amount --- formats, check/ensure that transactions are balanced, and maybe --- check balance assertions. -journalFinalise :: ClockTime -> FilePath -> Text -> Bool -> Bool -> ParsedJournal -> Either String Journal -journalFinalise t path txt reorder assrt j@Journal{jfiles=fs} = - let j' = if reorder - then j {jfiles = (path,txt) : reverse fs - ,jlastreadtime = t - ,jdeclaredaccounts = reverse $ jdeclaredaccounts j - ,jtxns = reverse $ jtxns j -- NOTE: see addTransaction - ,jtxnmodifiers = reverse $ jtxnmodifiers j -- NOTE: see addTransactionModifier - ,jperiodictxns = reverse $ jperiodictxns j -- NOTE: see addPeriodicTransaction - ,jmarketprices = reverse $ jmarketprices j -- NOTE: see addMarketPrice - } - else j - in journalTieTransactions <$> - (journalBalanceTransactions assrt $ journalApplyCommodityStyles j') +-- | Set this journal's last read time, ie when its files were last read. +journalSetLastReadTime :: ClockTime -> Journal -> Journal +journalSetLastReadTime t j = j{ jlastreadtime = t } journalNumberAndTieTransactions = journalTieTransactions . journalNumberTransactions diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 6df8890c4..8d0e97bf1 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -262,13 +262,21 @@ parseAndFinaliseJournal parser iopts f txt = do -- be false pending modifiers) and we don't reorder the second -- time. If we are only running once, we reorder and follow -- the options for checking assertions. - let runFin :: Bool -> Bool -> (ParsedJournal -> Either String Journal) - runFin reorder ignore = journalFinalise t f txt reorder ignore - fj = if auto_ iopts && (not . null . jtxnmodifiers) pj + let fj = if auto_ iopts && (not . null . jtxnmodifiers) pj then applyTransactionModifiers <$> - runFin True False pj >>= - runFin False (not $ ignore_assertions_ iopts) - else runFin True (not $ ignore_assertions_ iopts) pj + (journalBalanceTransactions False $ + journalReverse $ + journalApplyCommodityStyles pj) >>= + (\j -> journalBalanceTransactions (not $ ignore_assertions_ iopts) $ + journalAddFile (f, txt) $ + journalSetLastReadTime t $ + j) + else journalBalanceTransactions (not $ ignore_assertions_ iopts) $ + journalReverse $ + journalAddFile (f, txt) $ + journalApplyCommodityStyles $ + journalSetLastReadTime t $ + pj in case fj of Right j -> return j @@ -299,14 +307,14 @@ parseAndFinaliseJournal' parser iopts f txt = do journalReverse $ journalApplyCommodityStyles pj) >>= (\j -> journalBalanceTransactions (not $ ignore_assertions_ iopts) $ - journalSetTime t $ - journalSetFilePath f txt $ + journalAddFile (f, txt) $ + journalSetLastReadTime t $ j) else journalBalanceTransactions (not $ ignore_assertions_ iopts) $ journalReverse $ + journalAddFile (f, txt) $ journalApplyCommodityStyles $ - journalSetTime t $ - journalSetFilePath f txt $ + journalSetLastReadTime t $ pj in case fj of