Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.month() resets date property to 1 when in +00:00 UTC timezone #1860

Open
JohnBDonner opened this issue Apr 18, 2022 · 0 comments
Open

.month() resets date property to 1 when in +00:00 UTC timezone #1860

JohnBDonner opened this issue Apr 18, 2022 · 0 comments

Comments

@JohnBDonner
Copy link

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.

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)
@JohnBDonner JohnBDonner changed the title .month() resets date() property to 1 when in +00:00 UTC timezone .month() resets date property to 1 when in +00:00 UTC timezone Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant