Closed MSeeligHEC closed 10 months ago
Just updated to 3.4.3 and the Problem still exists.
hasSame('month')
asks "do these dates have the same calendar month". September 1971 and September 2023 are not the same calendar month. Even though both are a September, they are in different years and thus are different calendar months.
Another way to think about this is that hasSame('month')
implies hasSame('year')
.
If you want to check if the month is the same regardless of year, just check if the month property is the same:
const a = DateTime.fromJSDate(new Date(1971, 8, 8, 0, 0, 0, 0));
const b = DateTime.fromJSDate(new Date(2023, 8, 8, 0, 0, 0, 0));
console.log(a.month === b.month); // true
Just to be sure. If i check the day with hasSame it should also return false since they are not in the same year?
Correct. You can think of hasSame(<unit>)
checking that unit and all bigger units.
Describe the bug Using hasSame to check if two date times have the same month fails.
To Reproduce
Actual vs Expected behavior Using hasSame to check month should work correctly. If the first date time has september as month and the date time it gets checked with is also in september it shloud return true.
Desktop (please complete the following information):