Socket
Socket
Sign inDemoInstall

cron

Package Overview
Dependencies
2
Maintainers
3
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.0.0-beta.8 to 3.0.0-beta.9

dist/errors.d.ts

25

CHANGELOG.md

@@ -0,1 +1,26 @@

## [3.0.0-beta.9](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.8...v3.0.0-beta.9) (2023-09-29)
### ⚠ Breaking changes
* `utcOffset` parameter no longer accepts a string
* `utcOffset` values between -60 and 60 are no longer
treated as hours
* providing both `timeZone` and `utcOffset` parameters
now throws an error
### ✨ Features
* rework utcOffset parameter ([#699](https://github.com/kelektiv/node-cron/issues/699)) ([72d3d36](https://github.com/kelektiv/node-cron/commit/72d3d36c47b037cf4ce489c6b57b0a8b4e000a04))
### ♻️ Chores
* improve GitHub community standards ([#698](https://github.com/kelektiv/node-cron/issues/698)) ([6bdef77](https://github.com/kelektiv/node-cron/commit/6bdef779b813ee84c03b7c708176410aa24a8cfe))
### 💎 Styles
* fix linting issues ([b48c1b2](https://github.com/kelektiv/node-cron/commit/b48c1b299a25bfd3aea418652235e4e6ec92f8cf))
## [3.0.0-beta.8](https://github.com/kelektiv/node-cron/compare/v3.0.0-beta.7...v3.0.0-beta.8) (2023-09-26)

@@ -2,0 +27,0 @@

3

dist/job.d.ts

@@ -13,3 +13,4 @@ import { CronTime } from './time';

private _callbacks;
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: CronJobParams['timeZone'], context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: CronJobParams['utcOffset'], unrefTimeout?: CronJobParams['unrefTimeout']);
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: CronJobParams['timeZone'], context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: null, unrefTimeout?: CronJobParams['unrefTimeout']);
constructor(cronTime: CronJobParams['cronTime'], onTick: CronJobParams['onTick'], onComplete?: CronJobParams['onComplete'], start?: CronJobParams['start'], timeZone?: null, context?: CronJobParams['context'], runOnInit?: CronJobParams['runOnInit'], utcOffset?: CronJobParams['utcOffset'], unrefTimeout?: CronJobParams['unrefTimeout']);
static from(params: CronJobParams): CronJob;

@@ -16,0 +17,0 @@ private _fnWrap;

@@ -5,2 +5,3 @@ "use strict";

const child_process_1 = require("child_process");
const errors_1 = require("./errors");
const time_1 = require("./time");

@@ -15,3 +16,14 @@ class CronJob {

this.context = context || this;
this.cronTime = new time_1.CronTime(cronTime, timeZone, utcOffset);
if (timeZone != null && utcOffset != null) {
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
}
if (timeZone != null) {
this.cronTime = new time_1.CronTime(cronTime, timeZone, null);
}
else if (utcOffset != null) {
this.cronTime = new time_1.CronTime(cronTime, null, utcOffset);
}
else {
this.cronTime = new time_1.CronTime(cronTime, timeZone, utcOffset);
}
if (unrefTimeout != null) {

@@ -35,3 +47,14 @@ this.unrefTimeout = unrefTimeout;

static from(params) {
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
if (params.timeZone != null && params.utcOffset != null) {
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
}
if (params.timeZone != null) {
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
}
else if (params.utcOffset != null) {
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, null, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
}
else {
return new CronJob(params.cronTime, params.onTick, params.onComplete, params.start, params.timeZone, params.context, params.runOnInit, params.utcOffset, params.unrefTimeout);
}
}

@@ -38,0 +61,0 @@ _fnWrap(cmd) {

import { DateTime, Zone } from 'luxon';
import { CronJobParams } from './types/cron.types';
export declare class CronTime {
source: string | DateTime;
zone?: string;
utcOffset?: number | string;
timeZone?: string;
utcOffset?: number;
realDate: boolean;

@@ -13,3 +14,4 @@ private second;

private dayOfWeek;
constructor(source: string | Date | DateTime, zone?: string | null, utcOffset?: string | number | null);
constructor(source: CronJobParams['cronTime'], timeZone?: CronJobParams['timeZone'], utcOffset?: null);
constructor(source: CronJobParams['cronTime'], timeZone?: null, utcOffset?: CronJobParams['utcOffset']);
private _getWeekDay;

@@ -22,3 +24,3 @@ private _verifyParse;

toJSON(): string[];
getNextDateFrom(start: Date | DateTime, zone?: string | Zone): DateTime;
getNextDateFrom(start: Date | DateTime, timeZone?: string | Zone): DateTime;
private _findPreviousDSTJump;

@@ -25,0 +27,0 @@ private _checkTimeInSkippedRange;

@@ -6,5 +6,6 @@ "use strict";

const constants_1 = require("./constants");
const errors_1 = require("./errors");
const utils_1 = require("./utils");
class CronTime {
constructor(source, zone, utcOffset) {
constructor(source, timeZone, utcOffset) {
this.realDate = false;

@@ -17,8 +18,11 @@ this.second = {};

this.dayOfWeek = {};
if (zone) {
const dt = luxon_1.DateTime.fromObject({}, { zone });
if (timeZone != null && utcOffset != null) {
throw new errors_1.ExclusiveParametersError('timeZone', 'utcOffset');
}
if (timeZone) {
const dt = luxon_1.DateTime.fromObject({}, { zone: timeZone });
if (!dt.isValid) {
throw new Error('Invalid timezone.');
}
this.zone = zone;
this.timeZone = timeZone;
}

@@ -74,22 +78,12 @@ if (utcOffset != null) {

: luxon_1.DateTime.local();
if (this.zone) {
date = date.setZone(this.zone);
if (this.timeZone) {
date = date.setZone(this.timeZone);
}
if (this.utcOffset != null) {
const offsetHours = parseInt(this.utcOffset >= 60 || this.utcOffset <= -60
?
this.utcOffset / 60
: this.utcOffset);
const offsetMins = this.utcOffset >= 60 || this.utcOffset <= -60
?
Math.abs(this.utcOffset - offsetHours * 60)
: 0;
const offsetMinsStr = offsetMins >= 10 ? offsetMins : `0${offsetMins}`;
let utcZone = 'UTC';
if (parseInt(this.utcOffset) < 0) {
utcZone += `${offsetHours === 0 ? '-0' : offsetHours}:${offsetMinsStr}`;
}
else {
utcZone += `+${offsetHours}:${offsetMinsStr}`;
}
if (this.utcOffset !== undefined) {
const sign = this.utcOffset < 0 ? '-' : '+';
const offsetHours = Math.trunc(this.utcOffset / 60);
const offsetHoursStr = String(Math.abs(offsetHours)).padStart(2, '0');
const offsetMins = Math.abs(this.utcOffset - offsetHours * 60);
const offsetMinsStr = String(offsetMins).padStart(2, '0');
const utcZone = `UTC${sign}${offsetHoursStr}:${offsetMinsStr}`;
date = date.setZone(utcZone);

@@ -129,3 +123,3 @@ if (!date.isValid) {

}
getNextDateFrom(start, zone) {
getNextDateFrom(start, timeZone) {
var _a;

@@ -137,4 +131,4 @@ if (start instanceof Date) {

const firstDate = start.toMillis();
if (zone) {
date = date.setZone(zone);
if (timeZone) {
date = date.setZone(timeZone);
}

@@ -155,3 +149,3 @@ if (!this.realDate) {

Please provide the following string if you would like to help debug:
Time Zone: ${(_a = zone === null || zone === void 0 ? void 0 : zone.toString()) !== null && _a !== void 0 ? _a : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
Time Zone: ${(_a = timeZone === null || timeZone === void 0 ? void 0 : timeZone.toString()) !== null && _a !== void 0 ? _a : '""'} - Cron String: ${this.source.toString()} - UTC offset: ${date.offset} - current Date: ${luxon_1.DateTime.local().toString()}`);
}

@@ -158,0 +152,0 @@ if (!(date.month in this.month) &&

@@ -7,3 +7,3 @@ /// <reference types="node" />

import { IntRange } from './utils';
export interface CronJobParams {
interface BaseCronJobParams {
cronTime: string | Date | DateTime;

@@ -13,8 +13,13 @@ onTick: CronCommand;

start?: boolean | null;
timeZone?: string | null;
context?: unknown | null;
runOnInit?: boolean | null;
utcOffset?: string | number | null;
unrefTimeout?: boolean | null;
}
export type CronJobParams = BaseCronJobParams & ({
timeZone?: string | null;
utcOffset?: never;
} | {
timeZone?: never;
utcOffset?: number | null;
});
export type CronCommand = ((this: CronJob | any) => void) | string | {

@@ -41,1 +46,2 @@ command: string;

export type DayOfWeekRange = IntRange<(typeof CONSTRAINTS)['dayOfWeek'][0], (typeof CONSTRAINTS)['dayOfWeek'][1]>;
export {};
{
"name": "cron",
"description": "Cron jobs for your node",
"version": "3.0.0-beta.8",
"version": "3.0.0-beta.9",
"author": "Nick Campbell <nicholas.j.campbell@gmail.com> (https://github.com/ncb000gt)",

@@ -6,0 +6,0 @@ "bugs": {

@@ -123,6 +123,6 @@ <p align="center">

- `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 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 the various time zones format accepted in the [Luxon documentation](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone). Note: This parameter supports minutes offsets, e.g. `UTC+5:30`. **Warning**: 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 the various time zones format accepted in the [Luxon documentation](https://github.com/moment/luxon/blob/master/docs/zones.md#specifying-a-zone). Note: This parameter supports minutes offsets, e.g. `UTC+5:30`. **Note**: Cannot be used together with `utcOffset`.
- `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 time zone rather than using the `timeZone` param. This should be an integer representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours). **Warning**: Minutes offsets < 60 and >-60 will be treated as an offset in hours. This means a minute offset of `30` means an offset of +30 hours. Use the `timeZone` param in this case. This behavior [is planned to be removed in V3](https://github.com/kelektiv/node-cron/pull/685#issuecomment-1676417917). **Warning**: 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 representing the number of minutes offset (like `120` for +2 hours or `-90` for -1.5 hours). **Note**: Cannot be used together with `timeZone`.
- `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.

@@ -150,14 +150,10 @@ - `from` (static) - Create a new CronJob object providing arguments as an object. See argument names and descriptions above.

### Looking for maintainers/contributors
This project is looking for help! If you're interested in helping with the project, please take a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md).
This project is looking for help! If you're interested in helping with the project please reach out to me (ncb000gt) on [Twitter](https://twitter.com/ncb000gt). We'd love for it to continue on, but it needs a lot of attention. You can also join the [Discord server](https://discord.gg/yyKns29zch) to learn more about what needs to be done.
### Submitting Bugs/Issues
Before submitting a bug, please search the existing issues, [Discord](https://discord.gg/yyKns29zch) conversations, and the web to see if someone else has run into the same issue before.
Please have a look at our [contributing documentation](https://github.com/kelektiv/node-cron/blob/main/CONTRIBUTING.md), it contains all the information you need to know before submitting an issue.
Because we can't magically know what you are doing to expose an issue, it is best if you provide a snippet of code. This snippet need not include your secret sauce, but it must replicate the issue you are describing. The issues that get closed without resolution tend to be the ones without code examples. Thanks.
## Acknowledgements
### Acknowledgements
This is a community effort project. In the truest sense, this project started as an open source project from [cron.js](http://github.com/padolsey/cron.js) and grew into something else. Other people have contributed code, time, and oversight to the project. At this point there are too many to name here so we'll just say thanks.

@@ -164,0 +160,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc