Skip to content

Commit

Permalink
fix date bug (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiro5id authored Jan 15, 2023
1 parent e9deeca commit 8f4cf87
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/cron-job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ export class CronJob {
* @private
*/
private scheduleForNextIteration() {
const nextTrigger = this._scheduleGenerator.getNextScheduledDate(this.getNow());
const now = this.getNow();
const nextTrigger = this._scheduleGenerator.getNextScheduledDate(now);
if (this._jobOptions.endDate && nextTrigger >= this._jobOptions.endDate) {
this.log('info', `End date reached, resolving job promise...`);
this._resolveJobRunner();
return;
}
const now = this.getNow();

const milisecondsToNextTrigger = nextTrigger.getTime() - now.getTime();

this.log('info', `Scheduling to trigger in the next ${milisecondsToNextTrigger} ms, at ${nextTrigger.toISOString()} the time is now ${now.toISOString()}.`);
Expand Down
4 changes: 2 additions & 2 deletions src/cron-parser/cron-schedule-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export class CronScheduleGenerator {
public getNextScheduledDate(fromDate?: Date): Date {
let now: Date;
if (fromDate) {
now = fromDate;
now = new Date(fromDate.getTime());
} else {
now = this._triggeredDate;
now = new Date(this._triggeredDate.getTime());
}

for (let i = 0; i < 900100; i++) {
Expand Down

0 comments on commit 8f4cf87

Please sign in to comment.