Skip to content

Commit 6048902

Browse files
committed
🐛 fix: Fix tsc errors
1 parent 33df019 commit 6048902

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

index.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
/*!
23
* mi-cron
34
*
@@ -88,8 +89,11 @@ parseCron.nextDate = function (exp, from = new Date()) {
8889
const dial = dials[i];
8990
if (!schedule[dial].includes(date[dial])) {
9091
dials.filter((_, j) => j > i).forEach(d => date[d] = schedule[d][0]);
91-
date[dial] = schedule[dial].find(t => t >= date[dial]);
92-
if (date[dial] === undefined) {
92+
const nextTime = schedule[dial].find(t => t >= date[dial]);
93+
if (nextTime !== undefined) {
94+
date[dial] = nextTime;
95+
}
96+
else {
9397
date[dial] = schedule[dial][0];
9498
date[dials[i - 1]]++;
9599
i = (dial != 'months') ? (i - 2) : i;

index.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ function parseField(field: string, min: number, max: number, aliases: string[] =
112112
}
113113

114114
// Return the closest date and time matched by the cron schedule, or `undefined` if the schedule is deemed invalid
115-
parseCron.nextDate = function(exp: string | CronSchedule, from = new Date()): Date {
115+
parseCron.nextDate = function(exp: string | CronSchedule, from = new Date()): Date | undefined {
116116
const schedule = typeof exp == 'string' ? parseCron(exp) : exp;
117117
if (schedule === undefined) {
118118
return undefined;
@@ -137,10 +137,12 @@ parseCron.nextDate = function(exp: string | CronSchedule, from = new Date()): Da
137137
dials.filter((_, j) => j > i).forEach(d => date[d] = schedule[d][0]);
138138

139139
// Try to find the next incoming time
140-
date[dial] = schedule[dial].find(t => t >= date[dial]);
140+
const nextTime = schedule[dial].find(t => t >= date[dial]);
141141

142+
if (nextTime !== undefined) {
143+
date[dial] = nextTime;
142144
// If no fitting time is found...
143-
if (date[dial] === undefined) {
145+
} else {
144146
// ...restart from the beginning of the list...
145147
date[dial] = schedule[dial][0];
146148

@@ -170,6 +172,6 @@ function cronDateToUTC(date: CronDate): Date {
170172
return new Date(Date.UTC(date.years, date.months - 1, date.days, date.hours, date.minutes));
171173
}
172174

173-
function range(start: number, stop: number, step: number): number[] | null {
175+
function range(start: number, stop: number, step: number): number[] {
174176
return Array.from({ length: Math.floor((stop - start) / step) + 1 }).map((_, i) => start + i * step);
175177
}

0 commit comments

Comments
 (0)