Skip to content
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
4 changes: 2 additions & 2 deletions src/plugin/timezone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export default (o, c, d) => {
const date = this.toDate()
const target = date.toLocaleString('en-US', { timeZone: timezone })
const diff = Math.round((date - new Date(target)) / 1000 / 60)
let ins = d(target).$set(MS, this.$ms)
let ins = d(target, { locale: this.$L }).$set(MS, this.$ms)
.utcOffset((-Math.round(date.getTimezoneOffset() / 15) * 15) - diff, true)
if (keepLocalTime) {
const newOffset = ins.utcOffset()
Expand All @@ -120,7 +120,7 @@ export default (o, c, d) => {
return oldStartOf.call(this, units, startOf)
}

const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'))
const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'), { locale: this.$L })
const startOfWithoutTz = oldStartOf.call(withoutTz, units, startOf)
return startOfWithoutTz.tz(this.$x.$timezone, true)
}
Expand Down
11 changes: 11 additions & 0 deletions test/plugin/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,15 @@ describe('startOf and endOf', () => {
const endOfDay = originalDay.endOf('day')
expect(endOfDay.valueOf()).toEqual(originalDay.valueOf())
})

it('preserves locality when tz is called', () => {
const tzWithoutLocality = dayjs.tz('2023-02-17 00:00:00', NY)
const tzWithLocality = dayjs.tz('2023-02-17 00:00:00', NY).locale({
name: 'locale_test',
weekStart: 3
})

expect(tzWithoutLocality.startOf('week').format('YYYY-MM-DD')).toEqual('2023-02-12')
expect(tzWithLocality.startOf('week').format('YYYY-MM-DD')).toEqual('2023-02-15')
})
})