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: incorrect startOf/endOf behavior with +00:00 timezone #1493

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 0 additions & 11 deletions src/plugin/timezone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,6 @@ export default (o, c, d) => {
return result && result.value
}

const oldStartOf = proto.startOf
proto.startOf = function (units, startOf) {
if (!this.$x || !this.$x.$timezone) {
return oldStartOf.call(this, units, startOf)
}

const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'))
const startOfWithoutTz = oldStartOf.call(withoutTz, units, startOf)
return startOfWithoutTz.tz(this.$x.$timezone, true)
}

d.tz = function (input, arg1, arg2) {
const parseFormat = arg2 && arg1
const timezone = arg2 || arg1 || defaultTimezone
Expand Down
17 changes: 17 additions & 0 deletions test/plugin/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const NY = 'America/New_York'
const VAN = 'America/Vancouver'
const DEN = 'America/Denver'
const TOKYO = 'Asia/Tokyo'
const LONDON = 'Europe/London'

describe('Guess', () => {
it('return string', () => {
Expand Down Expand Up @@ -298,11 +299,27 @@ describe('startOf and endOf', () => {
const originalDay = dayjs.tz('2010-01-01 00:00:00', NY)
const startOfDay = originalDay.startOf('day')
expect(startOfDay.valueOf()).toEqual(originalDay.valueOf())
expect(startOfDay.format()).toEqual(originalDay.format())
})

it('corrects for timezone offset in endOf', () => {
const originalDay = dayjs.tz('2009-12-31 23:59:59.999', NY)
const endOfDay = originalDay.endOf('day')
expect(endOfDay.valueOf()).toEqual(originalDay.valueOf())
expect(endOfDay.format()).toEqual(originalDay.format())
})

it('corrects for +00:00 timezone offset in startOf', () => {
const originalDay = dayjs.tz('2021-05-10 00:00:00', LONDON)
const startOfDay = originalDay.startOf('day')
expect(startOfDay.valueOf()).toEqual(originalDay.valueOf())
expect(startOfDay.format()).toEqual(originalDay.format())
})

it('corrects for +00:00 timezone offset in endOf', () => {
const originalDay = dayjs.tz('2021-05-10 23:59:59.999', LONDON)
const endOfDay = originalDay.endOf('day')
expect(endOfDay.valueOf()).toEqual(originalDay.valueOf())
expect(endOfDay.format()).toEqual(originalDay.format())
})
})