Skip to content

Commit

Permalink
Merge pull request #31 from bahmanrafatjoo/master
Browse files Browse the repository at this point in the history
Fix for Bug in handling cronspecs with 31-day months #30
  • Loading branch information
mariusbancila authored Mar 30, 2023
2 parents 5c28f41 + 4506003 commit e817348
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/croncpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 17 additions & 0 deletions test/test_standard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]")
Expand Down

0 comments on commit e817348

Please sign in to comment.