Update Navbar component to use moment-timezone for countdown timer calculations

This commit is contained in:
akcodez
2025-05-29 09:12:30 -07:00
parent 5c97efbdac
commit b23aa3a55e

View File

@@ -6,7 +6,7 @@ import { Link } from "@redocly/theme/components/Link/Link";
import { ColorModeSwitcher } from "@redocly/theme/components/ColorModeSwitcher/ColorModeSwitcher"; import { ColorModeSwitcher } from "@redocly/theme/components/ColorModeSwitcher/ColorModeSwitcher";
import { Search } from "@redocly/theme/components/Search/Search"; import { Search } from "@redocly/theme/components/Search/Search";
import arrowUpRight from "../../../static/img/icons/arrow-up-right-custom.svg"; import arrowUpRight from "../../../static/img/icons/arrow-up-right-custom.svg";
import moment from "moment"; import moment from "moment-timezone";
// @ts-ignore // @ts-ignore
@@ -23,11 +23,9 @@ function useCountdown(targetDate: string) {
React.useEffect(() => { React.useEffect(() => {
const calculateTimeLeft = () => { const calculateTimeLeft = () => {
// Target: June 11, 2025 at 8AM Singapore time (GMT+8) // Create target date in Singapore timezone (Asia/Singapore)
// Singapore is UTC+8, so 8AM Singapore = 0AM UTC (midnight UTC) const target = moment.tz(targetDate, "YYYY-MM-DD HH:mm:ss", "Asia/Singapore");
const targetSingaporeTime = moment(targetDate, "YYYY-MM-DD HH:mm:ss"); const now = moment();
const target = targetSingaporeTime.clone().subtract(8, 'hours').utc();
const now = moment().utc();
const diff = target.diff(now); const diff = target.diff(now);
if (diff <= 0) { if (diff <= 0) {