From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH proxmox 2/2] time: calendar event: fix skipped events after a field wraps around
Date: Wed, 2 Dec 2026 10:41:08 +0100 [thread overview]
Message-ID: <20261202094209.1345186-3-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261202094209.1345186-1-d.csapak@proxmox.com>
For repetitions without an end (e.g. '1/5'), `find_next` returned the
next multiple even if that was not a valid value for the field
anymore. libc then carried the overflow into the next larger unit and
kept the remainder as an offset, so the first values there were
skipped.
For example, '1/5-5/10' (the 5th, 15th and 25th of January, June and
November) never triggered in January: in December, the next month was
calculated as 16, which is April of the next year, and the next match
from there is in June. The same happened for e.g. '0/5:00', which
skipped 00:00 every day.
This only worked when the overflow happened to land exactly on the
start of the next unit, like for '*/5' minutes or '*/3' months.
Days had the same problem even without a repetition, since not all
months have 31 days. E.g. '*-1,31' skipped the 1st of March, since the
31st of February is normalized to the 3rd of March (in non-leap
years).
To fix that, let `find_next` take the maximum valid value for the
field and return `None` for anything above it. The callers already
continue with the start of the next larger unit in that case.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
proxmox-time/src/calendar_event.rs | 13 +++++++------
proxmox-time/src/date_time_value.rs | 10 +++++++---
proxmox-time/src/test.rs | 26 ++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/proxmox-time/src/calendar_event.rs b/proxmox-time/src/calendar_event.rs
index 1cc0eae9..4e38fa53 100644
--- a/proxmox-time/src/calendar_event.rs
+++ b/proxmox-time/src/calendar_event.rs
@@ -94,7 +94,7 @@ impl CalendarEvent {
if !self.year.is_empty() {
let year: u32 = t.year().try_into()?;
if !DateTimeValue::list_contains(&self.year, year) {
- if let Some(n) = DateTimeValue::find_next(&self.year, year) {
+ if let Some(n) = DateTimeValue::find_next(&self.year, year, u32::MAX) {
t.add_years((n - year).try_into()?)?;
continue;
} else {
@@ -107,7 +107,7 @@ impl CalendarEvent {
if !self.month.is_empty() {
let month: u32 = t.month().try_into()?;
if !DateTimeValue::list_contains(&self.month, month) {
- if let Some(n) = DateTimeValue::find_next(&self.month, month) {
+ if let Some(n) = DateTimeValue::find_next(&self.month, month, 12) {
t.add_months((n - month).try_into()?)?;
} else {
// if we could not find valid month, retry next year
@@ -120,7 +120,8 @@ impl CalendarEvent {
if !self.day.is_empty() {
let day: u32 = t.day().try_into()?;
if !DateTimeValue::list_contains(&self.day, day) {
- if let Some(n) = DateTimeValue::find_next(&self.day, day) {
+ let last_day = t.days_in_month().try_into()?;
+ if let Some(n) = DateTimeValue::find_next(&self.day, day, last_day) {
t.add_days((n - day).try_into()?)?;
} else {
// if we could not find valid mday, retry next month
@@ -152,7 +153,7 @@ impl CalendarEvent {
if !self.hour.is_empty() {
let hour = t.hour().try_into()?;
if !DateTimeValue::list_contains(&self.hour, hour) {
- if let Some(n) = DateTimeValue::find_next(&self.hour, hour) {
+ if let Some(n) = DateTimeValue::find_next(&self.hour, hour, 23) {
// test next hour
t.set_time(n.try_into()?, 0, 0)?;
} else {
@@ -167,7 +168,7 @@ impl CalendarEvent {
if !self.minute.is_empty() {
let minute = t.min().try_into()?;
if !DateTimeValue::list_contains(&self.minute, minute) {
- if let Some(n) = DateTimeValue::find_next(&self.minute, minute) {
+ if let Some(n) = DateTimeValue::find_next(&self.minute, minute, 59) {
// test next minute
t.set_min_sec(n.try_into()?, 0)?;
} else {
@@ -182,7 +183,7 @@ impl CalendarEvent {
if !self.second.is_empty() {
let second = t.sec().try_into()?;
if !DateTimeValue::list_contains(&self.second, second) {
- if let Some(n) = DateTimeValue::find_next(&self.second, second) {
+ if let Some(n) = DateTimeValue::find_next(&self.second, second, 59) {
// test next second
t.set_sec(n.try_into()?)?;
} else {
diff --git a/proxmox-time/src/date_time_value.rs b/proxmox-time/src/date_time_value.rs
index 711ad205..7eeb7bf1 100644
--- a/proxmox-time/src/date_time_value.rs
+++ b/proxmox-time/src/date_time_value.rs
@@ -36,8 +36,8 @@ impl DateTimeValue {
list.iter().any(|spec| spec.contains(value))
}
- // Find an return an entry greater than value
- pub fn find_next(list: &[DateTimeValue], value: u32) -> Option<u32> {
+ // Find and return the smallest entry greater than value, but not greater than max
+ pub fn find_next(list: &[DateTimeValue], value: u32, max: u32) -> Option<u32> {
let mut next: Option<u32> = None;
let mut set_next = |v: u32| {
if let Some(n) = next {
@@ -82,6 +82,10 @@ impl DateTimeValue {
}
}
- next
+ match next {
+ // values past max would overflow into the next larger unit and skip its first entries
+ Some(n) if n > max => None,
+ other => other,
+ }
}
}
diff --git a/proxmox-time/src/test.rs b/proxmox-time/src/test.rs
index 306409f8..ec065b30 100644
--- a/proxmox-time/src/test.rs
+++ b/proxmox-time/src/test.rs
@@ -184,6 +184,32 @@ fn test_compute_next_event() -> Result<(), Error> {
test_value("2020-7..9-2/2", JUL_31_2020, JUL_31_2020 + 2 * DAY)?;
test_value("2020,2021-12-31", JUL_31_2020, DEC_31_2020)?;
+ // test that repetitions restart with the next larger unit
+ test_value("*:*:0/50", THURSDAY_00_00 + 50, THURSDAY_00_00 + MIN)?;
+ test_value("*:0/7", THURSDAY_00_00 + 56 * MIN, THURSDAY_00_00 + HOUR)?;
+ test_value("0/5:0", THURSDAY_00_00 + 20 * HOUR, THURSDAY_00_00 + DAY)?;
+ test_value("*/5-1", DEC_31_2020, DEC_31_2020 + DAY)?;
+
+ let n = test_value("1/5-5/10", DEC_31_2020, DEC_31_2020 + 5 * DAY)?;
+ let n = test_value("1/5-5/10", n, DEC_31_2020 + 15 * DAY)?;
+ let n = test_value("1/5-5/10", n, DEC_31_2020 + 25 * DAY)?;
+ // 2021-06-05
+ test_value(
+ "1/5-5/10",
+ n,
+ DEC_31_2020 + (31 + 28 + 31 + 30 + 31 + 5) * DAY,
+ )?;
+
+ // test days that do not exist in shorter months
+ test_value("*-*/10", (31 + 21) * DAY, (31 + 28) * DAY)?;
+ test_value("*-1,31", (31 + 1) * DAY, (31 + 28) * DAY)?;
+ // 1972-02-22 => 1972-03-01
+ test_value(
+ "*-*/10",
+ 2 * 365 * DAY + (31 + 21) * DAY,
+ 2 * 365 * DAY + (31 + 29) * DAY,
+ )?;
+
// keyword shortcuts
test_value("minutely", THURSDAY_00_00, THURSDAY_00_00 + MIN)?;
test_value("hourly", THURSDAY_00_00, THURSDAY_00_00 + HOUR)?;
--
2.47.3
prev parent reply other threads:[~2026-12-02 9:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 9:41 [PATCH proxmox 0/2] fix open ended repetitions in calendar events Dominik Csapak
2026-12-02 9:41 ` [PATCH proxmox 1/2] time: tm editor: add `days_in_month` helper Dominik Csapak
2026-12-02 9:41 ` Dominik Csapak [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202094209.1345186-3-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox