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

Fixing _getNextDateFrom function logic #359

Merged
merged 5 commits into from Aug 14, 2018
Merged

Fixing _getNextDateFrom function logic #359

merged 5 commits into from Aug 14, 2018

Conversation

jodevsa
Copy link
Collaborator

@jodevsa jodevsa commented Aug 13, 2018

Hi @ncb000gt

As Discussed in the previous PR, this fix will cover the following cases:

extracting the next day from the following cron strings

* * * * *
*/15 *  * * *
* 5 * * * *

and many others where * is used in minute/hour/day/week

Thanks alot.

lib/cron.js Outdated
var date;
if(zone){
date=moment(start).tz(zone);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The formatting here seems to be messed up. I'm going to add a eslint+prettier at some point in the near future. In the meantime can you change this to } else { and then being the last } in line? Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So sorry about that 👍

date.add(1, 'M');
date.date(1);
date.hours(0);
date.minutes(0);
date.seconds(0);
continue;
}

if (!(date.date() in this.dayOfMonth)) {
if (!(date.date() in this.dayOfMonth) && Object.keys(this.dayOfMonth).length!=31) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some testing to ensure that this wont break months that have less than 31 days?

Copy link
Collaborator Author

@jodevsa jodevsa Aug 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ncb000gt The logic behind this condition Object.keys(this.dayOfMonth).length!=31 is to know whether the dayOfMonth is set to * in the cronString or not. This has nothing to do with the current Date date.date()

lib/cron.js Outdated
break;
}

if(origDate.valueOf()==start){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to go back a second here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ncb000gt removed in commit 98dad71

@ncb000gt
Copy link
Member

Thanks for putting up this pr!

@jodevsa
Copy link
Collaborator Author

jodevsa commented Aug 13, 2018

@ncb000gt Can you please review again, i added new tests and made a couple of changes. Let me know what your thoughts and suggestions are.

@ncb000gt ncb000gt merged commit 4a16ee0 into kelektiv:master Aug 14, 2018
@ncb000gt
Copy link
Member

ncb000gt commented Aug 14, 2018

Landed. Thanks @jodevsa!

I'll try to get a new version out today.

@jodevsa
Copy link
Collaborator Author

jodevsa commented Aug 15, 2018

@ncb000gt That would be awesome.
BTW, don't you think we should throw errors when the next date is in the past?
same thing applies to when you choose a day of a month that is not valid like * * 31 1 * (FEB-31).

Thanks.

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

Successfully merging this pull request may close these issues.

None yet

2 participants