Skip to content

Commit

Permalink
Merge branch 'main' into chore/reduce-renovate-noise-2
Browse files Browse the repository at this point in the history
  • Loading branch information
intcreator authored Jan 10, 2025
2 parents f16c77d + ce4c3c2 commit d374569
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint_pr_title.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
uses: step-security/harden-runner@c95a14d0e5bab51a9f56296a4eb0e416910cd350 # v2.10.3
with:
egress-policy: audit # TODO: change to 'egress-policy: block' after couple of runs

Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
## [3.5.0](https://github.com/kelektiv/node-cron/compare/v3.4.0...v3.5.0) (2025-01-10)

### ✨ Features

* throw instead of silently rewriting invalid cron expressions ([#937](https://github.com/kelektiv/node-cron/issues/937)) ([dcc5b93](https://github.com/kelektiv/node-cron/commit/dcc5b939fb08a806793799019c9f256bd137c33d))

### ⚙️ Continuous Integrations

* **action:** update step-security/harden-runner action to v2.10.3 ([#943](https://github.com/kelektiv/node-cron/issues/943)) ([cd7ee9f](https://github.com/kelektiv/node-cron/commit/cd7ee9f62fbdd16ec150e9e5aa69d8852f5b3dcb))

### ♻️ Chores

* **deps:** update dependency [@types](https://github.com/types)/node to v20.17.12 ([2a867f9](https://github.com/kelektiv/node-cron/commit/2a867f9c34c216ac04ce8bce34e0e16578f7dd0c))
* **deps:** update dependency [@types](https://github.com/types)/node to v22 ([#900](https://github.com/kelektiv/node-cron/issues/900)) ([f7548bd](https://github.com/kelektiv/node-cron/commit/f7548bd3b6981514abd174341b39813d0d6f239a))

## [3.4.0](https://github.com/kelektiv/node-cron/compare/v3.3.2...v3.4.0) (2025-01-09)

### ✨ Features
Expand Down
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cron",
"description": "Cron jobs for your node",
"version": "3.4.0",
"version": "3.5.0",
"author": "Nick Campbell <[email protected]> (https://github.com/ncb000gt)",
"bugs": {
"url": "https://github.com/kelektiv/node-cron/issues"
Expand Down Expand Up @@ -40,7 +40,7 @@
"@semantic-release/npm": "12.0.1",
"@semantic-release/release-notes-generator": "14.0.3",
"@types/jest": "29.5.14",
"@types/node": "20.17.11",
"@types/node": "22.10.5",
"@types/sinon": "17.0.3",
"chai": "5.1.2",
"eslint": "8.57.1",
Expand Down
14 changes: 0 additions & 14 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ export const CONSTRAINTS = Object.freeze({
month: [1, 12],
dayOfWeek: [0, 7]
} as const);
export const MONTH_CONSTRAINTS = Object.freeze({
1: 31,
2: 29, // support leap year...not perfect
3: 31,
4: 30,
5: 31,
6: 30,
7: 31,
8: 31,
9: 30,
10: 31,
11: 30,
12: 31
} as const);
export const PARSE_DEFAULTS = Object.freeze({
second: '0',
minute: '*',
Expand Down
50 changes: 0 additions & 50 deletions src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { DateTime, Zone } from 'luxon';
import {
ALIASES,
CONSTRAINTS,
MONTH_CONSTRAINTS,
PARSE_DEFAULTS,
PRESETS,
RE_RANGE,
Expand All @@ -15,13 +14,10 @@ import {
import { CronError, ExclusiveParametersError } from './errors';
import {
CronJobParams,
DayOfMonthRange,
MonthRange,
Ranges,
TimeUnit,
TimeUnitField
} from './types/cron.types';
import { getRecordKeys } from './utils';

export class CronTime {
source: string | DateTime;
Expand Down Expand Up @@ -76,59 +72,13 @@ export class CronTime {
} else {
this.source = source;
this._parse(this.source);
this._verifyParse();
}
}

private _getWeekDay(date: DateTime) {
return date.weekday === 7 ? 0 : date.weekday;
}

/**
* Ensure that the syntax parsed correctly and correct the specified values if needed.
*/
private _verifyParse() {
const months = getRecordKeys(this.month);
const daysOfMonth = getRecordKeys(this.dayOfMonth);

let isOk = false;

/**
* if a dayOfMonth is not found in all months, we only need to fix the last
* wrong month to prevent infinite loop
*/
let lastWrongMonth: MonthRange | null = null;
for (const m of months) {
const con = MONTH_CONSTRAINTS[m];

for (const day of daysOfMonth) {
if (day <= con) {
isOk = true;
}
}

if (!isOk) {
// save the month in order to be fixed if all months fails (infinite loop)
lastWrongMonth = m;
console.warn(`Month '${m}' is limited to '${con}' days.`);
}
}

// infinite loop detected (dayOfMonth is not found in all months)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!isOk && lastWrongMonth !== null) {
const notOkCon = MONTH_CONSTRAINTS[lastWrongMonth];
for (const notOkDay of daysOfMonth) {
if (notOkDay > notOkCon) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this.dayOfMonth[notOkDay];
const fixedDay = (notOkDay % notOkCon) as DayOfMonthRange;
this.dayOfMonth[fixedDay] = true;
}
}
}
}

/**
* Calculate the "next" scheduled time
*/
Expand Down
29 changes: 13 additions & 16 deletions tests/cron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,28 +616,24 @@ describe('cron', () => {

it('should not get into an infinite loop on invalid times', () => {
expect(() => {
new CronJob(
'* 60 * * * *',
() => {
expect(true).toBe(true);
},
null,
true
);
new CronJob('* 60 * * * *', () => {}, null, true);
}).toThrow();

expect(() => {
new CronJob(
'* * 24 * * *',
() => {
expect(true).toBe(true);
},
null,
true
);
new CronJob('* * 24 * * *', () => {}, null, true);
}).toThrow();

expect(() => {
new CronJob('0 0 30 FEB *', callback, null, true);
}).toThrow();
});

it('should not throw if at least one time is valid', () => {
expect(() => {
new CronJob('0 0 30 JAN,FEB *', callback, null, true);
}).not.toThrow();
});

it('should test start of month', () => {
const d = new Date('12/31/2014');
d.setSeconds(59);
Expand Down Expand Up @@ -856,6 +852,7 @@ describe('cron', () => {

// tick by 1 day
clock.tick(24 * 60 * 60 * 1000);
clock.restore();
job.stop();
expect(callback).toHaveBeenCalledTimes(1);
});
Expand Down

0 comments on commit d374569

Please sign in to comment.