Skip to content

add a note to native Days in Month#66

Open
cymen wants to merge 1 commit intoyou-dont-need:masterfrom
cymen:clarify-native-days-in-month
Open

add a note to native Days in Month#66
cymen wants to merge 1 commit intoyou-dont-need:masterfrom
cymen:clarify-native-days-in-month

Conversation

@cymen
Copy link
Copy Markdown
Contributor

@cymen cymen commented Dec 20, 2018

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

@coveralls
Copy link
Copy Markdown

coveralls commented Dec 20, 2018

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 Coverage Status
Change from base Build 168: 0.0%
Covered Lines: 43
Relevant Lines: 43

💛 - Coveralls

1 similar comment
@coveralls
Copy link
Copy Markdown

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 Coverage Status
Change from base Build 168: 0.0%
Covered Lines: 43
Relevant Lines: 43

💛 - Coveralls

@stevemao
Copy link
Copy Markdown
Member

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.

@cymen
Copy link
Copy Markdown
Contributor Author

cymen commented Dec 20, 2018

@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).

@stevemao
Copy link
Copy Markdown
Member

Yeah, because new Date(2012, 02, 0) is the same as new Date(2012, 01, 29)

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

Successfully merging this pull request may close these issues.

3 participants