Skip to content

Commit

Permalink
chore: Update cron dependency
Browse files Browse the repository at this point in the history
fix(time): Fix breaking changes from cron package
  • Loading branch information
zachowj committed Dec 20, 2023
1 parent 135b587 commit 5cf6d5b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 21 deletions.
42 changes: 27 additions & 15 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 8 additions & 5 deletions src/nodes/time/TimeController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -56,7 +56,7 @@ export default class TimeController extends ExposeAsController {
}
}

#formatDate(d: Date) {
#formatDate(d?: Date) {
return formatDate({
date: d,
options: {
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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',
{
Expand Down Expand Up @@ -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 }));
}
}

0 comments on commit 5cf6d5b

Please sign in to comment.