Skip to content

Commit

Permalink
Root cause solution for #65
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Mar 4, 2022
1 parent 1db454a commit 1e42284
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ function CronDate (date, timezone) {
this.timezone = timezone;

if (date && date instanceof Date) {
this.fromDate(date);
if (!isNaN(date)) {
this.fromDate(date);
} else {
throw new TypeError("CronDate: Invalid date passed as parameter to CronDate constructor");
}
} else if (date === void 0) {
this.fromDate(new Date());
} else if (date && typeof date === "string") {
Expand All @@ -23,6 +27,7 @@ function CronDate (date, timezone) {
} else {
throw new TypeError("CronDate: Invalid type (" + typeof date + ") passed as parameter to CronDate constructor");
}

}

/**
Expand Down Expand Up @@ -119,6 +124,8 @@ CronDate.prototype.increment = function (pattern, options, rerun) {

const

origTime = this.getTime(),

/**
* Find next
*
Expand Down Expand Up @@ -259,7 +266,14 @@ CronDate.prototype.increment = function (pattern, options, rerun) {
doing++;
}

return this;
// If anything changed, recreate this CronDate and run again without incrementing
/*if (origTime != this.getTime()) {
this.apply();
return this.increment(pattern, options, true);
} else {*/
return this;
//}

};

/**
Expand Down
6 changes: 6 additions & 0 deletions test/js/src/suites/basics.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -660,4 +660,10 @@ module.exports = function (Cron, test) {

});

test("Invalid date should throw", function () {
assert.throws(() => {
new Cron("15 9 * * mon", { legacyMode: true }).next(new Date('pizza'));
});
});

};

0 comments on commit 1e42284

Please sign in to comment.