Skip to content

Commit

Permalink
fix: Fix Timezone plugin UTCOffset rounding bug (#987)
Browse files Browse the repository at this point in the history
fix #986
  • Loading branch information
iamkun committed Aug 6, 2020
1 parent 0f881c1 commit b07182b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/plugin/timezone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default (o, c, d) => {
const proto = c.prototype
proto.tz = function (timezone) {
const target = this.toDate().toLocaleString('en-US', { timeZone: timezone })
const diff = (this.toDate() - new Date(target)) / 1000 / 60
const diff = Math.round((this.toDate() - new Date(target)) / 1000 / 60)
return d(target).utcOffset(localUtcOffset - diff, true)
}
d.tz = function (input, timezone) {
Expand Down
7 changes: 7 additions & 0 deletions test/plugin/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ describe('Convert', () => {
expect(dec.tz('Australia/Sydney').format('ha')).toBe('11pm')
})
})

it('format Z', () => {
[dayjs, moment].forEach((_) => {
const losAngeles = _('2020-08-06T03:48:10.258Z').tz('Asia/Tokyo')
expect(losAngeles.format('Z')).toBe('+09:00')
})
})
})


Expand Down

0 comments on commit b07182b

Please sign in to comment.