diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js index c2caafb5a..5ef35d361 100644 --- a/src/plugin/timezone/index.js +++ b/src/plugin/timezone/index.js @@ -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 } diff --git a/test/plugin/timezone.test.js b/test/plugin/timezone.test.js index da6c743f5..e9fb71f45 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')