Support a --now option, for testing purposes
This sets Ledger's notion of the "current time" to the given date. This makes it possible to have stable output from budgeting and forecasting reports, for the sake of baseline tests.
This commit is contained in:
parent
aae134f692
commit
ab433d28e0
5 changed files with 22 additions and 4 deletions
|
|
@ -592,6 +592,7 @@ option_t<report_t> * report_t::lookup_option(const char * p)
|
|||
OPT_CH(collapse);
|
||||
else OPT(no_color);
|
||||
else OPT(no_total);
|
||||
else OPT(now_);
|
||||
break;
|
||||
case 'o':
|
||||
OPT(only_);
|
||||
|
|
|
|||
10
src/report.h
10
src/report.h
|
|
@ -250,6 +250,7 @@ public:
|
|||
HANDLER(market).report(out);
|
||||
HANDLER(monthly).report(out);
|
||||
HANDLER(no_total).report(out);
|
||||
HANDLER(now_).report(out);
|
||||
HANDLER(only_).report(out);
|
||||
HANDLER(output_).report(out);
|
||||
HANDLER(pager_).report(out);
|
||||
|
|
@ -602,6 +603,15 @@ public:
|
|||
|
||||
OPTION(report_t, no_total);
|
||||
|
||||
OPTION_(report_t, now_, DO_(args) {
|
||||
date_interval_t interval(args[1].to_string());
|
||||
if (! interval.start)
|
||||
throw_(std::invalid_argument,
|
||||
_("Could not determine beginning of period '%1'")
|
||||
<< args[1].to_string());
|
||||
ledger::epoch = datetime_t(*interval.start);
|
||||
});
|
||||
|
||||
OPTION__
|
||||
(report_t, only_,
|
||||
CTOR(report_t, only_) {}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
namespace ledger {
|
||||
|
||||
optional<datetime_t> epoch;
|
||||
|
||||
date_time::weekdays start_of_week = gregorian::Sunday;
|
||||
|
||||
//#define USE_BOOST_FACETS 1
|
||||
|
|
|
|||
11
src/times.h
11
src/times.h
|
|
@ -66,12 +66,17 @@ inline bool is_valid(const date_t& moment) {
|
|||
return ! moment.is_not_a_date();
|
||||
}
|
||||
|
||||
extern optional<datetime_t> epoch;
|
||||
|
||||
#ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK
|
||||
#define CURRENT_TIME() boost::posix_time::microsec_clock::universal_time()
|
||||
#define CURRENT_TIME() \
|
||||
(epoch ? *epoch : boost::posix_time::microsec_clock::universal_time())
|
||||
#else
|
||||
#define CURRENT_TIME() boost::posix_time::second_clock::universal_time()
|
||||
#define CURRENT_TIME() \
|
||||
(epoch ? *epoch : boost::posix_time::second_clock::universal_time())
|
||||
#endif
|
||||
#define CURRENT_DATE() boost::gregorian::day_clock::universal_day()
|
||||
#define CURRENT_DATE() \
|
||||
(epoch ? epoch->date() : boost::gregorian::day_clock::universal_day())
|
||||
|
||||
extern date_time::weekdays start_of_week;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
reg --forecast-while='total < $3500' books
|
||||
reg --now=2009/03/21 --forecast-while='total < $3500' books
|
||||
<<<
|
||||
~ monthly
|
||||
Expenses:Books $10.00
|
||||
Loading…
Add table
Reference in a new issue