From 712a256deebba89878dd27099e4e401ae202f4dc Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Sat, 5 Jun 2021 23:56:54 -0400 Subject: [PATCH] Fix incorrect time parsing For some reason, string-interpolating the result of chrono.parseDate can set the time of day-only dates to noon, instead of midnight, which is much more useful as a baseline time. To get midnight, prepend "00:00" to all day-only date strings before parsing them with chrono.parseDate. --- puppet/src/contentscript.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/puppet/src/contentscript.js b/puppet/src/contentscript.js index faf4a73..3de2b02 100644 --- a/puppet/src/contentscript.js +++ b/puppet/src/contentscript.js @@ -136,17 +136,18 @@ class MautrixController { } /** - * Parse a date separator (mws-relative-timestamp) + * Parse a date separator. * - * @param {string} text - The text in the mws-relative-timestamp element. - * @return {?Date} - The value in the date separator. + * @param {string} text - The text in the date saparator. + * @return {Promise} - The value of the date separator. * @private */ - async _tryParseDayDate(text) { + async _tryParseDateSeparator(text) { if (!text) { return null } - text = text.replace(/\. /, "/") + // Must prefix with midnight to prevent getting noon + text = "00:00 " + text.replace(/\. /, "/") const now = new Date() let newDate = await this._tryParseDate(text) if (!newDate || newDate > now) { @@ -345,7 +346,7 @@ class MautrixController { let refDate = null for (const child of msgList) { if (child.classList.contains("mdRGT10Date")) { - refDate = await this._tryParseDayDate(child.firstElementChild.innerText) + refDate = await this._tryParseDateSeparator(child.firstElementChild.innerText) } else if (child.classList.contains("MdRGT07Cont")) { // TODO :not(.MdNonDisp) to exclude not-yet-posted messages, // but that is unlikely to be a problem here.