diff --git a/background.js b/background.js index 413c218c..4a99038c 100644 --- a/background.js +++ b/background.js @@ -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; } } @@ -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); } } } diff --git a/experiments/headerView.js b/experiments/headerView.js index 001e317a..b349d881 100644 --- a/experiments/headerView.js +++ b/experiments/headerView.js @@ -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); diff --git a/utils/static.js b/utils/static.js index 6408e7b1..71c3eb30 100644 --- a/utils/static.js +++ b/utils/static.js @@ -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 "<": @@ -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(), @@ -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,