From b1e1027160f30acedc53d413d2b35b4e72ee43f6 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 16 Apr 2024 11:42:42 +1000 Subject: [PATCH] fix formatInTimeZone incorrectly interpreting the input date string * fixing https://github.com/marnusw/date-fns-tz/issues/279 --- src/formatInTimeZone/index.ts | 2 +- src/formatInTimeZone/test.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/formatInTimeZone/index.ts b/src/formatInTimeZone/index.ts index fb19a23..dc83477 100644 --- a/src/formatInTimeZone/index.ts +++ b/src/formatInTimeZone/index.ts @@ -34,5 +34,5 @@ export function formatInTimeZone( timeZone, originalDate: date, } - return format(toZonedTime(date, timeZone), formatStr, options) + return format(toZonedTime(date, timeZone, { timeZone: options.timeZone }), formatStr, options) } diff --git a/src/formatInTimeZone/test.js b/src/formatInTimeZone/test.js index ff92392..2e0bcb3 100644 --- a/src/formatInTimeZone/test.js +++ b/src/formatInTimeZone/test.js @@ -3,6 +3,10 @@ import { enGB } from 'date-fns/locale/en-GB' import { formatInTimeZone } from './index.js' describe('formatInTimeZone', function () { + it('treat date only string in the timezone specified in the options', function () { + assert.equal(formatInTimeZone('2023-04-16', 'GMT', 'MMM dd', { timeZone: 'GMT' }), 'Apr 16') + }) + describe('shifts the date to the zoned time and formats', function () { var date = '1986-04-04T10:32:55.123Z' var tests = [