From d910f2cf270a633007ad6d831a99429f67a6937c Mon Sep 17 00:00:00 2001 From: dtengeri Date: Thu, 24 Sep 2020 15:20:31 +0200 Subject: [PATCH] Fix timezone conversion --- src/plugin/timezone/index.js | 2 +- test/plugin/timezone.test.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js index 6746356bd..e8ed0c2bf 100644 --- a/src/plugin/timezone/index.js +++ b/src/plugin/timezone/index.js @@ -76,7 +76,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) - return d(target).utcOffset(localUtcOffset - diff, true).$set(ms, this.$ms) + return d(target).$set(ms, this.$ms).utcOffset(localUtcOffset - diff, true) } d.tz = function (input, timezone = defaultTimezone) { diff --git a/test/plugin/timezone.test.js b/test/plugin/timezone.test.js index 343bb6265..ced023629 100644 --- a/test/plugin/timezone.test.js +++ b/test/plugin/timezone.test.js @@ -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')