Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timezone conversion #1073

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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