From b371190749867de5aa4038c367c20b8e8ae7b095 Mon Sep 17 00:00:00 2001 From: AdhamA Date: Mon, 2 Dec 2024 21:09:28 -0600 Subject: [PATCH] fix: Update datetime handling to respect user timezone --- FrontEndReact/src/utility.js | 40 ++++++++++++++---------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/FrontEndReact/src/utility.js b/FrontEndReact/src/utility.js index 5b61bcdde..3d5009743 100644 --- a/FrontEndReact/src/utility.js +++ b/FrontEndReact/src/utility.js @@ -271,37 +271,27 @@ export function getDueDateString(dueDate) { } export function getHumanReadableDueDate(dueDate, timeZone) { - dueDate = dueDate.substring(5); + const date = new Date(dueDate); - var month = Number(dueDate.substring(0, 2)) - 1; + const month = date.getMonth(); - dueDate = dueDate.substring(3); + const day = date.getDate(); - var day = Number(dueDate.substring(0, 2)); - - dueDate = dueDate.substring(3); - - var hour = Number(dueDate.substring(0, 2)); - - var twelveHourClock = hour < 12 ? "am": "pm"; - - hour = hour > 12 ? (hour % 12) : hour; - - hour = hour === 0 ? 12 : hour; - - dueDate = dueDate.substring(3); - - var minute = Number(dueDate.substring(0, 2)); + const hour = date.getHours(); + const minute = date.getMinutes(); + const monthNames = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]; + + const twelveHourClock = hour < 12 ? "am": "pm"; - var minutesString = minute < 10 ? ("0" + minute): minute; - - var timeString = `${hour}:${minutesString}${twelveHourClock}`; - - var dueDateString = `${monthNames[month]} ${day} at ${timeString} ${timeZone ? timeZone : ""}`; - - return dueDateString; + const displayHour = hour > 12 ? (hour % 12) : (hour === 0 ? 12 : hour); + + const minutesString = minute < 10 ? ("0" + minute): minute; + + const timeString = `${displayHour}:${minutesString}${twelveHourClock}`; + + return `${monthNames[month]} ${day} at ${timeString} ${timeZone ? timeZone : ""}`; } /**