From 4f64a0c5f94479652213353e17110b40b0b5c9fe Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 1 Aug 2023 08:35:44 -0400 Subject: [PATCH] Updated date parsing. --- scripts/logbook.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/scripts/logbook.js b/scripts/logbook.js index 2f570fd..f428a8a 100644 --- a/scripts/logbook.js +++ b/scripts/logbook.js @@ -48,6 +48,14 @@ async function fetchMessages() { } } +const parseDate = dateString => { + const b = dateString.split(/\D+/); + const offsetMult = dateString.indexOf('+') !== -1 ? -1 : 1; + const hrOffset = offsetMult * (+b[7] || 0); + const minOffset = offsetMult * (+b[8] || 0); + return new Date(Date.UTC(+b[0], +b[1] - 1, +b[2], +b[3] + hrOffset, +b[4] + minOffset, +b[5], +b[6] || 0)); + }; + function renderMessages(messages) { messagesContainer.innerHTML = ""; messages.forEach(message => { @@ -55,7 +63,7 @@ function renderMessages(messages) { messageElement.className = "logbook-message"; const timestampElement = document.createElement("time"); - const date = Date(message.createdAt); + const date = parseDate(message.createdAt); timestampElement.dateTime = message.createdAt; timestampElement.innerText = date.toLocaleString();