cronti.v2
Introduction
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 | npm i cronti # Locale Install. For use in spesific project. |
Note: add --save
if you are using npm < 5.0.0
Quick Start
In Demo:
Demo project download (zip). Extract the project files from zip. Go to project directory. Execute index.js
file by nodejs.
1 | unzip demo.zip |
In NodeJs:
1 | // Include Package |
Documentation
The cronti
function takes the method name or index value in the first parameter. Then unlimited parameters can be added. Parameters sent according to the function of the called method are used.
cronti(<methodName(string)|methodIndex(number)>, <…args>)
Methods | Index | Name | Description |
---|---|---|---|
onDay | 0 | onDay | Generate crontime of the spesific day of date |
onWeek | 1 | onWeek | Generates the cron time for the week the date is in |
onIntervalTime | 2 | onIntervalTime | Creates a crontime that will run at regular intervals between two dates |
onTime | 3 | onTime | Create crontime with various combinations of month, week, weekdays, hours, minutes and tick |
onCrontime | 4 | onCrontime | Enter valid crontime expression get crontime expression |
onDate | 5 | onDate | Generate crontime of the spesific date |
onIntervalTime
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.
There should be 2 date values in the parameters. The order of these dates is not important. The smaller startDate will be used as the larger endDate. For the step parameter, you can use a string value suitable for the pattern.
Input
Parameter | Type | Required | Description |
---|---|---|---|
args.<startDate> | Date | true | Cron start date |
args.<endDate> | Date | true | Cron end date |
args.<step> | String <.d | .h | .m> | false | Specifies at what steps to run. |
Output
Type | Description |
---|---|
String | Crontime expression |
Example
1 | const cronti = require("cronti") |
onCrontime
Returns the crontime expression of the valid crontime expression. Returns undefined if invalid crontime expression.
Any crontime expression can be used in the parameters.
Input
Parameter | Type | Required | Description |
---|---|---|---|
args.<crontime> | String | true | Crontime expression |
Output
Type | Description |
---|---|
String | Crontime expression |
Example
1 | const cronti = require("cronti") |
onDate
Returns the crontime expression of the entered date value, repeated every month and every year by this expression.
A valid date value must be sent as a parameter.
Input
Parameter | Type | Required | Description |
---|---|---|---|
args.<date> | Date | true | Used date for crontime expression |
Output
Type | Description |
---|---|
String | Crontime expression |
Example
1 | const cronti = require("cronti") |
onDay
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.
A valid date value must be sent as a parameter. Any numeric value can be used for the tick value.
Input
Parameter | Type | Required | Description |
---|---|---|---|
args.<date> | Date | true | Used date for crontime expression |
args.<tick> | Number | false | The number of days to subtract from the date |
Output
Type | Description |
---|---|
String | Crontime expression |
Example
1 | const cronti = require("cronti") |
onTime
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.
A parameter can be sent with a valid month, week, weekdays value. Time parameter can be sent in accordance with the pattern. Any numeric value can be used for the tick value.
Input
Parameter | Type | Required | Description |
---|---|---|---|
args.<month> | String <..M> | false | Month for crontime expression. It takes values between 0 and 11. It takes value |
args.<week> | String <..W> | false | Week for crontime expression. It takes values 0, 1, 2 and -1. It takes value |
args.<weekDays> | String <..WD> | false | Weekdays for crontime expression. It takes values between 0 and 6. It takes value |
args.<time> | String <dd:mm> | false | Time(dd:mm) for crontime expression |
args.<tick> | Number | false | The number of days to subtract from the date. Month and week required parameters for tick |
args.<firstDayOfWeek> | String | false | First day of week. It takes values between 0 and 6. It takes value |
Output
Type | Description |
---|---|
String | Crontime expression |
Example
1 | const cronti = require("cronti") |
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.
A valid date value must be sent as a parameter. Any numeric value can be used for the tick value.
Input
Parameter | Type | Required | Description |
---|---|---|---|
args.<date> | Date | true | Date of the week for crontime expression |
args.<tick> | Number | false | The number of days to subtract from the date |
args.<firstDayOfWeek> | String | false | First day of week. It takes values between 0 and 6. It takes value |
Output
Type | Description |
---|---|
String | Crontime expression |
Example
1 | const cronti = require("cronti") |
Authors
It is maintained by:
- Levent Sencer Şahin : LinkedIn:@buglss | Blog:@buglss | Facebook:@buglss | Twitter:@buglss | Instagram:@buglss
Copyright And License
Copyright Levent Sencer Şahin and other contributors, under the GPL-3.0.