print, web: always show both dates, ignoring --effective (#42)

Ledger shows only the effective date with --effective, but not vice versa.
print is supposed to be information-preserving so this seems better.
This also fixes the web entries view.
This commit is contained in:
Simon Michael 2011-09-23 14:50:20 +00:00
parent 9a0a0be01c
commit 35f3a4fa00
7 changed files with 31 additions and 26 deletions

View File

@ -1203,9 +1203,13 @@ entries, and the following c++ ledger options and commands:
- hledger's output follows the decimal point character, digit grouping, - hledger's output follows the decimal point character, digit grouping,
and digit group separator character used in the journal. and digit group separator character used in the journal.
- hledger print shows amounts for all postings, and shows unit - hledger print shows amounts for all postings, and shows unit prices for
prices for amounts which have them. (This currently means that amounts which have them. (This means that it does not currently print
it does not print multi-commodity transactions in valid journal format.) 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 - hledger's default commodity directive (D) sets the commodity for
subsequent commodityless amounts, and contributes to that commodity's subsequent commodityless amounts, and contributes to that commodity's

1
NOTES
View File

@ -550,6 +550,7 @@ using be more place holders?
*** 33 edit form always displays in non-javascript browsers, like elinks *** 33 edit form always displays in non-javascript browsers, like elinks
*** 25 hledger in windows console does not print non-ascii characters *** 25 hledger in windows console does not print non-ascii characters
*** convert: manual needs a rewrite *** convert: manual needs a rewrite
*** web: manual needs update
*** parsing: recursive file includes cause a hang *** parsing: recursive file includes cause a hang
echo "!include rec" > rec echo "!include rec" > rec
hledger -f rec print hledger -f rec print

View File

@ -216,10 +216,6 @@ matchesTransaction _ _ = False
postingEffectiveDate :: Posting -> Maybe Day postingEffectiveDate :: Posting -> Maybe Day
postingEffectiveDate p = maybe Nothing (Just . transactionEffectiveDate) $ ptransaction p 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 ? -- | Does the match expression match this account ?
-- A matching in: clause is also considered a match. -- A matching in: clause is also considered a match.
matchesAccount :: Matcher -> AccountName -> Bool matchesAccount :: Matcher -> AccountName -> Bool

View File

@ -10,6 +10,7 @@ module Hledger.Data.Transaction
where where
import Data.List import Data.List
import Data.Maybe import Data.Maybe
import Data.Time.Calendar
import Test.HUnit import Test.HUnit
import Text.Printf import Text.Printf
import qualified Data.Map as Map 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) | otherwise = "balanced virtual postings are off by " ++ show (costOfMixedAmount bvsum)
sep = if not (null rmsg) && not (null bvmsg) then "; " else "" 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 :: WhichDate -> Transaction -> Transaction
journalTransactionWithDate ActualDate t = t 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. -- | Ensure a transaction's postings refer back to it.
txnTieKnot :: Transaction -> Transaction txnTieKnot :: Transaction -> Transaction

View File

@ -146,10 +146,14 @@ clearedValueFromOpts ReportOpts{..} | cleared_ = Just True
| uncleared_ = Just False | uncleared_ = Just False
| otherwise = Nothing | 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 -> WhichDate
whichDateFromOpts ReportOpts{..} = if effective_ then EffectiveDate else ActualDate 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 -- | Convert this journal's transactions' primary date to either the
-- actual or effective date, as per options. -- actual or effective date, as per options.
journalSelectingDateFromOpts :: ReportOpts -> Journal -> Journal journalSelectingDateFromOpts :: ReportOpts -> Journal -> Journal
@ -197,9 +201,10 @@ type EntriesReportItem = Transaction
-- | Select transactions for an entries report. -- | Select transactions for an entries report.
entriesReport :: ReportOpts -> FilterSpec -> Journal -> EntriesReport 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 where
j' = journalSelectingDateFromOpts opts $ journalSelectingAmountFromOpts opts j f = transactionDateFn opts
j' = journalSelectingAmountFromOpts opts j
------------------------------------------------------------------------------- -------------------------------------------------------------------------------

View File

@ -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

View File

@ -1,16 +1,17 @@
# # print shows both dates. The second's year defaults to the first's.
bin/hledger -f - print --effective bin/hledger -f - print --effective
<<< <<<
2009/1/1=1/2 x 2009/1/1=1/2 x
a 1 a 1
b b
>>> >>>
2009/01/02 x 2009/01/01=2009/01/02 x
a 1 a 1
b -1 b -1
>>>2 >>>2
>>>= 0 >>>= 0
# Effective date of 29 Feb on leap year should be valid # Effective date of 29 Feb on leap year should be valid
bin/hledger -f - print --effective bin/hledger -f - print --effective
<<< <<<
@ -18,7 +19,7 @@ bin/hledger -f - print --effective
a 1 a 1
b b
>>> >>>
2000/02/29 x 2001/02/27=2000/02/29 x
a 1 a 1
b -1 b -1