You need to know crontime expression to do scheduled jobs. However, this package saves you this trouble. You can create crontime expressions with timing expressions used in daily life. You can use this generated crontime expression to create a scheduled job. A valid crontime expression is returned.
You can use it with any cronjob package or directly with the crontab command sets provided by the operating systems. It can work with even the most primitive instruction sets. Because this package directly returns the crontime expression.
You can easily present an interface when creating scheduled and calendar works in your projects. It offers functions where people can make plans in the language they use in daily life.
Install
Using npm:
1 2
npm i cronti # Locale Install. For use in spesific project. npm i -g cronti # Global Install. For use in general projects.
Note: add --save if you are using npm < 5.0.0
Quick Start
In Demo:
Demo project download (rar). Extract the project files from rar. Go to project directory. Execute index.js file by nodejs.
// Include Package const cronti = require("cronti")
/* Creates a crontime expression that will run at regular intervals between two dates. */ cronti.intervalTime("2022-04-25T09:30:00.000Z", "2022-05-15T09:30:00.000Z") /* - OR - */ cronti.intervalTime(newDate("2022-04-25 12:30"), newDate("2022-05-15 12:30")) /* returns "30 12 25-15 4-5 *" */ /* ************************************************************************ */
/* Generate crontime expression of the spesific date. */ cronti.onDate("2022-05-26T09:30:00.000Z") /* - OR - */ cronti.onDate(newDate("2022-05-26 12:30")) /* returns "30 12 26 * *" */ /* ************************************************************************ */
/* Generate crontime expression of the spesific day of date. */ cronti.onDay("2022-05-26T09:30:00.000Z") /* - OR - */ cronti.onDay(newDate("2022-05-26 12:30")) /* returns "30 12 26 5 *" */ /* ************************************************************************ */
/* Create crontime with various combinations of month, week, weekdays, time and tick parameters. * Attention! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. */ cronti.onTime({month: 4, week: 2}) /* returns "30 12 15-21 5 *" */ /* ---------------------------------------------------- */ cronti.onTime({month: 4, week: 2, weekDays: 3}) /* returns "30 12 18 5 *" */ /* ---------------------------------------------------- */ cronti.onTime({month: 3, weekDays: 1}) /* returns "30 12 * 4 1" */ /* ************************************************************************ */
/* Generates the cron time for the week the date is in. * Attention! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. */ cronti.onWeek("2022-05-26T09:30:00.000Z") /* - OR - */ cronti.onWeek(newDate("2022-05-26 12:30")) /* returns "30 12 22-28 5-5 *" */ /* ************************************************************************ */
Creates crontime expression based on start and end date. According to step parameter, it is specified in which intervals it will work between two dates. The step parameter is used in days, hours or minutes.
Returns the crontime expression of the entered date value, repeated every year by this expression. The crontime expression that will be triggered before the entered date according to the tick value is returned.
Create crontime with various combinations of month, week, weekdays, time and tick parameters. Only time is a mandatory value. All crontime expressions are set according to this time parameter. The crontime expression that will be triggered before the entered date according to the tick value is returned.
If only the month(0..11) and week(0,1,2,-1) parameter is filled, the crontime expression that will be triggered every day from the first day of the week to the last day of that week is returned.
If only the month(0..11), week(0,1,2,-1) and weekdays(0..6) parameters are populated, the crontime expression for that weekday is returned.
If only the week(0,1,2,-1) parameter is populated, the crontime expression that will be triggered every day during that week is returned. Except for the last week of the month(-1).
If only the month(0..11) parameter is populated, the crontime expression is returned for each day in that month.
If only the weekdays(0..6) parameter is populated, the crontime expression is returned for this weekday every month.
If only the month(0..11) and weekdays(0..6) parameters are populated, the crontime expression is returned for these weekdays of this month.
If no parameters are filled in, the crontime expression is returned for each day of each month.
Input
Parameter
Type
Required
Description
options (destructuring param)
Object
true
Options
options.month
Number
false
Month(0..11) for crontime expression
options.week
Number
false
Week(0,1,2,-1) for crontime expression
options.weekDays
Number
false
Weekdays(0..6) for crontime expression
options.time
String <dd:mm>
false
Time(dd:mm) for crontime expression
options.tick
Number
false
The number of days to subtract from the date. Month and week required parameters for tick
options.firstDayOfWeek
Number
false
First day of week. It takes values between 0 and 6. Default value is monday
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({month: 4, week: 2}) // => "30 12 15-21 5 *"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({month: 4, week: 2, weekDays: 3}) // => "30 12 18 5 *"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({week: 0}) // => "30 12 1-7 * *"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({month: 2}) // => "30 12 * 3 *"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({weekDays: 6}) // => "30 12 * * 6"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({month: 3, weekDays: 1}) // => "30 12 * 4 1"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({}) // => "30 12 * * *"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({month: 4, week: 2, tick: 1}) // => "30 12 14-21 5 *"
// ! The crontime expression change according to the time they were created. The time to be tested is 27.05.2022. cronti.onTime({month: 2, time: "09:45"}) // => "45 09 * 3 *"
onWeek
The crontime expression that will be triggered every day of the week that the entered date is in returns. The crontime expression that will be triggered before the entered date based on the tick value is returned.
Input
Parameter
Type
Required
Description
date
Date
true
Date of the week for crontime expression
tick
Number
false
The number of days to subtract from the date
firstDayOfWeek
Number
false
First day of week. It takes values between 0 and 6. Default value is monday