diff --git a/src/VueDatePicker/utils/util.ts b/src/VueDatePicker/utils/util.ts index 0099df6d6..7f8bb4497 100644 --- a/src/VueDatePicker/utils/util.ts +++ b/src/VueDatePicker/utils/util.ts @@ -25,15 +25,15 @@ export const getArrayInArray = (list: T[], increment = 3): T[][] => { function dayNameIntlMapper(locale: string) { return (day: number) => { - return new Intl.DateTimeFormat(locale, { weekday: 'short', timeZone: 'UTC' }) - .format(new Date(`2017-01-0${day}T00:00:00+00:00`)) + return new Intl.DateTimeFormat(locale, { weekday: 'short' }) + .format(new Date(`2017-01-0${day}T00:00:00`)) .slice(0, 2); }; } function dayNameDateFnsMapper(formatLocale: Locale) { return (day: number) => { - return format(new Date(`2017-01-0${day}T00:00:00+00:00`), 'EEEEEE', { locale: formatLocale }); + return format(new Date(`2017-01-0${day}T00:00:00`), 'EEEEEE', { locale: formatLocale }); }; } @@ -86,7 +86,7 @@ export const getMonths = ( ): IDefaultSelect[] => { const months = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((month) => { const mm = month < 10 ? `0${month}` : month; - return new Date(`2017-${mm}-01T00:00:00+00:00`); + return new Date(`2017-${mm}-01T00:00:00`); }); if (formatLocale !== null) { @@ -104,7 +104,7 @@ export const getMonths = ( } } - const formatter = new Intl.DateTimeFormat(locale, { month: monthFormat, timeZone: 'UTC' }); + const formatter = new Intl.DateTimeFormat(locale, { month: monthFormat }); return months.map((date, i) => { const month = formatter.format(date); return { diff --git a/tests/unit/timezone.spec.ts b/tests/unit/timezone.spec.ts index 7adad9732..b65a9f0b5 100644 --- a/tests/unit/timezone.spec.ts +++ b/tests/unit/timezone.spec.ts @@ -11,7 +11,9 @@ describe('Timezone functionality', () => { const offset = getOffset(local); const zoned = localToTz(local, 'UTC'); - expect(differenceInHours(local, zoned)).toEqual(offset); + const diff = Math.abs(differenceInHours(local, zoned, { roundingMethod: 'round' })); + + expect(diff).toEqual(offset); }); it('Should map date to a timezone depending on the timezone config', () => { @@ -20,7 +22,10 @@ describe('Timezone functionality', () => { const utcExact = new Date(getYear(today), 0, 15, 1, 0, 0, 0); const offset = getOffset(today); const dateInTz = sanitizeDateToLocal(today, { timezone: 'UTC', exactMatch: false }); - expect(differenceInHours(today, dateInTz as Date)).toEqual(offset); + + const diff = Math.abs(differenceInHours(today, dateInTz as Date, { roundingMethod: 'round' })); + + expect(diff).toEqual(offset); const dateExact = sanitizeDateToLocal(utc, { timezone: 'UTC',