From 388044dec99a9ed27bfdefe3c07234e4b27b3997 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Sat, 14 Feb 2009 04:27:15 -0400 Subject: Fixed the way interval_t objects are initialized --- src/times.cc | 20 +++++++++----------- src/times.h | 4 ++-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/times.cc b/src/times.cc index 77968127..4ea7389b 100644 --- a/src/times.cc +++ b/src/times.cc @@ -118,21 +118,19 @@ date_t parse_date(const char * str, int current_year) return gregorian::date_from_tm(when); } -date_t interval_t::first(const optional& moment) const +date_t interval_t::first(const optional& moment) { - if (! is_valid(begin)) - throw_(date_error, - "Use of interval_t::first() with specifying a range start"); + if (! is_valid(begin)) { + // Find an efficient starting point for the upcoming while loop. We want + // a date early enough that the range will be correct, but late enough + // that we don't spend hundreds of thousands of loops skipping through + // time. + begin = date_t(moment->year(), gregorian::Jan, 1); + } date_t quant(begin); - if (moment && *moment > quant) { - // Find an efficient starting point for the upcoming while loop. - // We want a date early enough that the range will be correct, but - // late enough that we don't spend hundreds of thousands of loops - // skipping through time. - - date_t quant(moment->year(), gregorian::Jan, 1); + if (moment && *moment >= quant) { date_t temp; while (*moment >= (temp = increment(quant))) { if (quant == temp) diff --git a/src/times.h b/src/times.h index 2d47d60b..54c1dc80 100644 --- a/src/times.h +++ b/src/times.h @@ -162,10 +162,10 @@ struct interval_t } void set_start(const date_t& moment) { - begin = moment; + begin = first(moment); } - date_t first(const optional& moment = none) const; + date_t first(const optional& moment = none); date_t increment(const date_t&) const; void parse(std::istream& in); -- cgit v1.2.3