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

Error isn't always thrown when currentDate out of bounds of timespan range #357

Open
tonyd33 opened this issue Oct 23, 2024 · 0 comments
Open

Comments

@tonyd33
Copy link

tonyd33 commented Oct 23, 2024

Even if currentDate is out of bounds of startDate and endDate, it's possible that we don't throw an error. Here are illustrative examples:

Scenario 1: currentDate is after endDate

const options1 = {
  startDate: new Date('2024-10-01'),
  endDate: new Date('2024-10-07'),
  currentDate: new Date('2024-11-01'),
};

const interval1a = parser.parseExpression('0 1 * * *', options1);
const interval1b = parser.parseExpression('0 1 * * *', options1);
try {
  interval1a.next();
} catch (err) {
  // this is expected
  console.log("Error on interval1a.next()");
}
// but calling prev() won't throw even though currentDate is out of bounds
// and the date returned from this isn't even clamped to the endDate
interval1b.prev();
console.log("No error on interval1b.prev()");

Scenario 2: currentDate is before startDate

const options2 = {
  startDate: new Date('2024-10-01'),
  endDate: new Date('2024-10-07'),
  currentDate: new Date('2024-09-01'),
};
const interval2a = parser.parseExpression('0 1 * * *', options2);
const interval2b = parser.parseExpression('0 1 * * *', options2);
// this doesn't throw even though currentDate is out of bounds
// and the date returned from this isn't even clamped to startDate
interval2a.next();
console.log("No error on interval2a.next()");
try {
  interval2b.prev()
} catch (err) {
  // this is expected
  console.log("Error on interval2b.prev()")
}

I think this is bound to cause some troubles or confusion. It certainly did for me, although that was partly because I had confused currentDate with startDate at first. However, that trouble could've been prevented if we threw an error in these out-of-bounds cases.

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

No branches or pull requests

1 participant