question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Day of week vs Day of month

See original GitHub issue

Hey @merencia,

First of all, thank you so much for the library, very good job!

I wanted to ask you a question regarding the way node-cron is matching task against Day of week and Day of month.

In the specification of crontab, we have:

Finally, if either the month or day of month is specified as an element or list, and the day of week is also specified as an element or list, then any day matching either the month and day of month, or the day of week, shall be matched. – http://pubs.opengroup.org/onlinepubs/007904975/utilities/crontab.html

Which mean in your code we should have something like:

var runOnDay = false;
if (task.initialPatterns[3] === '*') {
   runOnDay = matchPattern(task.expressions[5], date.getDay());
} else if (task.initialPatterns[5] === '*')
   runOnDay = matchPattern(task.expressions[3], date.getDate());
} else {
   runOnDay = matchPattern(task.expressions[3], date.getDate()) || matchPattern(task.expressions[5], date.getDay());
}
return runInSecond && runOnMinute && runOnHour && runOnMonth && runOnDay;

With this.initialPatterns = pattern.split(' '); in the Task constructor.

I just want to highlight that node-cron does not match the standard specification of the crontab, which frankly I prefer since it helps us doing things like 0 10 1-7 * 1 = Every first Monday of the month at 10am.

So finally, my question. Could you either:

  1. put somewhere in the documentation that node-cron is not matching days like the standard for crontab
  2. or change the code to match the specification

Thanks,

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
merenciacommented, Jan 13, 2017

Hello @bchelli, sorry about the delay, I was on vacations and I was 15 days without internet 😄

I really prefer the option 2, but unfortunately I can’t code on node-cron in the next weeks.

Would you like to help me on node-cron?

1reaction
merenciacommented, Feb 6, 2017

btw, I’ve added you as collaborator on node-cron repository.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between Calendar.WEEK_OF_MONTH ...
Calendar.WEEK_OF_MONTH simply returns "Current week number in current month "; Calendar.DAY_OF_WEEK simply returns "Current day number in ...
Read more >
How to determine the day of the week, given the month, day ...
How to determine the day of the week, given the month, day and year. First a brief explanation: In the Gregorian Calendar, over...
Read more >
Month/ week/ day Definition | Law Insider
Month means calendar month. · Per day means per calendar day or part thereof. · Week means seven consecutive days. · Calendar Week...
Read more >
Day of Week/Month/Year or Week Number - Java Cookbook ...
You have a date and need to find what day of the week, month, or year that date falls on. Solution. Use the...
Read more >
Introduction to Days, Weeks, Months and Years - Math is Fun
Today is my day to learn about days, weeks, months and years ! ... A week can be any period of seven days,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found