From cbc9c0f0b99d10bbbfc26fce8edd9af78ef9f87f Mon Sep 17 00:00:00 2001 From: sevtdy Date: Mon, 10 May 2021 13:51:14 +0800 Subject: [PATCH] fix: incorrect startOf/endOf behavior with +00:00 timezone --- src/plugin/timezone/index.js | 11 ----------- test/plugin/timezone.test.js | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js index c8f8a4675..e8ea8cd5e 100644 --- a/src/plugin/timezone/index.js +++ b/src/plugin/timezone/index.js @@ -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 diff --git a/test/plugin/timezone.test.js b/test/plugin/timezone.test.js index 2b28cc309..70f9c136e 100644 --- a/test/plugin/timezone.test.js +++ b/test/plugin/timezone.test.js @@ -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()) }) })