Skip to content

Commit 3a8b863

Browse files
authored
Merge pull request #273 from mgrisole/fix/immediate-interval-start
fix no immediate execution with interval
2 parents 5208508 + 8467a9f commit 3a8b863

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/croner.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ class Cron {
284284
* @param prev Starting date, defaults to now - minimum interval
285285
*/
286286
public msToNext(prev?: CronDate | Date | string): number | null {
287-
prev = prev || new Date();
288-
289287
// Get next run time
290288
const next = this._next(prev);
291289

test/croner.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,3 +1020,11 @@ test("Fire-once should be supported by date, future and .nextRun() should return
10201020
assertEquals(nextRun && nextRun?.getTime() > refTime.getTime(), true);
10211021
assertEquals(nextRun && nextRun?.getTime() < refTime.getTime() + 4000, true);
10221022
});
1023+
1024+
test('Number of milliseconds to next run should be < 1s when interval is paired with a PerSecondJob', () => {
1025+
const cron = new Cron("* * * * * *", {
1026+
interval: 5,
1027+
})
1028+
assertEquals(cron.msToNext()! < 1000, true);
1029+
});
1030+

0 commit comments

Comments
 (0)