Skip to content

Commit d0e6738

Browse files
authored
fix: Fix zero offset issue when use tz with locale (#2532)
* test: add test case for tz with locale * fix: set utc as false if $offset is 0
1 parent 9635a93 commit d0e6738

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const dayjs = function (date, c) {
5050
const wrapper = (date, instance) =>
5151
dayjs(date, {
5252
locale: instance.$L,
53-
utc: instance.$u,
53+
utc: instance.$offset !== 0 && instance.$u,
5454
x: instance.$x,
5555
$offset: instance.$offset // todo: refactor; do not use this.$offset in you code
5656
})

test/timezone.test.js

+10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import moment from 'moment'
33
import dayjs from '../src'
44
import timezone from '../src/plugin/timezone'
55
import utc from '../src/plugin/utc'
6+
import '../src/locale/en'
67

78
dayjs.extend(utc)
89
dayjs.extend(timezone)
@@ -80,3 +81,12 @@ it('UTC diff in DST', () => {
8081
expect(day1.diff(day2, 'd'))
8182
.toBe(-3)
8283
})
84+
85+
it('TZ with Locale', () => {
86+
const test1 = dayjs('2000-01-01T09:00:00+09:00').tz('Asia/Seoul').locale('en')
87+
expect(test1.hour()).toBe(9)
88+
const test2 = dayjs('2000-01-01T09:00:00+09:00').tz('Asia/Hong_Kong').locale('en')
89+
expect(test2.hour()).toBe(8)
90+
const test3 = dayjs('2000-01-01T09:00:00+09:00').tz('Etc/UTC').locale('en')
91+
expect(test3.hour()).toBe(0)
92+
})

0 commit comments

Comments
 (0)