From 450600388a176310399ae77f4571b0620abeab91 Mon Sep 17 00:00:00 2001 From: "Rafatjoo, Bahman" Date: Fri, 18 Nov 2022 13:18:05 +0000 Subject: [PATCH] Fix for Bug in handling cronspecs with 31-day months #30 --- include/croncpp.h | 6 ++++++ test/test_standard.cpp | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/croncpp.h b/include/croncpp.h index 3c7c31c..b0037c0 100644 --- a/include/croncpp.h +++ b/include/croncpp.h @@ -563,9 +563,11 @@ namespace cron case cron_field::day_of_week: case cron_field::day_of_month: date.tm_mday += val; + date.tm_isdst = -1; break; case cron_field::month: date.tm_mon += val; + date.tm_isdst = -1; break; case cron_field::year: date.tm_year += val; @@ -597,9 +599,11 @@ namespace cron break; case cron_field::day_of_month: date.tm_mday = val; + date.tm_isdst = -1; break; case cron_field::month: date.tm_mon = val; + date.tm_isdst = -1; break; case cron_field::year: date.tm_year = val; @@ -630,9 +634,11 @@ namespace cron break; case cron_field::day_of_month: date.tm_mday = 1; + date.tm_isdst = -1; break; case cron_field::month: date.tm_mon = 0; + date.tm_isdst = -1; break; case cron_field::year: date.tm_year = 0; diff --git a/test/test_standard.cpp b/test/test_standard.cpp index 854d3ae..bf181f7 100644 --- a/test/test_standard.cpp +++ b/test/test_standard.cpp @@ -417,6 +417,23 @@ TEST_CASE("next", "[std]") check_next("0 30 23 30 1/3 ?", "2010-12-30 00:00:00", "2011-01-30 23:30:00"); check_next("0 30 23 30 1/3 ?", "2011-01-30 23:30:00", "2011-04-30 23:30:00"); check_next("0 30 23 30 1/3 ?", "2011-04-30 23:30:00", "2011-07-30 23:30:00"); + + // Last day of month in and out of DST + check_next("0 25 23 31 12 ?", "2011-09-22 14:20:00", "2011-12-31 23:25:00"); + check_next("0 25 23 31 12 ?", "2011-12-31 23:30:00", "2012-12-31 23:25:00"); + check_next("0 25 23 30 11 ?", "2011-09-22 14:20:00", "2011-11-30 23:25:00"); + check_next("0 25 23 30 11 ?", "2011-10-22 14:20:00", "2011-11-30 23:25:00"); + check_next("0 25 23 30 11 ?", "2011-11-22 14:20:00", "2011-11-30 23:25:00"); + check_next("0 25 23 30 11 ?", "2011-12-22 14:20:00", "2012-11-30 23:25:00"); + check_next("0 25 23 31 10 ?", "2011-09-22 14:20:00", "2011-10-31 23:25:00"); + check_next("0 25 23 31 10 ?", "2011-10-22 14:20:00", "2011-10-31 23:25:00"); + check_next("0 25 23 31 10 ?", "2011-10-31 23:30:00", "2012-10-31 23:25:00"); + check_next("0 25 23 31 10 ?", "2011-11-22 14:20:00", "2012-10-31 23:25:00"); + check_next("0 25 23 31 8 ?", "2011-09-22 14:20:00", "2012-08-31 23:25:00"); + check_next("0 25 23 31 7 ?", "2011-09-22 14:20:00", "2012-07-31 23:25:00"); + check_next("0 25 23 30 6 ?", "2011-09-22 14:20:00", "2012-06-30 23:25:00"); + check_next("0 25 23 31 5 ?", "2011-09-22 14:20:00", "2012-05-31 23:25:00"); + check_next("0 25 23 30 4 ?", "2011-09-22 14:20:00", "2012-04-30 23:25:00"); } TEST_CASE("cronexpr", "[std]")