You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some timezone does not have the same UTC all year.
For example in France we're UTC+2 from March to Octobre and UTC+1 from Novembre to February.
You can see that the behavior is the same with Day.js, Moment.js and native Date().
Please note that you can use the timezone plugin in order to take into account the time change when you format your Day.js object.
// dayjs
const d = dayjs('2022-02-28T00:00:00.000Z')
const d2 = d.add(1, 'month')
// moment
const m = moment('2022-02-28T00:00:00.000Z')
const m2 = moment('2022-02-28T00:00:00.000Z')
m2.add(1, 'month')
// native
const j = new Date(2022, 1, 28, 0, 0, 0)
const j2 = new Date(2022, 1, 28, 0, 0, 0)
j2.setMonth(j2.getMonth() + 1)
// one hour difference in relation to UTC
console.log(d.toISOString())
console.log(d2.toISOString())
// same behavior with moment
console.log(m.toISOString())
console.log(m2.toISOString())
// same behavior with native js Date object
console.log(j.toISOString())
console.log(j2.toISOString())
// we can see the explanation here because the utcOffset is different
console.log(d.utcOffset())
console.log(d2.utcOffset())
console.log(j.getTimezoneOffset())
console.log(j2.getTimezoneOffset())
// the timezone plugin allows us to display the date in a consistant way regarding to the user timezone
console.log(d.tz('Europe/Paris').format())
console.log(d2.tz('Europe/Paris').format())
Describe the bug
Adding a month to a date removes an hour.
Expected behavior
Should output
2022-03-28T00:00:00.000Z
Actual behaviour
Outputs
2022-03-27T23:00:00.000Z
Information
The text was updated successfully, but these errors were encountered: