Skip to content

Commit e73ee06

Browse files
committed
Merge pull request #64 from onlyjsmith/master
Corrected a solution for getting last day of the month
2 parents ca8c051 + c9d17ba commit e73ee06

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

chapters/dates_and_times/finding-last-day-of-the-month.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Use JavaScript's Date underflow to find the -1th day of the following month:
1313

1414
{% highlight coffeescript %}
1515
now = new Date
16-
lastDayOfTheMonth = new Date(1900+now.getYear(), now.getMonth()+1, -1)
16+
lastDayOfTheMonth = new Date(1900+now.getYear(), now.getMonth()+1, 0)
1717
{% endhighlight %}
1818

1919
## Discussion
2020

21-
JavaScript's Date constructor cheerfully handles overflow and underflow conditions, which makes date math very easy. Given this ease of manipulation, it doesn't make sense to worry about how many days are in a given month; just nudge the math around. In December, the solution above will actually ask for the -1th day of the 13th month of the current year, which works out to the -1th day of January of NEXT year, which works out to the 31st day of December of the current year.
21+
JavaScript's Date constructor cheerfully handles overflow and underflow conditions, which makes date math very easy. Given this ease of manipulation, it doesn't make sense to worry about how many days are in a given month; just nudge the math around. In December, the solution above will actually ask for the 0th day of the 13th month of the current year, which works out to the day before the 1st day of January of NEXT year, which works out to the 31st day of December of the current year.

0 commit comments

Comments
 (0)