diff options
-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 | ||||
-rw-r--r-- | test/baseline/opt-forecast-while.test (renamed from test/baseline/opt-forecast-while.test.save) | 2 |
5 files changed, 22 insertions, 4 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; diff --git a/test/baseline/opt-forecast-while.test.save b/test/baseline/opt-forecast-while.test index 91e3a24f..e3f1c57a 100644 --- a/test/baseline/opt-forecast-while.test.save +++ b/test/baseline/opt-forecast-while.test @@ -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 |