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

Croner returns different values in case of trailing whitespace #215

Closed
haggholm opened this issue Oct 10, 2023 · 2 comments
Closed

Croner returns different values in case of trailing whitespace #215

haggholm opened this issue Oct 10, 2023 · 2 comments
Labels

Comments

@haggholm
Copy link

Describe the bug

If a cron expression has trailing whitespace, Croner appears to ‘hallucinate’ an extra (empty?) field. At a first guess I'd suggest that maybe it chooses mode depending on the number of results from something like string.split().

To Reproduce

require("croner")("0 0 12 9 *").nextRuns(3);

[
  2024-09-12T07:01:00.000Z,
  2025-09-12T07:01:00.000Z,
  2026-09-12T07:01:00.000Z
]

But

require("croner")("0 0 12 9 * ").nextRuns(3);

[
  2023-11-09T20:00:00.000Z,
  2023-12-09T20:00:00.000Z,
  2024-01-09T20:00:00.000Z
]

Expected behavior
A clear and concise description of what you expected to happen.

I'd expect it to either trim the input expression and ignore extraneous whitespace, or failing that, throw an error. It's very surprising to get different results based on a trailing space.

System:

  • OS: Linux
  • Runtime: Node.js 16
  • Croner version: 7.0.0

Additional context
Add any other context about the problem here.

@haggholm haggholm added the bug label Oct 10, 2023
@Hexagon
Copy link
Owner

Hexagon commented Oct 11, 2023

@haggholm Issue confirmed 👍

When using a trailing space together with a five part pattern, it's treated as a six part pattern with an empty instruction for weekdays - which interestingly enough is accepted and treated as a wildcard. I will figure out a good solution to this, along with some additional tests.

@Hexagon
Copy link
Owner

Hexagon commented Oct 12, 2023

This issue is resolved in croner@dev or [email protected] by throwing on empty parts (which in this case is caused by a trailing space).

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