]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
calendarspec: day of month also needs to be reset when year is changed
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Jan 2026 00:37:46 +0000 (09:37 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 4 Jan 2026 11:05:43 +0000 (20:05 +0900)
Fixes #40260.

src/shared/calendarspec.c
src/test/test-calendarspec.c

index 88a4467187c5dd4276147afee3cc65c8a21a9bf9..dc13ae0f77994f11a3ea09230d75362bca0c0020 100644 (file)
@@ -1194,9 +1194,10 @@ static int tm_within_bounds(struct tm *tm, bool utc) {
          * other sub time units are already reset in find_next().
          */
         int cmp;
-        if ((cmp = CMP(t.tm_year, tm->tm_year)) != 0)
+        if ((cmp = CMP(t.tm_year, tm->tm_year)) != 0) {
                 t.tm_mon = 0;
-        else if ((cmp = CMP(t.tm_mon, tm->tm_mon)) != 0)
+                t.tm_mday = 1;
+        } else if ((cmp = CMP(t.tm_mon, tm->tm_mon)) != 0)
                 t.tm_mday = 1;
         else if ((cmp = CMP(t.tm_mday, tm->tm_mday)) != 0)
                 t.tm_hour = 0;
index 0b1cbacd625a2edc563f631d9928972619f6c5a4..6c901b1893c5786510ccbc90be381dba4352ffc9 100644 (file)
@@ -219,6 +219,8 @@ TEST(calendar_spec_next) {
         test_next("Sun *-*-* 01:00:00 Europe/Dublin", "IST", 1616412478000000, 1617494400000000);
         /* Europe/Dublin TZ that moves DST backwards */
         test_next("hourly", "IST-1GMT-0,M10.5.0/1,M3.5.0/1", 1743292800000000, 1743296400000000);
+        /* Check when the year changes, see issue #40260 */
+        test_next("*-*-1/11 23:00:00 UTC", "", 1763938800000000, 1764630000000000);
 }
 
 TEST(calendar_spec_from_string) {