Skip to content

Commit

Permalink
Merge pull request #506 from GSA-TTS/fix/info-session-et-time
Browse files Browse the repository at this point in the history
Adjust timezone logic
  • Loading branch information
ximekilgsa authored Oct 18, 2024
2 parents fe6b4f4 + e20f9ba commit 418208f
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
8 changes: 4 additions & 4 deletions _data/assetPaths.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"admin.map": "/assets/js/admin-77FHK54G.js.map",
"app.js": "/assets/js/app-U5OIPSUD.js",
"app.map": "/assets/js/app-U5OIPSUD.js.map",
"positions.js": "/assets/js/positions-WJQAKJ7I.js",
"positions.map": "/assets/js/positions-WJQAKJ7I.js.map",
"subnav.js": "/assets/js/subnav-4HLYTIGH.js",
"subnav.map": "/assets/js/subnav-4HLYTIGH.js.map",
"positions.js": "/assets/js/positions-7HNV4MMS.js",
"positions.map": "/assets/js/positions-7HNV4MMS.js.map",
"subnav.js": "/assets/js/subnav-3QHQ2EX4.js",
"subnav.map": "/assets/js/subnav-3QHQ2EX4.js.map",
"styles.css": "/assets/styles/styles-EQTR2GJL.css",
"styles.map": "/assets/styles/styles-EQTR2GJL.css.map"
}
43 changes: 29 additions & 14 deletions js/positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,23 +358,38 @@ function formatSessionTimes(sessionTime) {
return `${startET}-${endET} ET (${startPT}-${endPT} PT)`;
}

// Helper export function to convert the time to a specific timezone
// Helper function to convert the time to a specific timezone
function convertTimeToZone(time, timeZone) {
const now = new Date(); // Get today's date
const [hours, minutes, period] = time.match(/(\d+):(\d+)([ap]m)/i).slice(1); // Extract hours, minutes, period (am/pm)
const [hours, minutes, period] = time.match(/(\d+):(\d+)([ap]m)/i).slice(1);

// Create a date object using today's date and the given time in the desired timezone (ET or PT)
const date = new Date(
`${now.toLocaleDateString()} ${hours}:${minutes} ${period}`,
);
console.log(period);

let hours24 = parseInt(hours, 10);
let timePeriod = period;
if (period.toLowerCase() === "pm" && hours24 !== 12) {
hours24 += 12;
} else if (period.toLowerCase() === "am" && hours24 === 12) {
hours24 = 0;
}

// Set the PT offset
const ptOffset = timeZone !== "America/New_York" ? 3 : 0;
const ptHours = hours24 - ptOffset;

console.log(hours24, ptHours);

// Make sure the time period changes to AM if the Pacific Time is before noon
if (timeZone === "America/Los_Angeles" && hours24 >= 12 && ptHours < 12) {
timePeriod = "AM";
}

hours24 = hours24 - ptOffset;

if (hours24 > 12) {
hours24 += -12;
}

// Convert the time to the specified timezone (America/New_York for ET, America/Los_Angeles for PT)
return new Intl.DateTimeFormat("en-US", {
hour: "numeric",
minute: "numeric",
hour12: true,
timeZone: timeZone,
}).format(date);
return `${hours24}:${minutes} ${timePeriod.toUpperCase()}`;
}

if (typeof window !== "undefined") {
Expand Down

0 comments on commit 418208f

Please sign in to comment.