cron-parser icon indicating copy to clipboard operation
cron-parser copied to clipboard

Parsing and stringifying a cron string with "?" in it

Open Arkh1 opened this issue 2 years ago • 2 comments

I have a cron string 0 0 9 * * ?. If I parse the cron string and then call .stringify() it is changed to 0 0 9 * * *.

This appears to be caused by 173-178 of expression.js:

  // Replace '*' and '?'
  if (value.indexOf('*') !== -1) {
    value = value.replace(/\*/g, constraints.min + '-' + constraints.max);
  } else if (value.indexOf('?') !== -1) {
    value = value.replace(/\?/g, constraints.min + '-' + constraints.max);
  }

? and * are treated identically when parsed so become indistinguishable from one another after the initial parsing. Furthermore in https://github.com/harrisiirak/cron-parser/blob/master/lib/field_stringify.js there are no attempts to .stringify() a field to ?.

Are there any plans to support ? in .stringify() in the future?

Arkh1 avatar Aug 02 '21 16:08 Arkh1

? and * are treated identically when parsed so become indistinguishable from one another after the initial parsing.

Indeed, ? is currently handled as * and not supported as expected. And also, no initial context is being tracked, therefore it's not possible to serialize this in this manner. No plans to support thtis at the moment.

harrisiirak avatar Aug 18 '21 23:08 harrisiirak

I don't understand how "?" is expected to be supported anyway. There are references online that it means "No specific value" in some cron implementations. But if you don't care which specific day of the week it executes on, then this is the semantic equivalent of it being executed on ANY day of the week, thus "*" is the appropriate character. What other meaning could there be?

philios33 avatar Aug 12 '22 01:08 philios33