summaryrefslogtreecommitdiff
path: root/src/times.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/times.cc')
-rw-r--r--src/times.cc22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/times.cc b/src/times.cc
index 2c45cfcf..b66a6e30 100644
--- a/src/times.cc
+++ b/src/times.cc
@@ -1112,6 +1112,7 @@ date_interval_t date_parser_t::parse()
range.end_inclusive = end_inclusive;
period.range = date_specifier_or_range_t(range);
+ period.since_specified = static_cast<bool>(since_specifier);
}
else if (inclusion_specifier) {
period.range = date_specifier_or_range_t(*inclusion_specifier);
@@ -1180,7 +1181,7 @@ date_t date_duration_t::find_nearest(const date_t& date, skip_quantum_t skip)
return result;
}
-void date_interval_t::stabilize(const optional<date_t>& date)
+void date_interval_t::stabilize(const optional<date_t>& date, bool align_intervals)
{
#if DEBUG_ON
if (date)
@@ -1220,7 +1221,11 @@ void date_interval_t::stabilize(const optional<date_t>& date)
// These start on most recent period start quantum before when
DEBUG("times.interval",
"stabilize: monthly, quarterly or yearly duration");
- start = date_duration_t::find_nearest(when, duration->quantum);
+ if (align_intervals && since_specified) {
+ start = when;
+ } else {
+ start = date_duration_t::find_nearest(when, duration->quantum);
+ }
break;
case date_duration_t::WEEKS:
// Weeks start on the beginning of week prior to 400 remainder period length
@@ -1228,9 +1233,13 @@ void date_interval_t::stabilize(const optional<date_t>& date)
// implies period is never less than 400 days not too unreasonable
DEBUG("times.interval", "stabilize: weekly duration");
{
- int period = duration->length * 7;
- start = date_duration_t::find_nearest(
- when - gregorian::days(period + 400 % period), duration->quantum);
+ if (align_intervals && since_specified) {
+ start = when;
+ } else {
+ int period = duration->length * 7;
+ start = date_duration_t::find_nearest(
+ when - gregorian::days(period + 400 % period), duration->quantum);
+ }
}
break;
default:
@@ -1298,9 +1307,10 @@ void date_interval_t::stabilize(const optional<date_t>& date)
}
bool date_interval_t::find_period(const date_t& date,
+ const bool align_intervals,
const bool allow_shift)
{
- stabilize(date);
+ stabilize(date, align_intervals);
if (finish && date > *finish) {
DEBUG("times.interval",