diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-14 03:18:32 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-14 03:23:09 -0400 |
commit | dcffd218a1e90ee9a1cdd295c0a3015edc395448 (patch) | |
tree | 5957423c9ef3d629461f413e163917626c300c9d /src/times.cc | |
parent | e2fa8c6145679231cda5ad6b6e7440f6f16e654a (diff) | |
download | fork-ledger-dcffd218a1e90ee9a1cdd295c0a3015edc395448.tar.gz fork-ledger-dcffd218a1e90ee9a1cdd295c0a3015edc395448.tar.bz2 fork-ledger-dcffd218a1e90ee9a1cdd295c0a3015edc395448.zip |
Revised how Ledger handles the "current year"
Now when the Y directive sets the current year for a region, it affects
everything, as if the clock really were set back to that year.
Diffstat (limited to 'src/times.cc')
-rw-r--r-- | src/times.cc | 55 |
1 files changed, 22 insertions, 33 deletions
diff --git a/src/times.cc b/src/times.cc index 2610b44d..5eb969d7 100644 --- a/src/times.cc +++ b/src/times.cc @@ -194,7 +194,6 @@ namespace { std::deque<shared_ptr<date_io_t> > readers; date_t parse_date_mask_routine(const char * date_str, date_io_t& io, - optional_year year, date_traits_t * traits = NULL) { VERIFY(std::strlen(date_str) < 127); @@ -229,29 +228,26 @@ namespace { *traits = io.traits; if (! io.traits.has_year) { - when = date_t(year ? *year : CURRENT_DATE().year(), - when.month(), when.day()); + when = date_t(CURRENT_DATE().year(), when.month(), when.day()); - if (! year && when.month() > CURRENT_DATE().month()) + if (when.month() > CURRENT_DATE().month()) when -= gregorian::years(1); } } return when; } - date_t parse_date_mask(const char * date_str, optional_year year, - date_traits_t * traits = NULL) + date_t parse_date_mask(const char * date_str, date_traits_t * traits = NULL) { if (input_date_io.get()) { date_t when = parse_date_mask_routine(date_str, *input_date_io.get(), - year, traits); + traits); if (! when.is_not_a_date()) return when; } foreach (shared_ptr<date_io_t>& reader, readers) { - date_t when = parse_date_mask_routine(date_str, *reader.get(), - year, traits); + date_t when = parse_date_mask_routine(date_str, *reader.get(), traits); if (! when.is_not_a_date()) return when; } @@ -312,7 +308,7 @@ string_to_month_of_year(const std::string& str) return none; } -datetime_t parse_datetime(const char * str, optional_year) +datetime_t parse_datetime(const char * str) { datetime_t when = input_datetime_io->parse(str); if (when.is_not_a_date_time()) @@ -320,18 +316,16 @@ datetime_t parse_datetime(const char * str, optional_year) return when; } -date_t parse_date(const char * str, optional_year current_year) +date_t parse_date(const char * str) { - return parse_date_mask(str, current_year); + return parse_date_mask(str); } -date_t date_specifier_t::begin(const optional_year& current_year) const +date_t date_specifier_t::begin() const { - assert(year || current_year); - - year_type the_year = year ? *year : static_cast<year_type>(*current_year); + year_type the_year = year ? *year : year_type(CURRENT_DATE().year()); month_type the_month = month ? *month : date_t::month_type(1); - day_type the_day = day ? *day : date_t::day_type(1); + day_type the_day = day ? *day : date_t::day_type(1); #if !defined(NO_ASSERTS) if (day) @@ -348,14 +342,14 @@ date_t date_specifier_t::begin(const optional_year& current_year) const static_cast<date_t::day_type>(the_day)); } -date_t date_specifier_t::end(const optional_year& current_year) const +date_t date_specifier_t::end() const { if (day || wday) - return begin(current_year) + gregorian::days(1); + return begin() + gregorian::days(1); else if (month) - return begin(current_year) + gregorian::months(1); + return begin() + gregorian::months(1); else if (year) - return begin(current_year) + gregorian::years(1); + return begin() + gregorian::years(1); else { assert(false); return date_t(); @@ -1053,8 +1047,8 @@ void date_interval_t::stabilize(const optional<date_t>& date) // 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. - optional<date_t> initial_start = start ? start : begin(date->year()); - optional<date_t> initial_finish = finish ? finish : end(date->year()); + optional<date_t> initial_start = start ? start : begin(); + optional<date_t> initial_finish = finish ? finish : end(); #if defined(DEBUG_ON) if (initial_start) @@ -1117,13 +1111,8 @@ void date_interval_t::stabilize(const optional<date_t>& date) #endif } else if (range) { - if (date) { - start = range->begin(date->year()); - finish = range->end(date->year()); - } else { - start = range->begin(); - finish = range->end(); - } + start = range->begin(); + finish = range->end(); } aligned = true; } @@ -1229,7 +1218,7 @@ date_interval_t& date_interval_t::operator++() return *this; } -void date_interval_t::dump(std::ostream& out, optional_year current_year) +void date_interval_t::dump(std::ostream& out) { out << _("--- Before stabilization ---") << std::endl; @@ -1243,7 +1232,7 @@ void date_interval_t::dump(std::ostream& out, optional_year current_year) if (duration) out << _("duration: ") << duration->to_string() << std::endl; - stabilize(begin(current_year)); + stabilize(begin()); out << std::endl << _("--- After stabilization ---") << std::endl; @@ -1318,7 +1307,7 @@ date_parser_t::lexer_t::token_t date_parser_t::lexer_t::next_token() try { date_traits_t traits; - date_t when = parse_date_mask(possible_date.c_str(), none, &traits); + date_t when = parse_date_mask(possible_date.c_str(), &traits); if (! when.is_not_a_date()) { begin = i; return token_t(token_t::TOK_DATE, |