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 #1512

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
16 changes: 16 additions & 0 deletions test/plugin/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,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', 'UTC')
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', 'UTC')
const endOfDay = originalDay.endOf('day')
expect(endOfDay.valueOf()).toEqual(originalDay.valueOf())
expect(endOfDay.format()).toEqual(originalDay.format())
})
})