`.month()` resets date property to `1` when in +00:00 UTC timezone
- Dominant language
- JavaScript
- Stars
- 48.7k
- Forks
- 2.5k
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
When using the timezone plugin, if the timezone is in UTC, the `month()` setter function also resets the date property to `1`. When the timezone is in any other UTC offset besides 0, or if no `.tz` is applied, the date stays the same.
```typescript
import dayjs from 'dayjs'
import timezone from 'dayjs/plugin/timezone'
dayjs.extend(timezone)
const d = dayjs('2022-04-19T03:00:00-02:00').tz('America/Godthab')
console.log(dayjs(d).month(3).format()) // => 2022-04-19T03:00:00-02:00
console.log(dayjs(d).month(3).date(d.date()).format()) // => 2022-04-19T03:00:00-02:00
const dUtc = dayjs(d).tz('GMT')
console.log(dayjs(dUtc).month(3).format()) // => 2022-04-01T10:00:00Z
console.log(dayjs(dUtc).month(3).date(dUtc.date()).format()) // => 2022-04-19T10:00:00Z
```
**Expected behavior**
I'd expect `month()` to only change the month (and only reset the `date()` property if it's invalid, such as 31 into a 30-day month).
**Information**
- Day.js Version: `v1.10.7`
- OS: MacOS Monteray 12.3
- Browser: Brave 1.36.122
- Time zone: GMT-05:00 CDT (Central Daylight Time)
Contributor guide
Research direction
Start by reproducing the supplied timezone-plugin example, focusing on the month() setter and the GMT/UTC path. Inspect the timezone handling around that setter and add a regression test showing that changing the month preserves the date when the date remains valid. Verify the existing non-UTC behavior still passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- developer-experience
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100