Skip to content

Commit

Permalink
fix: Update datetime handling to respect user timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
Adham-Alammuri committed Dec 3, 2024
1 parent c1d4bb6 commit b371190
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions FrontEndReact/src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ""}`;
}

/**
Expand Down

0 comments on commit b371190

Please sign in to comment.