Skip to content

Commit

Permalink
Merge pull request #280 from dsun-cp/fix-format-in-timezone-date-stri…
Browse files Browse the repository at this point in the history
…ng-parsing

fix: formatInTimeZone incorrectly interpreting the input date string
  • Loading branch information
marnusw committed Apr 16, 2024
2 parents b1ff162 + b1e1027 commit e632f5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/formatInTimeZone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 4 additions & 0 deletions src/formatInTimeZone/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit e632f5f

Please sign in to comment.