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

Unexpected behavior with hours range #329

Open
PierreDemailly opened this issue Aug 14, 2023 · 1 comment
Open

Unexpected behavior with hours range #329

PierreDemailly opened this issue Aug 14, 2023 · 1 comment
Labels

Comments

@PierreDemailly
Copy link

Given a cron expression * 6-20 * * *, at 6:01.
I expect .prev() to be 6:00 and then .next() to be 6:01.
Actually .prev() is 6:00 as expected but then .next() is 7:00 instead of 6:01.

Reproduction code

import cronParser from 'cron-parser';

const cronExpressions = ['* 6-20 * * *', '* * * * *'];
const testingDate = [
  '01-01-2023 6:00:00',
  '01-01-2023 6:01:00',
  '01-01-2023 6:02:00',
];

for (const cronExpression of cronExpressions) {
  console.log('-----');
  console.log(`Given cron expression [${cronExpression}]`);
  console.log('-----');

  for (const date of testingDate) {
    console.log(`Given date ${date}`);
    const cron = cronParser.parseExpression(cronExpression, {
      currentDate: new Date(date),
    });

    const previous = cron.prev().toString();
    console.log('previous \t', previous);

    const current = cron.next().toString();
    console.log('current \t', current);

    const next = cron.next().toString();
    console.log('next \t\t', next);
  }
}

Given cron expression [* 6-20 * * *]

Given date 01-01-2023 6:00:00
previous .. Sat Dec 31 2022 20:59:00 GMT+0100
current ..... Sun Jan 01 2023 06:00:00 GMT+0100
next .......... Sun Jan 01 2023 06:01:00 GMT+0100
Given date 01-01-2023 6:01:00
previous .. Sun Jan 01 2023 06:00:00 GMT+0100
current ..... Sun Jan 01 2023 07:00:00 GMT+0100 <------------ ?
next .......... Sun Jan 01 2023 07:01:00 GMT+0100
Given date 01-01-2023 6:02:00
previous .. Sun Jan 01 2023 06:01:00 GMT+0100
current ..... Sun Jan 01 2023 06:02:00 GMT+0100
next .......... Sun Jan 01 2023 06:03:00 GMT+0100

See this StackBlitz

Can you confirm whether there is a bug on your side or if I do something wrong?

@harrisiirak
Copy link
Owner

Hi @PierreDemailly!

Thanks for reporting this! Looks like a bug to me. By a quick look, it seems that DST handling craps itself out when mixing prev/next calls and creates an invalid state. Needs some more time (no ETA) for in-depth investigation. I'll later also try to test with current ongoing TS rewrite, as it may have been already resolved over there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants