Skip to content

Commit

Permalink
fix: Fix zero offset issue when use tz with locale (#2532)
Browse files Browse the repository at this point in the history
* test: add test case for tz with locale

* fix: set utc as false if $offset is 0
  • Loading branch information
ohsory1324 authored Jul 18, 2024
1 parent 9635a93 commit d0e6738
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const dayjs = function (date, c) {
const wrapper = (date, instance) =>
dayjs(date, {
locale: instance.$L,
utc: instance.$u,
utc: instance.$offset !== 0 && instance.$u,
x: instance.$x,
$offset: instance.$offset // todo: refactor; do not use this.$offset in you code
})
Expand Down
10 changes: 10 additions & 0 deletions test/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import moment from 'moment'
import dayjs from '../src'
import timezone from '../src/plugin/timezone'
import utc from '../src/plugin/utc'
import '../src/locale/en'

dayjs.extend(utc)
dayjs.extend(timezone)
Expand Down Expand Up @@ -80,3 +81,12 @@ it('UTC diff in DST', () => {
expect(day1.diff(day2, 'd'))
.toBe(-3)
})

it('TZ with Locale', () => {
const test1 = dayjs('2000-01-01T09:00:00+09:00').tz('Asia/Seoul').locale('en')
expect(test1.hour()).toBe(9)
const test2 = dayjs('2000-01-01T09:00:00+09:00').tz('Asia/Hong_Kong').locale('en')
expect(test2.hour()).toBe(8)
const test3 = dayjs('2000-01-01T09:00:00+09:00').tz('Etc/UTC').locale('en')
expect(test3.hour()).toBe(0)
})

0 comments on commit d0e6738

Please sign in to comment.