From 9d61d3d621606f0158a048628c866a692465d886 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Thu, 4 Feb 2010 19:47:16 -0500 Subject: Added actual_date() methods for items --- src/item.cc | 5 +++++ src/item.h | 4 ++++ src/post.cc | 12 ++++++++++++ src/post.h | 1 + 4 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/item.cc b/src/item.cc index 135fa18f..8d1ba34f 100644 --- a/src/item.cc +++ b/src/item.cc @@ -199,6 +199,9 @@ namespace { value_t get_date(item_t& item) { return item.date(); } + value_t get_actual_date(item_t& item) { + return item.actual_date(); + } value_t get_effective_date(item_t& item) { if (optional effective = item.effective_date()) return *effective; @@ -351,6 +354,8 @@ expr_t::ptr_op_t item_t::lookup(const symbol_t::kind_t kind, case 'a': if (name == "actual") return WRAP_FUNCTOR(get_wrapper<&get_actual>); + else if (name == "actual_date") + return WRAP_FUNCTOR(get_wrapper<&get_actual_date>); break; case 'b': diff --git a/src/item.h b/src/item.h index 8250ab6e..f23350fc 100644 --- a/src/item.h +++ b/src/item.h @@ -173,6 +173,10 @@ public: return *effective; return *_date; } + virtual date_t actual_date() const { + assert(_date); + return *_date; + } virtual optional effective_date() const { return _date_eff; } diff --git a/src/post.cc b/src/post.cc index 34284e1b..5b9d2bb3 100644 --- a/src/post.cc +++ b/src/post.cc @@ -97,6 +97,18 @@ date_t post_t::date() const return *_date; } +date_t post_t::actual_date() const +{ + if (xdata_ && is_valid(xdata_->date)) + return xdata_->date; + + if (! _date) { + assert(xact); + return xact->date(); + } + return *_date; +} + optional post_t::effective_date() const { optional date = item_t::effective_date(); diff --git a/src/post.h b/src/post.h index a0ab5ffd..cea1aca1 100644 --- a/src/post.h +++ b/src/post.h @@ -105,6 +105,7 @@ public: const optional& value_mask = none) const; virtual date_t date() const; + virtual date_t actual_date() const; virtual optional effective_date() const; bool must_balance() const { -- cgit v1.2.3