@@ -112,7 +112,7 @@ function parseField(field: string, min: number, max: number, aliases: string[] =
112
112
}
113
113
114
114
// 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 {
116
116
const schedule = typeof exp == 'string' ? parseCron ( exp ) : exp ;
117
117
if ( schedule === undefined ) {
118
118
return undefined ;
@@ -137,10 +137,12 @@ parseCron.nextDate = function(exp: string | CronSchedule, from = new Date()): Da
137
137
dials . filter ( ( _ , j ) => j > i ) . forEach ( d => date [ d ] = schedule [ d ] [ 0 ] ) ;
138
138
139
139
// 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 ] ) ;
141
141
142
+ if ( nextTime !== undefined ) {
143
+ date [ dial ] = nextTime ;
142
144
// If no fitting time is found...
143
- if ( date [ dial ] === undefined ) {
145
+ } else {
144
146
// ...restart from the beginning of the list...
145
147
date [ dial ] = schedule [ dial ] [ 0 ] ;
146
148
@@ -170,6 +172,6 @@ function cronDateToUTC(date: CronDate): Date {
170
172
return new Date ( Date . UTC ( date . years , date . months - 1 , date . days , date . hours , date . minutes ) ) ;
171
173
}
172
174
173
- function range ( start : number , stop : number , step : number ) : number [ ] | null {
175
+ function range ( start : number , stop : number , step : number ) : number [ ] {
174
176
return Array . from ( { length : Math . floor ( ( stop - start ) / step ) + 1 } ) . map ( ( _ , i ) => start + i * step ) ;
175
177
}
0 commit comments