diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-14 08:14:48 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-14 08:14:48 -0400 |
commit | 63b4bdaecff5a865bff22e8e7914bef6ab46fa6b (patch) | |
tree | e6e5954f40a09e7fd002f242523c1eb0f318b397 /src/times.cc | |
parent | d9d04f62a3fc8196224b30a2cc47651b92e0fb31 (diff) | |
download | fork-ledger-63b4bdaecff5a865bff22e8e7914bef6ab46fa6b.tar.gz fork-ledger-63b4bdaecff5a865bff22e8e7914bef6ab46fa6b.tar.bz2 fork-ledger-63b4bdaecff5a865bff22e8e7914bef6ab46fa6b.zip |
Support period expressions "this/next/last week"
Diffstat (limited to 'src/times.cc')
-rw-r--r-- | src/times.cc | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/src/times.cc b/src/times.cc index 26c91ea4..31367e34 100644 --- a/src/times.cc +++ b/src/times.cc @@ -851,26 +851,40 @@ date_interval_t date_parser_t::parse() } case lexer_t::token_t::TOK_QUARTER: { - date_t temp = + date_t base = date_duration_t::find_nearest(today, date_duration_t::QUARTERS); - temp += gregorian::months(3 * adjust); - inclusion_specifier = - date_specifier_t(static_cast<date_specifier_t::year_type>(temp.year()), - temp.month()); -#if 0 - period.duration = date_duration_t(date_duration_t::QUARTERS, 1); -#endif + date_t temp; + if (adjust < 0) { + temp = base + gregorian::months(3 * adjust); + } + else if (adjust == 0) { + temp = base + gregorian::months(3); + } + else if (adjust > 0) { + base += gregorian::months(3 * adjust); + temp = base + gregorian::months(3 * adjust); + } + since_specifier = date_specifier_t(adjust < 0 ? temp : base); + until_specifier = date_specifier_t(adjust < 0 ? base : temp); break; } case lexer_t::token_t::TOK_WEEK: { - date_t temp = + date_t base = date_duration_t::find_nearest(today, date_duration_t::WEEKS); - temp += gregorian::days(7 * adjust); - inclusion_specifier = date_specifier_t(today); -#if 0 - period.duration = date_duration_t(date_duration_t::WEEKS, 1); -#endif + date_t temp; + if (adjust < 0) { + temp = base + gregorian::days(7 * adjust); + } + else if (adjust == 0) { + temp = base + gregorian::days(7); + } + else if (adjust > 0) { + base += gregorian::days(7 * adjust); + temp = base + gregorian::days(7 * adjust); + } + since_specifier = date_specifier_t(adjust < 0 ? temp : base); + until_specifier = date_specifier_t(adjust < 0 ? base : temp); break; } |