rename --value-date -> --value-at; --value-at implies -V

This commit is contained in:
Simon Michael 2019-04-26 07:03:11 -07:00
parent 6626778012
commit 65934958f9
5 changed files with 53 additions and 55 deletions

View File

@ -73,13 +73,13 @@ erValue ropts@ReportOpts{..} j ts =
mperiodorjournallastday = mperiodlastday <|> journalEndDate False j
d = case value_date_ of
ValueOn d -> d
TransactionValue -> postingDate p
PeriodEndValue -> fromMaybe (postingDate p) mperiodorjournallastday
CurrentValue -> case today_ of
d = case value_at_ of
AtTransaction -> postingDate p
AtPeriod -> fromMaybe (postingDate p) mperiodorjournallastday
AtNow -> case today_ of
Just d -> d
Nothing -> error' "ReportOpts today_ is unset so could not satisfy --value-date=current"
Nothing -> error' "ReportOpts today_ is unset so could not satisfy --value-at=now"
AtDate d -> d
tests_EntriesReport = tests "EntriesReport" [
tests "entriesReport" [

View File

@ -74,15 +74,17 @@ data AccountListMode = ALDefault | ALTree | ALFlat deriving (Eq, Show, Data, Typ
instance Default AccountListMode where def = ALDefault
-- | On which date(s) should amount values be calculated ?
-- UI: --value-date=transaction|period|current|DATE
-- UI: --value-at=transaction|period|now|DATE.
-- ("today" would have been preferable, but clashes with
-- "transaction" for abbreviating.)
data ValueDate =
TransactionValue -- ^ Calculate values as of each transaction's (actually, each posting's) date
| PeriodEndValue -- ^ Calculate values as of each report period's end
| CurrentValue -- ^ Calculate values as of today
| ValueOn Day -- ^ Calculate values as of a specified date
AtTransaction -- ^ Calculate values as of each posting's date
| AtPeriod -- ^ Calculate values as of each report period's last day
| AtNow -- ^ Calculate values as of today (report generation date)
| AtDate Day -- ^ Calculate values as of some other date
deriving (Show,Data) -- Eq,Typeable
instance Default ValueDate where def = CurrentValue
instance Default ValueDate where def = AtNow
-- | Standard options for customising report filtering and output.
-- Most of these correspond to standard hledger command-line options
@ -97,7 +99,7 @@ data ReportOpts = ReportOpts {
,statuses_ :: [Status] -- ^ Zero, one, or two statuses to be matched
,cost_ :: Bool
,value_ :: Bool
,value_date_ :: ValueDate
,value_at_ :: ValueDate
,depth_ :: Maybe Int
,display_ :: Maybe DisplayExp -- XXX unused ?
,date2_ :: Bool
@ -176,8 +178,8 @@ rawOptsToReportOpts rawopts = checkReportOpts <$> do
,interval_ = intervalFromRawOpts rawopts'
,statuses_ = statusesFromRawOpts rawopts'
,cost_ = boolopt "cost" rawopts'
,value_ = boolopt "value" rawopts'
,value_date_ = valueDateFromRawOpts rawopts'
,value_ = or $ map (flip boolopt rawopts') ["value", "value-at"]
,value_at_ = valueDateFromRawOpts rawopts'
,depth_ = maybeintopt "depth" rawopts'
,display_ = maybedisplayopt d rawopts'
,date2_ = boolopt "date2" rawopts'
@ -344,17 +346,17 @@ reportOptsToggleStatus s ropts@ReportOpts{statuses_=ss}
| otherwise = ropts{statuses_=simplifyStatuses (s:ss)}
valueDateFromRawOpts :: RawOpts -> ValueDate
valueDateFromRawOpts = lastDef CurrentValue . catMaybes . map valuedatefromrawopt
valueDateFromRawOpts = lastDef AtNow . catMaybes . map valuedatefromrawopt
where
valuedatefromrawopt (n,v)
| n == "value-date" = valuedatevalue v
| n == "value-at" = valuedate v
| otherwise = Nothing
valuedatevalue v
| v `elem` ["transaction","t"] = Just TransactionValue
| v `elem` ["period","p"] = Just PeriodEndValue
| v `elem` ["current","c"] = Just CurrentValue
| otherwise = flip maybe (Just . ValueOn)
(usageError $ "could not parse \""++v++"\" as value date, should be: transaction|period|current|t|p|c|YYYY-MM-DD")
valuedate v
| v `elem` ["transaction","t"] = Just AtTransaction
| v `elem` ["period","p"] = Just AtPeriod
| v `elem` ["now","n"] = Just AtNow
| otherwise = flip maybe (Just . AtDate)
(usageError $ "could not parse \""++v++"\" as value date, should be: transaction|period|now|t|p|n|YYYY-MM-DD")
(parsedateM v)
type DisplayExp = String

View File

@ -149,7 +149,7 @@ reportflags = [
,flagNone ["empty","E"] (setboolopt "empty") "show items with zero amount, normally hidden (and vice-versa in hledger-ui/hledger-web)"
,flagNone ["cost","B"] (setboolopt "cost") "convert amounts to their cost at transaction time (using the transaction price, if any)"
,flagNone ["value","V"] (setboolopt "value") "convert amounts to their market value"
,flagReq ["value-date"] (\s opts -> Right $ setopt "value-date" s opts) "VALUEDATE" "as of which date(s) should market values be calculated ? transaction|period|current|YYYY-MM-DD (default: current)"
,flagReq ["value-at"] (\s opts -> Right $ setopt "value-at" s opts) "VALUEDATE" "as of which date should market values be calculated ? transaction|period|now|YYYY-MM-DD (default: now)"
,flagNone ["auto"] (setboolopt "auto") "apply automated posting rules to modify transactions"
,flagNone ["forecast"] (setboolopt "forecast") "apply periodic transaction rules to generate future transactions, to 6 months from now or report end date"
]

View File

@ -450,8 +450,8 @@ if they have a [transaction price](/journal.html#transaction-prices) specified.
## Market value
The `-V/--value` flag converts reported amounts to their market value in some other commodity.
It uses the latest [market price](journal.html#market-prices) (declared with a P directive)
The `-V/--value` flag converts reported amounts to their market value in another commodity.
It uses the commodity referenced in the latest [market price](journal.html#market-prices) (P directive)
dated on or before the valuation date. The default valuation date is today.
For example:
@ -487,34 +487,34 @@ A note for Ledger users: Ledger's -V also infers market prices from journal entr
but we don't do that. hledger's -V uses only market prices declared explicitly, with P directives.
(Mnemonic: -B/--cost uses transaction prices, -V/--value uses market prices.)
### Value date
### Value at another date
*(experimental, added 201904)*
You can select other valuation dates with the `--value-date` option:
You can select other valuation dates with the `--value-at` option. (This implies `-V`):
--value-date=VALUEDATE as of which date(s) should market values be
calculated ? transaction|period|current|YYYY-MM-DD
(default: current)
calculated ? transaction|period|now|YYYY-MM-DD
(default: now)
The argument must be one of those keywords, or their first letter, or a custom date.
The precise effect of the keywords is command-specific, but here is their general meaning:
- `--value-date=transaction` (or `t`)
- `--value-at=transaction` (or `t`)
: Use the prices as of each transaction date (more precisely, each [posting date](/journal.html#posting-dates)).
- `--value-date=period` (or `p`)
- `--value-at=period` (or `p`)
: Use the prices as of the last day of the report period (or each subperiod).
: Or if the report period is unspecified, as of the journal's last transaction date.
: When no report period is specified, this will be the journal's last transaction date.
- `--value-date=current` (or `c`)
: Use the prices as of today's date (when the report is generated). This is the default.
- `--value-at=now` (or `n`)
: Use the prices as of today's date when the report is generated. This is the default.
- `--value-date=YYYY-MM-DD`
- `--value-at=YYYY-MM-DD`
: Use the prices as of the given date (must be 8 digits with `-` or `/` or `.` separators).
: Eg `--value-date=2019-04-25`.
: Eg `--value-at=2019-04-25`.
Currently `--value-date` affects only the [print](/hledger.html#print) command.
Currently `--value-at` affects only the [print](/hledger.html#print) command.
Here are some examples to show its effect:
```journal
@ -535,7 +535,7 @@ P 2000-04-01 A 4 B
Show the value as of each transaction (posting) date:
```shell
$ hledger -f- print -V --value-date=transaction
$ hledger -f- print --value-at=transaction
2000/01/01
(a) 1 B
@ -549,7 +549,7 @@ $ hledger -f- print -V --value-date=transaction
Show the value as of the last day of the report period (2000-02-29):
```shell
$ hledger -f- print -V --value-date=period date:2000/01-2000/03
$ hledger -f- print --value-at=period date:2000/01-2000/03
2000-01-01
(a) 2 B
@ -560,7 +560,7 @@ $ hledger -f- print -V --value-date=period date:2000/01-2000/03
Or with no report period specified, show the value as of the last day of the journal (2000-03-01):
```shell
$ hledger -f- print -V --value-date=period
$ hledger -f- print --value-at=period
2000/01/01
(a) 3 B
@ -574,7 +574,7 @@ $ hledger -f- print -V --value-date=period
Show the current value (the last declared price is still in effect today):
```shell
$ hledger -f- print -V --value-date=current
$ hledger -f- print --value-at=now
2000-01-01
(a) 4 B
@ -588,7 +588,7 @@ $ hledger -f- print -V --value-date=current
Show the value on 2000/01/15:
```shell
$ hledger -f- print -V --value-date=2000-01-15
$ hledger -f- print --value-at=2000-01-15
2000/01/01
(a) 1 B
@ -600,10 +600,6 @@ $ hledger -f- print -V --value-date=2000-01-15
```
<!-- [multicolumn balance reports](#multicolumn-balance-reports): -->
## Combining -B and -V

View File

@ -118,7 +118,7 @@ $ hledger -f- print -V
>=0
# print -V --value-date
# print --value-at
<
P 2000/01/01 A 1 B
P 2000/02/01 A 2 B
@ -135,7 +135,7 @@ P 2000/04/01 A 4 B
(a) 1 A
# 9. value with prices on transaction (posting) dates
$ hledger -f- print -V --value-date=transaction
$ hledger -f- print --value-at=transaction
2000/01/01
(a) 1 B
@ -148,7 +148,7 @@ $ hledger -f- print -V --value-date=transaction
>=0
# 10. value with prices on last day of report period (2000-02-29)
$ hledger -f- print -V --value-date=period date:2000/01-2000/03
$ hledger -f- print --value-at=period date:2000/01-2000/03
2000/01/01
(a) 2 B
@ -159,7 +159,7 @@ $ hledger -f- print -V --value-date=period date:2000/01-2000/03
# 11. value with prices on last day of report period with no period
# specified - uses last day of journal (2000-03-01)
$ hledger -f- print -V --value-date=period
$ hledger -f- print --value-at=period
2000/01/01
(a) 3 B
@ -173,7 +173,7 @@ $ hledger -f- print -V --value-date=period
# 12. value with prices on current date
# (this test assumes today's date is >= 2000-04-01)
$ hledger -f- print -V --value-date=current
$ hledger -f- print --value-at=now
2000/01/01
(a) 4 B
@ -186,7 +186,7 @@ $ hledger -f- print -V --value-date=current
>=0
# 13. value with prices on a custom date
$ hledger -f- print -V --value-date=2000-01-15
$ hledger -f- print --value-at=2000-01-15
2000/01/01
(a) 1 B