From ee0631bdb3a79938d4c735b07d460e39d6556406 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/svelte-app/src/lib/helpers/date.ts b/svelte-app/src/lib/helpers/date.ts index 11a67604e..8e5bd1d99 100644 --- a/svelte-app/src/lib/helpers/date.ts +++ b/svelte-app/src/lib/helpers/date.ts @@ -7,8 +7,13 @@ export const formatDate = ( format: 'full' | 'med' | 'short' = 'full', lang: string = get(currentLang) || 'en' ) => { - const date = new Date(dateStr); - date.setHours(0 - date.getTimezoneOffset() / 60); + const [year, month, day] = dateStr.split('-'), + date = new Date(dateStr); + + year !== undefined && date.setUTCFullYear(parseInt(year, 10)); + month !== undefined && date.setUTCMonth(parseInt(month, 10) - 1); + day !== undefined && date.setUTCDate(parseInt(day, 10)); + switch (format) { case 'full': return new Intl.DateTimeFormat(lang, {