Skip to content

Commit

Permalink
Fix "send between" time comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
jperryhouts committed Nov 25, 2020
1 parent 4653cfa commit 5c70e45
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
9 changes: 6 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,11 @@ const SendLater = {

// Respect "send between" preference
if (recur.between) {
if ((now < recur.between.start) || (now > recur.between.end)) {
SLStatic.debug(`Message ${msgHdr.id} outside of sendable time range.`);
if (SLStatic.compareTimes(now, '<', recur.between.start) ||
SLStatic.compareTimes(now, '>', recur.between.end)) {
SLStatic.debug(
`Message ${msgHdr.id} ${originalMsgId} outside of sendable time range.`,
recur.between);
return;
}
}
Expand All @@ -274,7 +277,7 @@ const SendLater = {
const today = (new Date()).getDay();
if (!recur.days.includes(today)) {
const wkday = new Intl.DateTimeFormat('default', {weekday:'long'});
SLStatic.debug(`Message ${msgHdr.id} not scheduled to send on ${wkday.format(new Date())}`);
SLStatic.debug(`Message ${msgHdr.id} not scheduled to send on ${wkday.format(new Date())}`,recur.days);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions experiments/headerView.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ SendLaterHeaderView = {

hideShowColumn() {
SLStatic.debug("Entering function","SendLaterHeaderView.hideShowColumn");
if (!gDBView) {
SLStatic.debug(`Leaving function SendLaterHeaderView.hideShowColumn. ` +
`(gDBView is ${gDBView})`);
return;
}
const visible =
this.getStorageLocal("showColumn") &&
this.isDraftsFolder(gDBView.viewFolder);
Expand Down
42 changes: 22 additions & 20 deletions utils/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ var SLStatic = {
hour:'numeric',minute:'2-digit'});
},

convertTime(t) {
if (!t) {
return null;
} else if (typeof t === "string") {
return SLStatic.parseDateTime(null, t) || new Date(t);
} else if (typeof t === "number") {
if (t < 2401) {
return SLStatic.parseDateTime(null, `${t}`);
} else {
return new Date(t);
}
} else if (t.getTime) {
return new Date(t.getTime());
} else {
throw new Error(`Send Later error: unable to parse time format ${t}`);
}
},

compare(a, comparison, b) {
switch (comparison) {
case "<":
Expand Down Expand Up @@ -116,6 +134,8 @@ var SLStatic = {
},

compareTimes(a,comparison,b,ignoreSec) {
a = SLStatic.convertTime(a);
b = SLStatic.convertTime(b);
const A = new Date(2000, 0, 01, a.getHours(), a.getMinutes(),
(ignoreSec ? 0 : a.getSeconds()));
const B = new Date(2000, 0, 01, b.getHours(), b.getMinutes(),
Expand Down Expand Up @@ -817,27 +837,9 @@ var SLStatic = {
// than the scheduled day, or if there is none, then the smallest day in
// the restriction overall.
adjustDateForRestrictions(sendAt, start_time, end_time, days) {
convertTime = (t) => {
if (!t) {
return null;
} else if (typeof t === "string") {
return SLStatic.parseDateTime(null, t) || new Date(t);
} else if (typeof t === "number") {
if (t < 2401) {
return SLStatic.parseDateTime(null, `${t}`);
} else {
return new Date(t);
}
} else if (t.getTime) {
return new Date(t.getTime());
} else {
throw new Error(`Send Later error: unable to parse time format ${t}`);
}
}

let dt = new Date(sendAt.getTime());
start_time = convertTime(start_time);
end_time = convertTime(end_time);
start_time = SLStatic.convertTime(start_time);
end_time = SLStatic.convertTime(end_time);

if (start_time && SLStatic.compareTimes(dt, '<', start_time)) {
// If there is a time restriction and the scheduled time is before it,
Expand Down

0 comments on commit 5c70e45

Please sign in to comment.