From 6c9047ebc591a08c03dbda704802f8fbf550b555 Mon Sep 17 00:00:00 2001 From: Roushan Singh Date: Fri, 17 Jan 2025 19:32:41 +0530 Subject: [PATCH] fix: timezome update logic based on timezone availability in object --- src/plugin/timezone/index.js | 3 ++- test/timezone.test.js | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js index bcacf9ab6..108135783 100644 --- a/src/plugin/timezone/index.js +++ b/src/plugin/timezone/index.js @@ -123,7 +123,8 @@ export default (o, c, d) => { const oldStartOf = proto.startOf proto.startOf = function (units, startOf) { - if (!this.$x || !this.$x.$timezone) { + if (this.$x && this.$x.$timezone) { + // timezone information is kept in $x: { timezone: "utc"} return oldStartOf.call(this, units, startOf) } diff --git a/test/timezone.test.js b/test/timezone.test.js index 42cab8934..62e40afc1 100644 --- a/test/timezone.test.js +++ b/test/timezone.test.js @@ -45,14 +45,14 @@ it('Diff (DST)', () => { it('UTC add day in DST', () => { const testDate = '2019-03-10' const dayTest = dayjs(testDate) - .utc() + .tz('utc') .startOf('day') const momentTest = moment(testDate) .utc() .startOf('day') - expect(dayTest.add(1, 'day').format()) + expect(dayTest.add(1, 'day').format('YYYY-MM-DDTHH:mm:ss[Z]')) .toBe(momentTest.clone().add(1, 'day').format()) - expect(dayTest.add(2, 'day').format()) + expect(dayTest.add(2, 'day').format('YYYY-MM-DDTHH:mm:ss[Z]')) .toBe(momentTest.clone().add(2, 'day').format()) })