Skip to content

Commit

Permalink
Fix format returning wrong time zone offset close to DST
Browse files Browse the repository at this point in the history
  • Loading branch information
marnusw committed Dec 20, 2021
1 parent 72728b7 commit 5eef1ec
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/format/formatters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var formatters = {
X: function (date, token, localize, options) {
var originalDate = options._originalDate || date
var timezoneOffset = options.timeZone
? tzParseTimezone(options.timeZone, originalDate) / MILLISECONDS_IN_MINUTE
? tzParseTimezone(options.timeZone, originalDate, true) / MILLISECONDS_IN_MINUTE
: originalDate.getTimezoneOffset()

if (timezoneOffset === 0) {
Expand Down Expand Up @@ -41,7 +41,7 @@ var formatters = {
x: function (date, token, localize, options) {
var originalDate = options._originalDate || date
var timezoneOffset = options.timeZone
? tzParseTimezone(options.timeZone, originalDate) / MILLISECONDS_IN_MINUTE
? tzParseTimezone(options.timeZone, originalDate, true) / MILLISECONDS_IN_MINUTE
: originalDate.getTimezoneOffset()

switch (token) {
Expand Down Expand Up @@ -70,7 +70,7 @@ var formatters = {
O: function (date, token, localize, options) {
var originalDate = options._originalDate || date
var timezoneOffset = options.timeZone
? tzParseTimezone(options.timeZone, originalDate) / MILLISECONDS_IN_MINUTE
? tzParseTimezone(options.timeZone, originalDate, true) / MILLISECONDS_IN_MINUTE
: originalDate.getTimezoneOffset()

switch (token) {
Expand Down
4 changes: 2 additions & 2 deletions src/format/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ describe('format', function () {
const date = new Date('2020-10-31T21:37:02.233-05:00')
const timeZone = 'America/Chicago'
const offsetDate = utcToZonedTime(date, timeZone)
const result = format(offsetDate, "yyyy-MM-dd h:mmaaaaa'm' xxx", { timeZone })
assert.equal(result, '2020-10-31 9:37pm -05:00')
const result = format(offsetDate, "yyyy-MM-dd h:mmaaaaa'm' xxx XXX OOO zzz", { timeZone })
assert.equal(result, '2020-10-31 9:37pm -05:00 -05:00 GMT-5 CDT')
})
})

Expand Down

0 comments on commit 5eef1ec

Please sign in to comment.