From 9a1e78dcc6d15a8f4674f8240add4327831d2dbf Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Fri, 9 Feb 2024 07:19:57 +0100 Subject: [PATCH] Bi-yearly recurring support --- src/recurring.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/recurring.cpp b/src/recurring.cpp index 072a81c..64242e8 100644 --- a/src/recurring.cpp +++ b/src/recurring.cpp @@ -29,7 +29,7 @@ namespace { data_handler recurrings { "recurrings", "recurrings.data" }; -const std::vector recurrences{"yearly", "quarterly", "monthly", "weekly"}; +const std::vector recurrences{"yearly", "bi-yearly", "quarterly", "monthly", "weekly"}; budget::date last_date(const budget::recurring& recurring) { budget::date last(1400, 1, 1); @@ -137,6 +137,29 @@ void budget::check_for_recurrings(){ recurring_date += budget::years(1); } } + } else if (recurring.recurs == "bi-yearly") { + if (recurring_not_triggered(recurring)) { + // If the recurring has never been created, we create it for + // the first time at the beginning of the current semester + + date_type semester_start = 6 * ((now.month() - date_type(1)) / 6) + 1; + + changed |= generate_recurring({now.year(), semester_start, 1}, recurring); + } else { + auto last = last_date(recurring); + + // If the recurring has already been triggered, we trigger again + // for each of the missing quarters + + budget::date recurring_date(last.year(), last.month() + date_type(6), 1); + + while (recurring_date < now) { + changed |= generate_recurring(recurring_date, recurring); + + // Get to the next quarter + recurring_date += budget::months(6); + } + } } else if (recurring.recurs == "quarterly") { if (recurring_not_triggered(recurring)) { // If the recurring has never been created, we create it for