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

add a note to native Days in Month #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cymen
Copy link
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

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

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

None yet

3 participants