From bd7da29a5cfa72fbc30c718e1f390e0baaeb03c6 Mon Sep 17 00:00:00 2001 From: kiosion Date: Sat, 11 Nov 2023 17:28:16 -0500 Subject: [PATCH] fix: Try setting UTC date when formatting --- svelte-app/src/lib/helpers/date.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/svelte-app/src/lib/helpers/date.ts b/svelte-app/src/lib/helpers/date.ts index 11a67604e..65c4ba0f5 100644 --- a/svelte-app/src/lib/helpers/date.ts +++ b/svelte-app/src/lib/helpers/date.ts @@ -8,24 +8,27 @@ export const formatDate = ( lang: string = get(currentLang) || 'en' ) => { const date = new Date(dateStr); - date.setHours(0 - date.getTimezoneOffset() / 60); + switch (format) { case 'full': return new Intl.DateTimeFormat(lang, { month: 'long', day: 'numeric', - year: 'numeric' + year: 'numeric', + timeZone: 'UTC' }).format(date); case 'short': return new Intl.DateTimeFormat(lang, { month: 'short', - day: 'numeric' + day: 'numeric', + timeZone: 'UTC' }).format(date); case 'med': return new Intl.DateTimeFormat(lang, { month: 'short', day: 'numeric', - year: 'numeric' + year: 'numeric', + timeZone: 'UTC' }).format(date); } };