Skip to content

Commit

Permalink
fix: Fix timezone plugin conversion bug (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtengeri authored Sep 25, 2020
1 parent cbb755e commit 16816a3
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 @@ -83,7 +83,7 @@ export default (o, c, d) => {
proto.tz = function (timezone = defaultTimezone) {
const target = this.toDate().toLocaleString('en-US', { timeZone: timezone })
const diff = Math.round((this.toDate() - new Date(target)) / 1000 / 60)
const ins = d(target).utcOffset(localUtcOffset - diff, true).$set(ms, this.$ms)
const ins = d(target).$set(ms, this.$ms).utcOffset(localUtcOffset - diff, true)
ins.$x.$timezone = timezone
return ins
}
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 @@ -86,6 +86,13 @@ describe('Convert', () => {
})
})

it('convert from time with timezone to target time', () => {
const losAngelesInUTC = dayjs('2014-06-01T05:00:00-07:00').tz('UTC')
const MlosAngelesInUTC = moment('2014-06-01T05:00:00-07:00').tz('UTC')
expect(losAngelesInUTC.format()).toBe('2014-06-01T12:00:00Z')
expect(losAngelesInUTC.format()).toBe(MlosAngelesInUTC.format())
})

it('DST', () => {
[dayjs, moment].forEach((_) => {
const jun = _('2014-06-01T12:00:00Z')
Expand Down

0 comments on commit 16816a3

Please sign in to comment.