Permalink
Browse files

First iteration of the new date_interval_t rewrite

  • Loading branch information...
1 parent 1889d44 commit a05353e26928464b485767cc843ec5b3d9e47040 @jwiegley jwiegley committed Mar 15, 2009
Showing with 389 additions and 273 deletions.
  1. +35 −41 src/filters.cc
  2. +21 −19 src/filters.h
  3. +41 −12 src/precmd.cc
  4. +6 −6 src/report.h
  5. +217 −119 src/times.cc
  6. +61 −71 src/times.h
  7. +5 −2 src/token.cc
  8. +3 −3 src/xact.h
View
@@ -562,7 +562,7 @@ void interval_posts::report_subtotal(const date_t& finish)
if (exact_periods)
subtotal_posts::report_subtotal();
else
- subtotal_posts::report_subtotal(NULL, interval.begin, finish);
+ subtotal_posts::report_subtotal(NULL, *interval.start, finish);
}
last_post = NULL;
@@ -572,49 +572,37 @@ void interval_posts::operator()(post_t& post)
{
date_t date = post.date();
- if ((is_valid(interval.begin) && date < interval.begin) ||
- (is_valid(interval.end) && date >= interval.end))
+ if (! interval.find_period(post.date(), &last_interval))
return;
- if (interval) {
- if (! is_valid(interval.begin))
- interval.set_start(date);
- start = interval.begin;
-
- date_t quant = interval.increment(interval.begin);
- if (date >= quant) {
- if (last_post)
- report_subtotal(quant - gregorian::days(1));
-
- date_t temp;
- while (date >= (temp = interval.increment(quant))) {
- if (quant == temp)
- break;
- interval.begin = quant;
- quant = temp;
+ if (interval.duration) {
+ if (last_interval) {
+ if (interval != last_interval) {
+ report_subtotal(last_interval.inclusive_end());
if (generate_empty_posts) {
- // Generate a null posting, so the intervening periods can be
- // seen when -E is used, or if the calculated amount ends up being
- // non-zero
- xact_temps.push_back(xact_t());
- xact_t& null_xact = xact_temps.back();
- null_xact.add_flags(ITEM_TEMP);
- null_xact._date = quant - gregorian::days(1);
-
- post_temps.push_back(post_t(&empty_account));
- post_t& null_post = post_temps.back();
- null_post.add_flags(ITEM_TEMP | POST_CALCULATED);
- null_post.amount = 0L;
- null_xact.add_post(&null_post);
-
- last_post = &null_post;
- subtotal_posts::operator()(null_post);
-
- report_subtotal(quant - gregorian::days(1));
+ for (++last_interval; interval != last_interval; ++last_interval) {
+ // Generate a null posting, so the intervening periods can be
+ // seen when -E is used, or if the calculated amount ends up being
+ // non-zero
+ xact_temps.push_back(xact_t());
+ xact_t& null_xact = xact_temps.back();
+ null_xact.add_flags(ITEM_TEMP);
+ null_xact._date = last_interval.inclusive_end();
+
+ post_temps.push_back(post_t(&empty_account));
+ post_t& null_post = post_temps.back();
+ null_post.add_flags(ITEM_TEMP | POST_CALCULATED);
+ null_post.amount = 0L;
+ null_xact.add_post(&null_post);
+
+ last_post = &null_post;
+ subtotal_posts::operator()(null_post);
+
+ report_subtotal(last_interval.inclusive_end());
+ }
}
}
- start = interval.begin = quant;
}
subtotal_posts::operator()(post);
} else {
@@ -745,7 +733,7 @@ void generate_posts::add_period_xacts(period_xacts_list& period_xacts)
add_post(xact->period, *post);
}
-void generate_posts::add_post(const interval_t& period, post_t& post)
+void generate_posts::add_post(const date_interval_t& period, post_t& post)
{
pending_posts.push_back(pending_posts_pair(period, &post));
}
@@ -759,6 +747,7 @@ void budget_posts::report_budget_items(const date_t& date)
do {
reported = false;
foreach (pending_posts_list::value_type& pair, pending_posts) {
+#if 0
date_t& begin = pair.first.begin;
if (! is_valid(begin)) {
pair.first.set_start(date);
@@ -790,6 +779,7 @@ void budget_posts::report_budget_items(const date_t& date)
reported = true;
}
+#endif
}
} while (reported);
}
@@ -823,25 +813,28 @@ void budget_posts::operator()(post_t& post)
}
}
-void forecast_posts::add_post(const interval_t& period, post_t& post)
+void forecast_posts::add_post(const date_interval_t& period, post_t& post)
{
generate_posts::add_post(period, post);
- interval_t& i = pending_posts.back().first;
+ date_interval_t& i = pending_posts.back().first;
+#if 0
if (! is_valid(i.begin)) {
i.set_start(CURRENT_DATE());
i.begin = i.increment(i.begin);
} else {
while (i.begin < CURRENT_DATE())
i.begin = i.increment(i.begin);
}
+#endif
}
void forecast_posts::flush()
{
posts_list passed;
date_t last;
+#if 0
while (pending_posts.size() > 0) {
pending_posts_list::iterator least = pending_posts.begin();
for (pending_posts_list::iterator i = ++pending_posts.begin();
@@ -900,6 +893,7 @@ void forecast_posts::flush()
}
}
}
+#endif
item_handler<post_t>::flush();
}
View
@@ -558,22 +558,22 @@ class subtotal_posts : public item_handler<post_t>
*/
class interval_posts : public subtotal_posts
{
- interval_t interval;
- post_t * last_post;
- account_t empty_account;
- bool exact_periods;
- bool generate_empty_posts;
- date_t start;
+ date_interval_t interval;
+ date_interval_t last_interval;
+ post_t * last_post;
+ account_t empty_account;
+ bool exact_periods;
+ bool generate_empty_posts;
interval_posts();
public:
- interval_posts(post_handler_ptr _handler,
- expr_t& amount_expr,
- const interval_t& _interval,
- bool _exact_periods = false,
- bool _generate_empty_posts = false)
+ interval_posts(post_handler_ptr _handler,
+ expr_t& amount_expr,
+ const date_interval_t& _interval,
+ bool _exact_periods = false,
+ bool _generate_empty_posts = false)
: subtotal_posts(_handler, amount_expr), interval(_interval),
last_post(NULL), empty_account(NULL, _("<None>")),
exact_periods(_exact_periods),
@@ -588,9 +588,11 @@ class interval_posts : public subtotal_posts
void report_subtotal(const date_t& finish);
virtual void flush() {
- if (last_post && interval)
- report_subtotal(interval.increment(interval.begin) - gregorian::days(1));
- subtotal_posts::flush();
+ if (last_post && interval.duration) {
+ if (interval.is_valid())
+ report_subtotal(interval.inclusive_end());
+ subtotal_posts::flush();
+ }
}
virtual void operator()(post_t& post);
};
@@ -725,11 +727,11 @@ class generate_posts : public item_handler<post_t>
generate_posts();
protected:
- typedef std::pair<interval_t, post_t *> pending_posts_pair;
- typedef std::list<pending_posts_pair> pending_posts_list;
+ typedef std::pair<date_interval_t, post_t *> pending_posts_pair;
+ typedef std::list<pending_posts_pair> pending_posts_list;
pending_posts_list pending_posts;
- std::list<xact_t> xact_temps;
+ std::list<xact_t> xact_temps;
std::list<post_t> post_temps;
public:
@@ -745,7 +747,7 @@ class generate_posts : public item_handler<post_t>
void add_period_xacts(period_xacts_list& period_xacts);
- virtual void add_post(const interval_t& period, post_t& post);
+ virtual void add_post(const date_interval_t& period, post_t& post);
};
/**
@@ -800,7 +802,7 @@ class forecast_posts : public generate_posts
TRACE_DTOR(forecast_posts);
}
- virtual void add_post(const interval_t& period, post_t& post);
+ virtual void add_post(const date_interval_t& period, post_t& post);
virtual void flush();
};
View
@@ -160,25 +160,54 @@ value_t period_command(call_scope_t& args)
report_t& report(find_scope<report_t>(args));
std::ostream& out(report.output_stream);
- interval_t interval(arg);
+ date_interval_t interval(arg);
+
+ out << _("global details => ") << std::endl << std::endl;
+
+ if (interval.start)
+ out << _(" start: ") << format_date(*interval.start) << std::endl;
+ else
+ out << _(" start: TODAY: ") << format_date(CURRENT_DATE()) << std::endl;
+ if (interval.end)
+ out << _(" end: ") << format_date(*interval.end) << std::endl;
+
+ if (interval.skip_duration)
+ out << _(" skip: ") << *interval.skip_duration << std::endl;
+ if (interval.factor)
+ out << _(" factor: ") << interval.factor << std::endl;
+ if (interval.duration)
+ out << _("duration: ") << *interval.duration << std::endl;
+
+ if (interval.find_period(interval.start ?
+ *interval.start : CURRENT_DATE())) {
+ out << std::endl
+ << _("after finding first period => ") << std::endl
+ << std::endl;
+
+ if (interval.start)
+ out << _(" start: ") << format_date(*interval.start) << std::endl;
+ if (interval.end)
+ out << _(" end: ") << format_date(*interval.end) << std::endl;
+
+ if (interval.skip_duration)
+ out << _(" skip: ") << *interval.skip_duration << std::endl;
+ if (interval.factor)
+ out << _(" factor: ") << interval.factor << std::endl;
+ if (interval.duration)
+ out << _("duration: ") << *interval.duration << std::endl;
- if (! is_valid(interval.begin)) {
- out << _("Time period has no beginning.") << std::endl;
- } else {
- out << _("begin: ") << format_date(interval.begin) << std::endl;
- out << _(" end: ") << format_date(interval.end) << std::endl;
out << std::endl;
- date_t date = interval.first();
-
- for (int i = 0; i < 20; i++) {
+ for (int i = 0; i < 20 && interval; i++, ++interval) {
out << std::right;
out.width(2);
- out << i << "): " << format_date(date) << std::endl;
+ out << i << "): " << format_date(*interval.start);
+ if (interval.end_of_duration)
+ out << " -- " << format_date(interval.inclusive_end());
+ out << std::endl;
- date = interval.increment(date);
- if (is_valid(interval.end) && date >= interval.end)
+ if (! interval.skip_duration)
break;
}
}
View
@@ -240,14 +240,14 @@ class report_t : public scope_t
});
OPTION_(report_t, begin_, DO_(args) { // -b
- interval_t interval(args[0].to_string());
- if (! is_valid(interval.begin))
+ date_interval_t interval(args[0].to_string());
+ if (! interval.start)
throw_(std::invalid_argument,
_("Could not determine beginning of period '%1'")
<< args[0].to_string());
string predicate =
- "date>=[" + to_iso_extended_string(interval.begin) + "]";
+ "date>=[" + to_iso_extended_string(*interval.start) + "]";
parent->HANDLER(limit_).on(predicate);
});
@@ -355,14 +355,14 @@ class report_t : public scope_t
OPTION(report_t, empty); // -E
OPTION_(report_t, end_, DO_(args) { // -e
- interval_t interval(args[0].to_string());
- if (! is_valid(interval.begin))
+ date_interval_t interval(args[0].to_string());
+ if (! interval.start)
throw_(std::invalid_argument,
_("Could not determine end of period '%1'")
<< args[0].to_string());
string predicate =
- "date<[" + to_iso_extended_string(interval.begin) + "]";
+ "date<[" + to_iso_extended_string(*interval.start) + "]";
parent->HANDLER(limit_).on(predicate);
#if 0
terminus = interval.begin;
Oops, something went wrong.

0 comments on commit a05353e

Please sign in to comment.