diff --git a/src/plugin/timezone/index.js b/src/plugin/timezone/index.js index bcacf9ab6..2bbf4482d 100644 --- a/src/plugin/timezone/index.js +++ b/src/plugin/timezone/index.js @@ -127,9 +127,10 @@ export default (o, c, d) => { return oldStartOf.call(this, units, startOf) } - const withoutTz = d(this.format('YYYY-MM-DD HH:mm:ss:SSS'), { locale: this.$L }) + const timezone = this.$x.$timezone + const withoutTz = this.clone().$set('$x', {}) const startOfWithoutTz = oldStartOf.call(withoutTz, units, startOf) - return startOfWithoutTz.tz(this.$x.$timezone, true) + return startOfWithoutTz.tz(timezone, true) } d.tz = function (input, arg1, arg2) { diff --git a/test/plugin/timezone.test.js b/test/plugin/timezone.test.js index d83a03f8a..3a51c0cca 100644 --- a/test/plugin/timezone.test.js +++ b/test/plugin/timezone.test.js @@ -352,3 +352,18 @@ describe('UTC timezone', () => { expect(dayjs2.format()).toBe(moment2.format()) }) }) + +describe('add after startOf', () => { + it('corrects startOf month in UTC', () => { + const originalDay = dayjs.tz('2025-01-31', 'etc/UTC') + const startOfDay = originalDay.startOf('month') + expect(startOfDay.format('YYYY-MM-DD')).toEqual('2025-01-01') + }) + + it('corrects startOf and add in UTC', () => { + const originalDay = dayjs.tz('2025-01-31', 'etc/UTC') + const startOfDay = originalDay.startOf('month') + const addedDay = startOfDay.add(3, 'month') + expect(addedDay.format('YYYY-MM-DD')).toEqual('2025-04-01') + }) +})