summaryrefslogtreecommitdiff
path: root/src/times.cc
diff options
context:
space:
mode:
authorIan2020 <Ian2020@users.noreply.github.com>2023-11-29 13:12:24 +0000
committerJohn Wiegley <johnw@newartisans.com>2024-08-06 11:08:15 -1000
commit762353945a744ae4b89970b9e08c2c22a52ddbff (patch)
tree1e3cc5fcbe4f89c5134f0fcb7a5f7ba3a8fb372d /src/times.cc
parentb7be0a1fedfeec26e4b7d35357157d5a9209f3ee (diff)
downloadfork-ledger-762353945a744ae4b89970b9e08c2c22a52ddbff.tar.gz
fork-ledger-762353945a744ae4b89970b9e08c2c22a52ddbff.tar.bz2
fork-ledger-762353945a744ae4b89970b9e08c2c22a52ddbff.zip
Add new --align-intervals option.
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",