Skip to content

Commit

Permalink
[B] Event times strip timezone offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Mason committed Mar 11, 2024
1 parent ce1e5c9 commit 5061628
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ export const usePathData = () => {
return { asPath, pathname, query };
};

function dateWoTimezone(iso) {
// attuned to the iso-ish php dateformat from Craft
return new Date(iso.slice(0, -6));
}

export const useDateString = (date, isShort = false) => {
const localeInfo = useGlobalData("localeInfo");
const locale = localeInfo.language || "en-US";
Expand All @@ -184,15 +189,11 @@ export const useDateString = (date, isShort = false) => {
return dateString;
};

export const useTimeString = (time) => {
export const useTimeString = (iso) => {
const localeInfo = useGlobalData("localeInfo");
const locale = localeInfo.language || "en-US";

if (!time) return undefined;

const newTime = new Date(time).toLocaleTimeString(locale);

return newTime;
if (!iso) return undefined;
return dateWoTimezone(iso).toLocaleTimeString(locale);
};

export const useTimeZone = (timezone) => {
Expand Down

0 comments on commit 5061628

Please sign in to comment.