Socket
Socket
Sign inDemoInstall

cron

Package Overview
Dependencies
1
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.3.1 to 3.0.0-beta.1

types/index.d.ts

70

CHANGELOG.md

@@ -1,22 +0,78 @@

## [v2.0.0] - 2022-05-03
## [3.0.0-beta.1](https://github.com/kelektiv/node-cron/compare/v2.3.1...v3.0.0-beta.1) (2023-07-23)
### ⚠ Breaking changes
* UNIX standard alignments (#667)
### ✨ Features
* UNIX standard alignments ([#667](https://github.com/kelektiv/node-cron/issues/667)) ([96ef954](https://github.com/kelektiv/node-cron/commit/96ef954998f9c109cc2a969296568b1b56bbbd79))
### ⚙️ Continuous Integrations
* add support for beta & maintenance releases ([#677](https://github.com/kelektiv/node-cron/issues/677)) ([c6fc842](https://github.com/kelektiv/node-cron/commit/c6fc8429e905b38b05ba428e0df4a0fea273614a))
* setup conventional commits & release automation ([#673](https://github.com/kelektiv/node-cron/issues/673)) ([c6f39ff](https://github.com/kelektiv/node-cron/commit/c6f39ff384041b7f91566fc935a9b961d453dd14))
### ♻️ Chores
* update default branch name ([#678](https://github.com/kelektiv/node-cron/issues/678)) ([7471e95](https://github.com/kelektiv/node-cron/commit/7471e95cb7433b4f29cfa68da0a652ec8cf630b6))
## [v2.3.1](https://github.com/kelektiv/node-cron/compare/v2.3.0...v2.3.1) (2023-05-25)
### Added
- Logo!
- New test cases
### Fixed
- Linting issues
## [v2.3.0](https://github.com/kelektiv/node-cron/compare/v2.2.0...v2.3.0) (2023-03-14)
### Fixed
- Some small bugs
### Changed
- Refactored get next date function
## [v2.2.0](https://github.com/kelektiv/node-cron/compare/v2.1.0...v2.2.0) (2023-01-09)
### Changed
- Updated Luxon dependency
- Updated unit tests to be compatible with new Luxon version
## [v2.1.0](https://github.com/kelektiv/node-cron/compare/v2.0.0...v2.1.0) (2022-07-14)
### Changed
- "Maximum iterations" will direct the user to refer to a single canonical issue instead of creating a new one
## [v2.0.0](https://github.com/kelektiv/node-cron/compare/v1.8.2...v2.0.0) (2022-05-03)
- Upgrade vulnerable dependencies
- Move from moment.js to luxon (breaking change)
## [v1.8.2] - 2020-01-24
## [v1.8.2](https://github.com/kelektiv/node-cron/compare/v1.8.1...v1.8.2) (2020-01-24)
- Fix syntax parsing bug
## [v1.8.1] - 2020-01-19
## [v1.8.1](https://github.com/kelektiv/node-cron/compare/v1.8.0...v1.8.1) (2020-01-19)
- Revert TS definition defaulting to DefinitelyTyped definitions.
## [v1.8.0] - 2020-01-19
## [v1.8.0](https://github.com/kelektiv/node-cron/compare/v1.7.1...v1.8.0) (2020-01-19)
- GH-454 - Range upper limit should default to highest value when step is provided by Noah May <noahmouse2011@gmail.com> in d36dc9581f9f68580a2016b368f8002a9f1e357d
## [v1.7.1] - 2019-04-26
## [v1.7.1](https://github.com/kelektiv/node-cron/compare/v1.7.0...v1.7.1) (2019-04-26)
- GH-416 - Fix issue where next execution time is incorrect in some cases in Naoya Inada <naoina@kuune.org> in c08522ff80b3987843e9930c307b76d5fe38b5dc
## [v1.7.0] - 2019-03-19
## [v1.7.0](https://github.com/kelektiv/node-cron/compare/v1.6.0...v1.7.0) (2019-03-19)
- GH-408 - DST issue by Shua Talansky <shua@bitbean.com> in 1e971fd6dfa6ba4b0469d99dd64e6c31189d17d3 and 849a2467d16216a9dfa818c57cc26be6b6d0899b
## [v1.6.0] - 2018-11-15
## [v1.6.0](https://github.com/kelektiv/node-cron/compare/v1.5.1...v1.6.0) (2018-11-15)
- GH-393, GH-394 - Remove hard limit on max iters in favor of a timeout by Nick Campbell <nicholas.j.campbell@gmail.com> in 57632b0c06c56e82f40b740b8d7986be43842735
- GH-390 - better handling of real dates which are in the past by Nick Campbell <nicholas.j.campbell@gmail.com> in 7cbcc984aea6ec063e38829f68eb9bc0dfb1c775

69

lib/time.js

@@ -6,4 +6,4 @@ const CONSTRAINTS = [

[1, 31],
[0, 11],
[0, 6]
[1, 12],
[0, 7]
];

@@ -26,14 +26,14 @@ const MONTH_CONSTRAINTS = [

const ALIASES = {
jan: 0,
feb: 1,
mar: 2,
apr: 3,
may: 4,
jun: 5,
jul: 6,
aug: 7,
sep: 8,
oct: 9,
nov: 10,
dec: 11,
jan: 1,
feb: 2,
mar: 3,
apr: 4,
may: 5,
jun: 6,
jul: 7,
aug: 8,
sep: 9,
oct: 10,
nov: 11,
dec: 12,
sun: 0,

@@ -47,13 +47,14 @@ mon: 1,

};
const TIME_UNITS = [
'second',
'minute',
'hour',
'dayOfMonth',
'month',
'dayOfWeek'
];
const TIME_UNITS_MAP = {
SECOND: 'second',
MINUTE: 'minute',
HOUR: 'hour',
DAY_OF_MONTH: 'dayOfMonth',
MONTH: 'month',
DAY_OF_WEEK: 'dayOfWeek'
};
const TIME_UNITS = Object.values(TIME_UNITS_MAP);
const TIME_UNITS_LEN = TIME_UNITS.length;
const PRESETS = {
'@yearly': '0 0 0 1 0 *',
'@yearly': '0 0 0 1 1 *',
'@monthly': '0 0 0 1 * *',

@@ -118,3 +119,3 @@ '@weekly': '0 0 0 * * 0',

const m = months[i];
const con = MONTH_CONSTRAINTS[parseInt(m, 10)];
const con = MONTH_CONSTRAINTS[parseInt(m, 10) - 1];

@@ -137,3 +138,3 @@ for (let j = 0; j < dom.length; j++) {

if (!ok) {
const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10)];
const notOkCon = MONTH_CONSTRAINTS[parseInt(lastWrongMonth, 10) - 1];
for (let k = 0; k < dom.length; k++) {

@@ -286,3 +287,3 @@ const notOkDay = dom[k];

if (
!(date.month - 1 in this.month) &&
!(date.month in this.month) &&
Object.keys(this.month).length !== 12

@@ -480,3 +481,3 @@ ) {

if (
date.month in this.month &&
date.month + 1 in this.month &&
date.day in this.dayOfMonth &&

@@ -681,4 +682,9 @@ date.getWeekDay() in this.dayOfWeek

const constraints = CONSTRAINTS[TIME_UNITS.indexOf(type)];
const low = constraints[0];
const high =
type === TIME_UNITS_MAP.DAY_OF_WEEK
? constraints[1] - 1
: constraints[1];
for (let i = constraints[0], n = constraints[1]; i < n; i++) {
for (let i = low, n = high; i < n; i++) {
if (!(i in this[type])) {

@@ -814,2 +820,9 @@ return false;

} while (pointer <= upper);
// merge day 7 into day 0 (both Sunday), and remove day 7
// since we work with day-of-week 0-6 under the hood
if (type === 'dayOfWeek') {
if (!typeObj[0] && !!typeObj[7]) typeObj[0] = typeObj[7];
delete typeObj[7];
}
});

@@ -816,0 +829,0 @@ } else {

{
"name": "cron",
"description": "Cron jobs for your node",
"version": "2.3.1",
"version": "3.0.0-beta.1",
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)",

@@ -17,4 +17,7 @@ "bugs": {

"test": "jest --coverage",
"test:watch": "jest --watch --coverage"
"test:watch": "jest --watch --coverage",
"prepare": "husky install",
"release": "semantic-release"
},
"types": "types/index.d.ts",
"dependencies": {

@@ -24,2 +27,11 @@ "luxon": "^3.2.1"

"devDependencies": {
"@commitlint/cli": "~17.6.6",
"@insurgentlab/commitlint-config": "^18.1.0",
"@insurgentlab/conventional-changelog-preset": "~6.0.3",
"@semantic-release/changelog": "~6.0.x",
"@semantic-release/commit-analyzer": "~9.0.x",
"@semantic-release/git": "~10.0.x",
"@semantic-release/github": "~8.1.x",
"@semantic-release/npm": "~10.0.x",
"@semantic-release/release-notes-generator": "~11.0.x",
"chai": "~4.2.x",

@@ -34,4 +46,6 @@ "eslint": "~8.36.x",

"eslint-plugin-promise": "~6.1.x",
"husky": "^8.0.3",
"jest": "~29.5.x",
"prettier": "~2.8.x",
"semantic-release": "~21.0.x",
"sinon": "^15.0.x"

@@ -82,2 +96,3 @@ },

"lib",
"types",
"CHANGELOG.md",

@@ -84,0 +99,0 @@ "LICENSE",

@@ -30,2 +30,17 @@ <p align="center">

## Migrating from v2 to v3
In version 3 of this library, we aligned our format for the cron patterns with the UNIX format. See below for the changes you need to make when upgrading:
<details>
<summary>Migrating from v2 to v3</summary>
### Month & day-of-week indexing changes
**Month indexing went from `0-11` to `1-12`. So you need to increment all numeric months by 1.**
For day-of-week indexing, we only added support for `7` as Sunday, so you don't need to change anything !
</details>
## Versions and Backwards compatibility breaks

@@ -53,3 +68,3 @@

There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/master/examples)
There are more examples available in this repository at: [/examples](https://github.com/kelektiv/node-cron/tree/main/examples)

@@ -70,13 +85,21 @@ ## Available Cron patterns

When specifying your cron values you'll need to make sure that your values fall within the ranges. For instance, some cron's use a 0-7 range for the day of week where both 0 and 7 represent Sunday. We do not. And that is an optimisation.
This library follows the [UNIX Cron format](https://man7.org/linux/man-pages/man5/crontab.5.html), with an added field at the beginning for second granularity.
- Seconds: 0-59
- Minutes: 0-59
- Hours: 0-23
- Day of Month: 1-31
- Months: 0-11 (Jan-Dec)
- Day of Week: 0-6 (Sun-Sat)
```
field allowed values
----- --------------
second 0-59
minute 0-59
hour 0-23
day of month 1-31
month 1-12 (or names, see below)
day of week 0-7 (0 or 7 is Sunday, or use names)
```
> Names can also be used for the 'month' and 'day of week' fields. Use the first three letters of the particular day or month (case does not matter). Ranges and lists of names are allowed.
> Examples: "mon,wed,fri", "jan-mar".
## Gotchas
- Months are indexed as 0-11 instead of 1-12. This is different from Unix `cron` and is planned to updated to match Unix `cron` in v3.0.0 of `node-cron`.
- Millisecond level granularity in JS `Date` or Luxon `DateTime` objects: Because computers take time to do things, there may be some delay in execution. This should be on the order of milliseconds. This module doesn't allow MS level granularity for the regular cron syntax, but _does_ allow you to specify a real date of execution in either a javascript `Date` object or a Luxon `DateTime` object. When this happens you may find that you aren't able to execute a job that _should_ run in the future like with `new Date().setMilliseconds(new Date().getMilliseconds() + 1)`. This is due to those cycles of execution above. This wont be the same for everyone because of compute speed. When we tried it locally we saw that somewhere around the 4-5 ms mark was where we got consistent ticks using real dates, but anything less than that would result in an exception. This could be really confusing. We could restrict the granularity for all dates to seconds, but felt that it wasn't a huge problem so long as you were made aware. If this becomes more of an issue, We can revisit it.

@@ -94,3 +117,3 @@ - Arrow Functions for `onTick`: Arrow functions get their `this` context from their parent scope. Thus, if you use them, you will not get the `this` context of the cronjob. You can read a little more in issue [GH-47](https://github.com/kelektiv/node-cron/issues/47#issuecomment-459762775)

- `CronJob`
- `constructor(cronTime, onTick, onComplete, start, timezone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
- `constructor(cronTime, onTick, onComplete, start, timeZone, context, runOnInit, utcOffset, unrefTimeout)` - Of note, the first parameter here can be a JSON object that has the below names and associated types (see examples above).
- `cronTime` - [REQUIRED] - The time to fire off your job. This can be in the form of cron syntax or a JS [Date](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Date) object.

@@ -100,6 +123,6 @@ - `onTick` - [REQUIRED] - The function to fire at the specified time. If an `onComplete` callback was provided, `onTick` will receive it as an argument. `onTick` may call `onComplete` when it has finished its work.

- `start` - [OPTIONAL] - Specifies whether to start the job just before exiting the constructor. By default this is set to false. If left at default you will need to call `job.start()` in order to start the job (assuming `job` is the variable you set the cronjob to). This does not immediately fire your `onTick` function, it just gives you more control over the behavior of your jobs.
- `timeZone` - [OPTIONAL] - Specify the timezone for the execution. This will modify the actual time relative to your timezone. If the timezone is invalid, an error is thrown. You can check all timezones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
- `timeZone` - [OPTIONAL] - Specify the time zone for the execution. This will modify the actual time relative to your time zone. If the time zone is invalid, an error is thrown. By default (if this is omitted) the local time zone will be used. You can check all time zones available at [Moment Timezone Website](http://momentjs.com/timezone/). Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
- `context` - [OPTIONAL] - The context within which to execute the onTick method. This defaults to the cronjob itself allowing you to call `this.stop()`. However, if you change this you'll have access to the functions and values within your context object.
- `runOnInit` - [OPTIONAL] - This will immediately fire your `onTick` function as soon as the requisite initialization has happened. This option is set to `false` by default for backwards compatibility.
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your timezone rather than using the `timeZone` param. This should be an integer amount representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours) Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
- `utcOffset` - [OPTIONAL] - This allows you to specify the offset of your time zone rather than using the `timeZone` param. This should be an integer amount representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours) Probably don't use both `timeZone` and `utcOffset` together or weird things may happen.
- `unrefTimeout` - [OPTIONAL] - If you have code that keeps the event loop running and want to stop the node process when that finishes regardless of the state of your cronjob, you can do so making use of this parameter. This is off by default and cron will run as if it needs to control the event loop. For more information take a look at [timers#timers_timeout_unref](https://nodejs.org/api/timers.html#timers_timeout_unref) from the NodeJS docs.

@@ -106,0 +129,0 @@ - `start` - Runs your job.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc