From 5cf6d5b4f2e8f06cccb8ebde8acceb7ccee1382e Mon Sep 17 00:00:00 2001 From: Jason <37859597+zachowj@users.noreply.github.com> Date: Tue, 19 Dec 2023 20:09:57 -0800 Subject: [PATCH] chore: Update cron dependency fix(time): Fix breaking changes from cron package --- package-lock.json | 42 ++++++++++++++++++++------------ package.json | 2 +- src/nodes/time/TimeController.ts | 13 ++++++---- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index a8315026e1..dab8e2b136 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "axios": "1.6.0", "bonjour": "3.5.0", "compare-versions": "6.1.0", - "cron": "2.4.0", + "cron": "3.1.6", "debug": "4.3.4", "flat": "5.0.2", "geolib": "3.3.4", @@ -2956,6 +2956,11 @@ "@types/lodash": "*" } }, + "node_modules/@types/luxon": { + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.3.7.tgz", + "integrity": "sha512-gKc9P2d4g5uYwmy4s/MO/yOVPmvHyvzka1YH6i5dM03UrFofHSmgc0D0ymbDRStFWHusk6cwwF6nhLm/ckBbbQ==" + }, "node_modules/@types/markdown-it": { "version": "12.2.3", "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz", @@ -7154,11 +7159,12 @@ "dev": true }, "node_modules/cron": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/cron/-/cron-2.4.0.tgz", - "integrity": "sha512-Cx77ic1TyIAtUggr0oAhtS8MLzPBUqGNIvdDM7jE3oFIxfe8LXWI9q3iQN/H2CebAiMir53LQKWOhEKnzkJTAQ==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/cron/-/cron-3.1.6.tgz", + "integrity": "sha512-cvFiQCeVzsA+QPM6fhjBtlKGij7tLLISnTSvFxVdnFGLdz+ZdXN37kNe0i2gefmdD17XuZA6n2uPVwzl4FxW/w==", "dependencies": { - "luxon": "^3.2.1" + "@types/luxon": "~3.3.0", + "luxon": "~3.4.0" } }, "node_modules/cronosjs": { @@ -14160,9 +14166,9 @@ } }, "node_modules/luxon": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.2.1.tgz", - "integrity": "sha512-QrwPArQCNLAKGO/C+ZIilgIuDnEnKx5QYODdDtbFaxzsbZcc/a7WFq7MhsVYgRlwawLtvOUESTlfJ+hc/USqPg==", + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz", + "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==", "engines": { "node": ">=12" } @@ -25196,6 +25202,11 @@ "@types/lodash": "*" } }, + "@types/luxon": { + "version": "3.3.7", + "resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.3.7.tgz", + "integrity": "sha512-gKc9P2d4g5uYwmy4s/MO/yOVPmvHyvzka1YH6i5dM03UrFofHSmgc0D0ymbDRStFWHusk6cwwF6nhLm/ckBbbQ==" + }, "@types/markdown-it": { "version": "12.2.3", "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-12.2.3.tgz", @@ -28505,11 +28516,12 @@ "dev": true }, "cron": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/cron/-/cron-2.4.0.tgz", - "integrity": "sha512-Cx77ic1TyIAtUggr0oAhtS8MLzPBUqGNIvdDM7jE3oFIxfe8LXWI9q3iQN/H2CebAiMir53LQKWOhEKnzkJTAQ==", + "version": "3.1.6", + "resolved": "https://registry.npmjs.org/cron/-/cron-3.1.6.tgz", + "integrity": "sha512-cvFiQCeVzsA+QPM6fhjBtlKGij7tLLISnTSvFxVdnFGLdz+ZdXN37kNe0i2gefmdD17XuZA6n2uPVwzl4FxW/w==", "requires": { - "luxon": "^3.2.1" + "@types/luxon": "~3.3.0", + "luxon": "~3.4.0" } }, "cronosjs": { @@ -33914,9 +33926,9 @@ } }, "luxon": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.2.1.tgz", - "integrity": "sha512-QrwPArQCNLAKGO/C+ZIilgIuDnEnKx5QYODdDtbFaxzsbZcc/a7WFq7MhsVYgRlwawLtvOUESTlfJ+hc/USqPg==" + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.4.4.tgz", + "integrity": "sha512-zobTr7akeGHnv7eBOXcRgMeCP6+uyYsczwmeRCauvpvaAltgNyTbLH/+VaEAPUeWBT+1GuNmz4wC/6jtQzbbVA==" }, "magic-string": { "version": "0.30.0", diff --git a/package.json b/package.json index d43bc926b3..a891b48e43 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "axios": "1.6.0", "bonjour": "3.5.0", "compare-versions": "6.1.0", - "cron": "2.4.0", + "cron": "3.1.6", "debug": "4.3.4", "flat": "5.0.2", "geolib": "3.3.4", diff --git a/src/nodes/time/TimeController.ts b/src/nodes/time/TimeController.ts index e0a35cc93a..22eb2be82f 100644 --- a/src/nodes/time/TimeController.ts +++ b/src/nodes/time/TimeController.ts @@ -21,7 +21,7 @@ export default class TimeController extends ExposeAsController { #cronjob: CronJob | null = null; #createCronjob(crontab: string | Date) { - this.#cronjob = new CronJob({ + this.#cronjob = CronJob.from({ cronTime: crontab, onTick: async () => { try { @@ -56,7 +56,7 @@ export default class TimeController extends ExposeAsController { } } - #formatDate(d: Date) { + #formatDate(d?: Date) { return formatDate({ date: d, options: { @@ -114,7 +114,7 @@ export default class TimeController extends ExposeAsController { thursday: 4, friday: 5, saturday: 6, - }; + } as const; const selectedDays = Object.keys(days).reduce((acc, day) => { if (this.node.config[day as keyof TimeNodeProperties]) { @@ -146,7 +146,10 @@ export default class TimeController extends ExposeAsController { if (this.node.config.repeatDaily) { const sentTime = this.#formatDate(now); - const nextTime = this.#formatDate(this.#cronjob?.nextDates()); + // convert luxon to date + const nextTime = this.#formatDate( + this.#cronjob?.nextDate().toJSDate() + ); this.status.setSuccess([ 'ha-time.status.sent_and_next', { @@ -220,7 +223,7 @@ export default class TimeController extends ExposeAsController { this.#createCronjob(crontab); - const nextTime = this.#formatDate(this.#cronjob?.nextDates()); + const nextTime = this.#formatDate(this.#cronjob?.nextDate().toJSDate()); this.status.setText(RED._('ha-time.status.next_at', { nextTime })); } }