Skip to content

Commit

Permalink
Fixissue #217
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexagon committed Oct 21, 2023
1 parent 2155b1b commit 837863f
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 56 deletions.
19 changes: 11 additions & 8 deletions dist/croner.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions dist/croner.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/croner.min.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/croner.min.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/croner.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/croner.min.js.map

Large diffs are not rendered by default.

19 changes: 11 additions & 8 deletions dist/croner.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/croner.umd.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/croner.umd.min.js.map

Large diffs are not rendered by default.

41 changes: 24 additions & 17 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "croner",
"version": "7.0.3",
"version": "7.0.4-dev.0",
"description": "Trigger functions and/or evaluate cron expressions in JavaScript. No dependencies. Most features. All environments.",
"author": "Hexagon <github.com/hexagon>",
"homepage": "https://hexagon.github.io/croner",
Expand Down
19 changes: 11 additions & 8 deletions src/croner.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,14 @@ Cron.prototype.getPattern = function () {
* @returns {boolean} - Running or not
*/
Cron.prototype.isRunning = function () {
const msLeft = this.msToNext(this._states.currentRun);
const nextRunTime = this.nextRun(this._states.currentRun);

const isRunning = !this._states.paused;
const isScheduled = this.fn !== void 0;
// msLeft will be null if _states.kill is set to true, so we don't need to check this one, but we do anyway...
const notIsKilled = !this._states.kill;

return isRunning && isScheduled && notIsKilled && msLeft !== null;
return isRunning && isScheduled && notIsKilled && nextRunTime !== null;
};

/**
Expand Down Expand Up @@ -297,14 +297,14 @@ Cron.prototype.previousRun = function () {
* @returns {number | null}
*/
Cron.prototype.msToNext = function (prev) {

prev = prev || new Date();

// Get next run time
const next = this._next(prev);

// Default previous for millisecond calculation
prev = new CronDate(prev, this.options.timezone || this.options.utcOffset);

if (next) {
return (next.getTime(true) - prev.getTime(true));
return (next.getTime() - prev.getTime());
} else {
return null;
}
Expand Down Expand Up @@ -385,9 +385,12 @@ Cron.prototype.schedule = function (func) {
this.fn = func;
}

// Get ms to next run, bail out early if any of them is null (no next run)
let waitMs = this.msToNext(this._states.currentRun);
// Get actual ms to next run, bail out early if any of them is null (no next run)
let waitMs = this.msToNext();

// Get the target date based on previous run
const target = this.nextRun(this._states.currentRun);

if (waitMs === null || target === null) return this;

// setTimeout cant handle more than Math.pow(2, 32 - 1) - 1 ms
Expand Down

0 comments on commit 837863f

Please sign in to comment.