You-Dont-Need-Momentjs
You-Dont-Need-Momentjs copied to clipboard
add a note to native Days in Month
Not sure on the exact wording but native days in month is confusing because the second parameter to Date
is normally zero-based month however in this case, we need the number for the month after the desired month. In other words, December === 11 with zero-based but if we want number of days in December, we have to pass in 12.
Example:
new Date(2018, 11, 0).getDate()
> 30
new Date(2018, 12, 0).getDate()
> 31
Pull Request Test Coverage Report for Build 169
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 100.0%
Totals | |
---|---|
Change from base Build 168: | 0.0% |
Covered Lines: | 43 |
Relevant Lines: | 43 |
💛 - Coveralls
Pull Request Test Coverage Report for Build 169
- 0 of 0 changed or added relevant lines in 0 files are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage remained the same at 100.0%
Totals | |
---|---|
Change from base Build 168: | 0.0% |
Covered Lines: | 43 |
Relevant Lines: | 43 |
💛 - Coveralls
Thanks @cymen. The reason for this is day is 1
-based. So if you supply 0
, it's the same as the last day of last month. I'd add a description at the top stating we are checking how many days in Feb 2012. And perhaps adding a comment in date-fns
to mention this is special.
@stevemao I didn't find the day part confusing -- it's the month or second parameter to new Date()
. If I want the months for December (11
in zero-based), I need to pass in 12
(or the month "after" what I am looking for).
Yeah, because new Date(2012, 02, 0)
is the same as new Date(2012, 01, 29)