diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-27 21:32:55 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-27 21:32:55 -0400 |
commit | ab433d28e08bbe23bbc75d333ed63343356e043a (patch) | |
tree | 273377e30b59a28de199e45fe66519ff8a387bf3 /src | |
parent | aae134f69275e4f71ec70d893cdfd0b5839fef8e (diff) | |
download | fork-ledger-ab433d28e08bbe23bbc75d333ed63343356e043a.tar.gz fork-ledger-ab433d28e08bbe23bbc75d333ed63343356e043a.tar.bz2 fork-ledger-ab433d28e08bbe23bbc75d333ed63343356e043a.zip |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/report.cc | 1 | ||||
-rw-r--r-- | src/report.h | 10 | ||||
-rw-r--r-- | src/times.cc | 2 | ||||
-rw-r--r-- | src/times.h | 11 |
4 files changed, 21 insertions, 3 deletions
diff --git a/src/report.cc b/src/report.cc index 7f31b615..87ebb71d 100644 --- a/src/report.cc +++ b/src/report.cc @@ -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_); diff --git a/src/report.h b/src/report.h index e665ac2d..40097c8d 100644 --- a/src/report.h +++ b/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_) {} diff --git a/src/times.cc b/src/times.cc index facdc4f6..7b6eb6e8 100644 --- a/src/times.cc +++ b/src/times.cc @@ -35,6 +35,8 @@ namespace ledger { +optional<datetime_t> epoch; + date_time::weekdays start_of_week = gregorian::Sunday; //#define USE_BOOST_FACETS 1 diff --git a/src/times.h b/src/times.h index c77cde1d..035d86cd 100644 --- a/src/times.h +++ b/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; |