croncpp
croncpp copied to clipboard
Wrong timestamp when set day of month and day of week
If I set the cronjob 0 0 0 1 1 1 (https://crontab.guru/#0_0_1_1_1) and want to have the next timestamp, I expect Friday, January 1. 2021. But my program crashes with a stack overflow, because it is looking for the 1st of January which is also on a Monday.
By making this change I could fix the problem locally:
template <typename Traits>
static size_t find_next_day(
std::tm& date,
std::bitset<31> const & days_of_month,
size_t day_of_month,
std::bitset<7> const & days_of_week,
size_t day_of_week,
std::bitset<7> const & marked_fields)
{
unsigned int count = 0;
unsigned int maximum = 366;
const auto is_all_days_of_month = days_of_month.all();
const auto is_all_days_of_week = days_of_week.all();
while (
count++ < maximum && (
(is_all_days_of_month && is_all_days_of_week && (!days_of_month.test(day_of_month - Traits::CRON_MIN_DAYS_OF_MONTH) || !days_of_week.test(day_of_week - Traits::CRON_MIN_DAYS_OF_WEEK)))
||
(!is_all_days_of_month && is_all_days_of_week && (!days_of_month.test(day_of_month - Traits::CRON_MIN_DAYS_OF_MONTH)))
||
(is_all_days_of_month && !is_all_days_of_week && (!days_of_week.test(day_of_week - Traits::CRON_MIN_DAYS_OF_WEEK)))
||
(!is_all_days_of_month && !is_all_days_of_week && (!days_of_month.test(day_of_month - Traits::CRON_MIN_DAYS_OF_MONTH) && !days_of_week.test(day_of_week - Traits::CRON_MIN_DAYS_OF_WEEK)))
)`
)
{
add_to_field(date, cron_field::day_of_month, 1);
day_of_month = date.tm_mday;
day_of_week = date.tm_wday;
reset_all_fields(date, marked_fields);
}
return day_of_month;
}
CRON: * 45 12 ? 3 3 bitset test argument out of range