Skip to content

Commit

Permalink
Adjust timezone logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ximekilgsa committed Oct 18, 2024
1 parent ee9bef2 commit 935226d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 28 deletions.
10 changes: 5 additions & 5 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"
}
}
63 changes: 40 additions & 23 deletions js/positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,37 +346,54 @@ function formatDate(date) {

// Function to format the session times into a readable string with Eastern and Pacific times
function formatSessionTimes(sessionTime) {
const [startTime, endTime] = sessionTime.split("-");
const [startTime, endTime] = sessionTime.split("-");

// Convert the start and end times to both Eastern Time (ET) and Pacific Time (PT)
const startET = convertTimeToZone(startTime, "America/New_York");
const endET = convertTimeToZone(endTime, "America/New_York");
const startPT = convertTimeToZone(startTime, "America/Los_Angeles");
const endPT = convertTimeToZone(endTime, "America/Los_Angeles");
// Convert the start and end times to both Eastern Time (ET) and Pacific Time (PT)
const startET = convertTimeToZone(startTime, "America/New_York");
const endET = convertTimeToZone(endTime, "America/New_York");
const startPT = convertTimeToZone(startTime, "America/Los_Angeles");
const endPT = convertTimeToZone(endTime, "America/Los_Angeles");

// Format the result: ET times with PT equivalents
return `${startET}-${endET} ET (${startPT}-${endPT} PT)`;
// Format the result: ET times with PT equivalents
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);

// 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);
// 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;
}

return `${hours24}:${minutes} ${timePeriod.toUpperCase()}`;
}



if (typeof window !== "undefined") {
window.sortJobs = sortJobs;
window.renderGlobalInfoSessions = renderGlobalInfoSessions;
Expand Down

0 comments on commit 935226d

Please sign in to comment.