Skip to content

Commit e817348

Browse files
Merge pull request #31 from bahmanrafatjoo/master
Fix for Bug in handling cronspecs with 31-day months #30
2 parents 5c28f41 + 4506003 commit e817348

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

include/croncpp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,11 @@ namespace cron
563563
case cron_field::day_of_week:
564564
case cron_field::day_of_month:
565565
date.tm_mday += val;
566+
date.tm_isdst = -1;
566567
break;
567568
case cron_field::month:
568569
date.tm_mon += val;
570+
date.tm_isdst = -1;
569571
break;
570572
case cron_field::year:
571573
date.tm_year += val;
@@ -597,9 +599,11 @@ namespace cron
597599
break;
598600
case cron_field::day_of_month:
599601
date.tm_mday = val;
602+
date.tm_isdst = -1;
600603
break;
601604
case cron_field::month:
602605
date.tm_mon = val;
606+
date.tm_isdst = -1;
603607
break;
604608
case cron_field::year:
605609
date.tm_year = val;
@@ -630,9 +634,11 @@ namespace cron
630634
break;
631635
case cron_field::day_of_month:
632636
date.tm_mday = 1;
637+
date.tm_isdst = -1;
633638
break;
634639
case cron_field::month:
635640
date.tm_mon = 0;
641+
date.tm_isdst = -1;
636642
break;
637643
case cron_field::year:
638644
date.tm_year = 0;

test/test_standard.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,23 @@ TEST_CASE("next", "[std]")
417417
check_next("0 30 23 30 1/3 ?", "2010-12-30 00:00:00", "2011-01-30 23:30:00");
418418
check_next("0 30 23 30 1/3 ?", "2011-01-30 23:30:00", "2011-04-30 23:30:00");
419419
check_next("0 30 23 30 1/3 ?", "2011-04-30 23:30:00", "2011-07-30 23:30:00");
420+
421+
// Last day of month in and out of DST
422+
check_next("0 25 23 31 12 ?", "2011-09-22 14:20:00", "2011-12-31 23:25:00");
423+
check_next("0 25 23 31 12 ?", "2011-12-31 23:30:00", "2012-12-31 23:25:00");
424+
check_next("0 25 23 30 11 ?", "2011-09-22 14:20:00", "2011-11-30 23:25:00");
425+
check_next("0 25 23 30 11 ?", "2011-10-22 14:20:00", "2011-11-30 23:25:00");
426+
check_next("0 25 23 30 11 ?", "2011-11-22 14:20:00", "2011-11-30 23:25:00");
427+
check_next("0 25 23 30 11 ?", "2011-12-22 14:20:00", "2012-11-30 23:25:00");
428+
check_next("0 25 23 31 10 ?", "2011-09-22 14:20:00", "2011-10-31 23:25:00");
429+
check_next("0 25 23 31 10 ?", "2011-10-22 14:20:00", "2011-10-31 23:25:00");
430+
check_next("0 25 23 31 10 ?", "2011-10-31 23:30:00", "2012-10-31 23:25:00");
431+
check_next("0 25 23 31 10 ?", "2011-11-22 14:20:00", "2012-10-31 23:25:00");
432+
check_next("0 25 23 31 8 ?", "2011-09-22 14:20:00", "2012-08-31 23:25:00");
433+
check_next("0 25 23 31 7 ?", "2011-09-22 14:20:00", "2012-07-31 23:25:00");
434+
check_next("0 25 23 30 6 ?", "2011-09-22 14:20:00", "2012-06-30 23:25:00");
435+
check_next("0 25 23 31 5 ?", "2011-09-22 14:20:00", "2012-05-31 23:25:00");
436+
check_next("0 25 23 30 4 ?", "2011-09-22 14:20:00", "2012-04-30 23:25:00");
420437
}
421438

422439
TEST_CASE("cronexpr", "[std]")

0 commit comments

Comments
 (0)