-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set users timezone correctly in add to calendar button
- Loading branch information
Showing
9 changed files
with
60 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
export default function () { | ||
function setTimeZoneCookie() { | ||
// Timezone settings. See TimezoneMiddleware in utils/middleware.py | ||
// If timezone isn't set in cookies, set it. Pages can force a reload if they need to. | ||
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone // e.g. "America/New_York" | ||
const timezone = getTimeZone() // e.g. "America/New_York" | ||
const hasTimezone = globalThis.document.cookie | ||
.split(";") | ||
.some((item) => item.trim().startsWith("totem_timezone=")) | ||
if (timezone && !hasTimezone) { | ||
globalThis.document.cookie = `totem_timezone=${timezone}; SameSite=Strict; Secure; path=/; max-age=31536000` | ||
} | ||
} | ||
|
||
function getTimeZone() { | ||
try { | ||
if (Intl?.DateTimeFormat) { | ||
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone | ||
return timeZone || "UTC" // fallback to UTC if timeZone is undefined | ||
} | ||
return "UTC" // fallback if Intl.DateTimeFormat isn't available | ||
} catch (error) { | ||
console.error("Error getting timezone:", error) | ||
return "UTC" // fallback in case of any errors | ||
} | ||
} | ||
|
||
export { setTimeZoneCookie, getTimeZone } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters