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

一些数据无法解析正确的表达式 #236

Open
martian98 opened this issue Aug 4, 2021 · 1 comment
Open

一些数据无法解析正确的表达式 #236

martian98 opened this issue Aug 4, 2021 · 1 comment

Comments

@martian98
Copy link

martian98 commented Aug 4, 2021

错误复现

  let parser = require('cron-parser');

  let interval = parser.parseExpression('* * * */7 * *');
  var fields = JSON.parse(JSON.stringify(interval.fields)); 

  fields.dayOfMonth = [1,8,15,22,29];

  var modifiedInterval = parser.fieldsToExpression(fields,true);
  var cronString = modifiedInterval.stringify(true);
  console.log(cronString); //输出结果 "* * * 1-29/7 * *"

  //应当输出的结果 * * * */7 * *

通过查看源码发现 field_stringify.js ** 第13-15行**


  //这行判断导致无法正确解析
    if (step !== 1 && singleRange.start === min && singleRange.end === max - step + 1) { 
      return '*/' + step;
    }

修改代码如下:


    //修改之后即可正确解析    * * * */7 * *
    if (step !== 1 && singleRange.start === min && singleRange.end + step > max) {
    
      return '*/' + step;
    }

希望作者大大处理一下, 感谢!!!

@martian98 martian98 changed the title 一些数据无法解析正常的表达式 一些数据无法解析正确的表达式 Aug 4, 2021
@harrisiirak
Copy link
Owner

@martian98 thanks for reporting this. Probably also related to the suggestion provided here: #222 -- I'll investigate this when I've a bit more time.

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

No branches or pull requests

2 participants