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 ee0631b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions svelte-app/src/lib/helpers/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit ee0631b

Please sign in to comment.