diff --git a/MANUAL.md b/MANUAL.md index cf2fca835..44cbb2bc7 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -1203,9 +1203,13 @@ entries, and the following c++ ledger options and commands: - hledger's output follows the decimal point character, digit grouping, and digit group separator character used in the journal. -- hledger print shows amounts for all postings, and shows unit - prices for amounts which have them. (This currently means that - it does not print multi-commodity transactions in valid journal format.) +- hledger print shows amounts for all postings, and shows unit prices for + amounts which have them. (This means that it does not currently print + multi-commodity transactions in valid journal format.) + +- hledger print ignores the --effective flag, always showing both dates. + ledger print shows only the effective date with --effective, but not + vice versa. - hledger's default commodity directive (D) sets the commodity for subsequent commodityless amounts, and contributes to that commodity's diff --git a/NOTES b/NOTES index 76734e6b7..bf148eb5c 100644 --- a/NOTES +++ b/NOTES @@ -550,6 +550,7 @@ using be more place holders? *** 33 edit form always displays in non-javascript browsers, like elinks *** 25 hledger in windows console does not print non-ascii characters *** convert: manual needs a rewrite +*** web: manual needs update *** parsing: recursive file includes cause a hang echo "!include rec" > rec hledger -f rec print diff --git a/hledger-lib/Hledger/Data/Matching.hs b/hledger-lib/Hledger/Data/Matching.hs index 2863c7224..62f0e975d 100644 --- a/hledger-lib/Hledger/Data/Matching.hs +++ b/hledger-lib/Hledger/Data/Matching.hs @@ -216,10 +216,6 @@ matchesTransaction _ _ = False postingEffectiveDate :: Posting -> Maybe Day postingEffectiveDate p = maybe Nothing (Just . transactionEffectiveDate) $ ptransaction p -transactionEffectiveDate :: Transaction -> Day -transactionEffectiveDate t = case teffectivedate t of Just d -> d - Nothing -> tdate t - -- | Does the match expression match this account ? -- A matching in: clause is also considered a match. matchesAccount :: Matcher -> AccountName -> Bool diff --git a/hledger-lib/Hledger/Data/Transaction.hs b/hledger-lib/Hledger/Data/Transaction.hs index 03488844a..8ddd26db5 100644 --- a/hledger-lib/Hledger/Data/Transaction.hs +++ b/hledger-lib/Hledger/Data/Transaction.hs @@ -10,6 +10,7 @@ module Hledger.Data.Transaction where import Data.List import Data.Maybe +import Data.Time.Calendar import Test.HUnit import Text.Printf import qualified Data.Map as Map @@ -233,10 +234,18 @@ nonzerobalanceerror t = printf "could not balance this transaction (%s%s%s)" rms | otherwise = "balanced virtual postings are off by " ++ show (costOfMixedAmount bvsum) sep = if not (null rmsg) && not (null bvmsg) then "; " else "" --- | Convert the primary date to either the actual or effective date. +transactionActualDate :: Transaction -> Day +transactionActualDate = tdate + +-- Get a transaction's effective date, defaulting to the actual date. +transactionEffectiveDate :: Transaction -> Day +transactionEffectiveDate t = fromMaybe (tdate t) $ teffectivedate t + +-- | Once we no longer need both, set the main transaction date to either +-- the actual or effective date. A bit hacky. journalTransactionWithDate :: WhichDate -> Transaction -> Transaction journalTransactionWithDate ActualDate t = t -journalTransactionWithDate EffectiveDate t = txnTieKnot t{tdate=fromMaybe (tdate t) (teffectivedate t)} +journalTransactionWithDate EffectiveDate t = txnTieKnot t{tdate=transactionEffectiveDate t} -- | Ensure a transaction's postings refer back to it. txnTieKnot :: Transaction -> Transaction diff --git a/hledger-lib/Hledger/Reports.hs b/hledger-lib/Hledger/Reports.hs index aa9ba7f57..8ee7e891a 100644 --- a/hledger-lib/Hledger/Reports.hs +++ b/hledger-lib/Hledger/Reports.hs @@ -146,10 +146,14 @@ clearedValueFromOpts ReportOpts{..} | cleared_ = Just True | uncleared_ = Just False | otherwise = Nothing --- | Detect which date we will report on, based on --effective. +-- | Report which date we will report on based on --effective. whichDateFromOpts :: ReportOpts -> WhichDate whichDateFromOpts ReportOpts{..} = if effective_ then EffectiveDate else ActualDate +-- | Select a Transaction date accessor based on --effective. +transactionDateFn :: ReportOpts -> (Transaction -> Day) +transactionDateFn ReportOpts{..} = if effective_ then transactionEffectiveDate else transactionActualDate + -- | Convert this journal's transactions' primary date to either the -- actual or effective date, as per options. journalSelectingDateFromOpts :: ReportOpts -> Journal -> Journal @@ -197,9 +201,10 @@ type EntriesReportItem = Transaction -- | Select transactions for an entries report. entriesReport :: ReportOpts -> FilterSpec -> Journal -> EntriesReport -entriesReport opts fspec j = sortBy (comparing tdate) $ jtxns $ filterJournalTransactions fspec j' +entriesReport opts fspec j = sortBy (comparing f) $ jtxns $ filterJournalTransactions fspec j' where - j' = journalSelectingDateFromOpts opts $ journalSelectingAmountFromOpts opts j + f = transactionDateFn opts + j' = journalSelectingAmountFromOpts opts j ------------------------------------------------------------------------------- diff --git a/tests/effective-print.test b/tests/effective-print.test deleted file mode 100644 index 5fe1b21cc..000000000 --- a/tests/effective-print.test +++ /dev/null @@ -1,11 +0,0 @@ -bin/hledger -f - print --effective -<<< -2009/1/1=2010/1/1 x - a 1 - b ->>> -2010/01/01 x - a 1 - b -1 - ->>>=0 diff --git a/tests/effective-date.test b/tests/print-effective.test similarity index 72% rename from tests/effective-date.test rename to tests/print-effective.test index 7415fbdd4..7d1b3573c 100644 --- a/tests/effective-date.test +++ b/tests/print-effective.test @@ -1,16 +1,17 @@ -# +# print shows both dates. The second's year defaults to the first's. bin/hledger -f - print --effective <<< 2009/1/1=1/2 x a 1 b >>> -2009/01/02 x +2009/01/01=2009/01/02 x a 1 b -1 >>>2 >>>= 0 + # Effective date of 29 Feb on leap year should be valid bin/hledger -f - print --effective <<< @@ -18,7 +19,7 @@ bin/hledger -f - print --effective a 1 b >>> -2000/02/29 x +2001/02/27=2000/02/29 x a 1 b -1