From 05d3c8886619908ca54814e07b7d00bd87d9a067 Mon Sep 17 00:00:00 2001 From: Sean Date: Wed, 25 Sep 2024 21:12:11 -0700 Subject: [PATCH] Use Pacific Time on server side (#264) --- src/lib/utils.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f2a4f3bc..0063f7f1 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -183,19 +183,22 @@ export function useObjectUrl(file?: Blob | null): string { return url; } +// Set timeZone to Pacific Time on server-side, use local time on client. Users +// will usually be in California, so this helps with hydration. const dateFormat = new Intl.DateTimeFormat('en-US', { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', + timeZone: typeof window === 'undefined' ? 'America/Los_Angeles' : undefined, }); - const dateFormatWithYear = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', + timeZone: typeof window === 'undefined' ? 'America/Los_Angeles' : undefined, }); export const formatDate = (date: Date | string, year?: boolean): string => {