Fixed the way interval_t objects are initialized
This commit is contained in:
parent
e50abb5645
commit
388044dec9
2 changed files with 11 additions and 13 deletions
20
src/times.cc
20
src/times.cc
|
|
@ -118,21 +118,19 @@ date_t parse_date(const char * str, int current_year)
|
||||||
return gregorian::date_from_tm(when);
|
return gregorian::date_from_tm(when);
|
||||||
}
|
}
|
||||||
|
|
||||||
date_t interval_t::first(const optional<date_t>& moment) const
|
date_t interval_t::first(const optional<date_t>& moment)
|
||||||
{
|
{
|
||||||
if (! is_valid(begin))
|
if (! is_valid(begin)) {
|
||||||
throw_(date_error,
|
// Find an efficient starting point for the upcoming while loop. We want
|
||||||
"Use of interval_t::first() with specifying a range start");
|
// 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);
|
date_t quant(begin);
|
||||||
|
|
||||||
if (moment && *moment > quant) {
|
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);
|
|
||||||
date_t temp;
|
date_t temp;
|
||||||
while (*moment >= (temp = increment(quant))) {
|
while (*moment >= (temp = increment(quant))) {
|
||||||
if (quant == temp)
|
if (quant == temp)
|
||||||
|
|
|
||||||
|
|
@ -162,10 +162,10 @@ struct interval_t
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_start(const date_t& moment) {
|
void set_start(const date_t& moment) {
|
||||||
begin = moment;
|
begin = first(moment);
|
||||||
}
|
}
|
||||||
|
|
||||||
date_t first(const optional<date_t>& moment = none) const;
|
date_t first(const optional<date_t>& moment = none);
|
||||||
date_t increment(const date_t&) const;
|
date_t increment(const date_t&) const;
|
||||||
|
|
||||||
void parse(std::istream& in);
|
void parse(std::istream& in);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue