Skip to content
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
5 changes: 3 additions & 2 deletions src/plugin/timezone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions test/plugin/timezone.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})