Skip to content

Commit

Permalink
fix: Try setting UTC date when formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kiosion committed Nov 11, 2023
1 parent e300422 commit bd7da29
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions svelte-app/src/lib/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down

0 comments on commit bd7da29

Please sign in to comment.