From 977b9f81de5dd693220fdba8305aa7dc9dc7fce9 Mon Sep 17 00:00:00 2001 From: Yuriy Date: Wed, 28 Jul 2021 11:13:46 +0300 Subject: [PATCH] fix: fixed failing schedule().next() #14 --- README.md | 1 + package.json | 2 +- src/index.js | 8 ++++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3706ee5..067457a 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ Assuming you are using [browserify][], [webpack][], [rollup][], or another bundl | -------------- | -------------------------- | | **BunKat** | | | **Nick Baugh** | | +| **yrambler2001** | | ## License diff --git a/package.json b/package.json index 12a0d33..983e2c4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@breejs/later", "description": "Maintained fork of later. Determine later (or previous) occurrences of recurring schedules", - "version": "4.0.2", + "version": "4.0.3", "author": "BunKat ", "bugs": { "url": "https://github.com/breejs/later/issues", diff --git a/src/index.js b/src/index.js index 85e067b..5ddfd6b 100644 --- a/src/index.js +++ b/src/index.js @@ -841,9 +841,11 @@ later.compile = function (schedDef) { function compareFn(dir) { return dir === 'next' ? function (a, b) { + if (!a || !b) return true; return a.getTime() > b.getTime(); } : function (a, b) { + if (!a || !b) return true; return b.getTime() > a.getTime(); }; } @@ -1148,10 +1150,12 @@ later.schedule = function (sched) { function compareFn(dir) { return dir === 'next' ? function (a, b) { - return !b || a.getTime() > b.getTime(); + if (!a || !b) return true; + return a.getTime() > b.getTime(); } : function (a, b) { - return !a || b.getTime() > a.getTime(); + if (!a || !b) return true; + return b.getTime() > a.getTime(); }; }