Skip to content

Commit e632f5f

Browse files
authored
Merge pull request #280 from dsun-cp/fix-format-in-timezone-date-string-parsing
fix: formatInTimeZone incorrectly interpreting the input date string
2 parents b1ff162 + b1e1027 commit e632f5f

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/formatInTimeZone/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ export function formatInTimeZone(
3434
timeZone,
3535
originalDate: date,
3636
}
37-
return format(toZonedTime(date, timeZone), formatStr, options)
37+
return format(toZonedTime(date, timeZone, { timeZone: options.timeZone }), formatStr, options)
3838
}

src/formatInTimeZone/test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import { enGB } from 'date-fns/locale/en-GB'
33
import { formatInTimeZone } from './index.js'
44

55
describe('formatInTimeZone', function () {
6+
it('treat date only string in the timezone specified in the options', function () {
7+
assert.equal(formatInTimeZone('2023-04-16', 'GMT', 'MMM dd', { timeZone: 'GMT' }), 'Apr 16')
8+
})
9+
610
describe('shifts the date to the zoned time and formats', function () {
711
var date = '1986-04-04T10:32:55.123Z'
812
var tests = [

0 commit comments

Comments
 (0)