Fix landing 500 from invalid Asia/Esfahan timezone.

Normalize Iran city aliases to Asia/Tehran, harden the clock, and make settings timezone a safe select.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-30 21:25:45 +03:30
co-authored by Cursor
parent 183ebf5e7f
commit e9eafdaabc
7 changed files with 98 additions and 12 deletions
+7 -8
View File
@@ -18,20 +18,19 @@
</template>
<script setup lang="ts">
import { formatClock } from "~/utils/timezone";
const props = defineProps<{ brand?: string; timezone?: string }>();
const brand = computed(() => props.brand || "منتک");
const time = ref("");
onMounted(() => {
const tz = props.timezone || "Asia/Tehran";
const tick = () => {
time.value = new Intl.DateTimeFormat("fa-IR", {
timeZone: tz,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
}).format(new Date());
try {
time.value = formatClock(new Date(), props.timezone);
} catch {
time.value = "";
}
};
tick();
const id = setInterval(tick, 1000);
+4 -1
View File
@@ -29,7 +29,10 @@
</template>
<script setup lang="ts">
const { data: site } = await useAsyncData("public-site", () => fetchPublicSite());
const { data: site } = await useAsyncData("public-site", () => fetchPublicSite(), {
// always refetch so admin edits show up after refresh
getCachedData: () => undefined,
});
const homePage = computed(() => site.value?.pages?.find((p: any) => p.key === "home"));
applyPageSeo(homePage.value?.seo);
</script>
+32
View File
@@ -0,0 +1,32 @@
const FALLBACK_TZ = "Asia/Tehran";
const TZ_ALIASES: Record<string, string> = {
"Asia/Esfahan": FALLBACK_TZ,
"Asia/Isfahan": FALLBACK_TZ,
"Asia/Mashhad": FALLBACK_TZ,
"Asia/Shiraz": FALLBACK_TZ,
"Asia/Tabriz": FALLBACK_TZ,
Iran: FALLBACK_TZ,
};
export function resolveTimezone(input?: string | null): string {
const raw = (input || FALLBACK_TZ).trim() || FALLBACK_TZ;
const candidate = TZ_ALIASES[raw] || raw;
try {
Intl.DateTimeFormat("en-US", { timeZone: candidate });
return candidate;
} catch {
return FALLBACK_TZ;
}
}
export function formatClock(date: Date, timezone?: string | null, locale = "fa-IR") {
const tz = resolveTimezone(timezone);
return new Intl.DateTimeFormat(locale, {
timeZone: tz,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
hour12: false,
}).format(date);
}