Skip to content

Commit

Permalink
Simplify nextRecurDate interface
Browse files Browse the repository at this point in the history
Make nextRecurDate always return the same object type, rather than
sometimes returning a Date and sometimes returning its own custom
object format, to simplify the code that uses it.
  • Loading branch information
jikamens committed Aug 26, 2023
1 parent 2e5591b commit e5dd564
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
11 changes: 3 additions & 8 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,14 +553,9 @@ const SendLater = {
}

if (nextRecur) {
let nextRecurAt, nextRecurSpec, nextRecurArgs;
if (nextRecur.getTime) {
nextRecurAt = nextRecur;
} else {
nextRecurAt = nextRecur.sendAt;
nextRecurSpec = nextRecur.nextspec;
nextRecurArgs = nextRecur.nextargs;
}
let nextRecurAt = nextRecur.sendAt;
let nextRecurSpec = nextRecur.nextspec;
let nextRecurArgs = nextRecur.nextargs;
while (nextRecurAt < new Date()) {
nextRecurAt = new Date(nextRecurAt.getTime() + 60000);
}
Expand Down
6 changes: 3 additions & 3 deletions test/nextrecurtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ exports.init = function () {
return "Unexpected error: " + ex;
}
expected = new Date(expected);
if (result.getTime() == expected.getTime()) {
if (result.sendAt.getTime() == expected.getTime()) {
return true;
} else {
return `Expected ${expected}, got ${result}`;
return `Expected ${expected}, got ${result.sendAt}`;
}
}

Expand All @@ -26,7 +26,7 @@ exports.init = function () {
recur,
new Date(now),
);
return "Expected exception, got " + result;
return "Expected exception, got " + result.sendAt;
} catch (ex) {
if ((ex + "").indexOf(expected) !== -1) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion utils/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -1498,7 +1498,7 @@ var SLStatic = {
return null;
}

return next;
return { sendAt: next };
},

// sendAt is a Date object for the scheduled send time we need to adjust.
Expand Down

0 comments on commit e5dd564

Please sign in to comment.