Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong timestamp when set day of month and day of week #12

Open
Kevni92 opened this issue Oct 8, 2020 · 1 comment
Open

Wrong timestamp when set day of month and day of week #12

Kevni92 opened this issue Oct 8, 2020 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@Kevni92
Copy link

Kevni92 commented Oct 8, 2020

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;
}
@mariusbancila mariusbancila self-assigned this Oct 9, 2020
@mariusbancila mariusbancila added the bug Something isn't working label Oct 9, 2020
@qhs1573
Copy link

qhs1573 commented Mar 16, 2022

CRON: * 45 12 ? 3 3 bitset test argument out of range

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants