Last active
January 10, 2020 19:43
-
-
Save TehShrike/6a27b28160bad1e3ccd98e2ee3ea752c to your computer and use it in GitHub Desktop.
daysInMonth.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An expansion of https://stackoverflow.com/a/1184359/201789 | |
function daysInMonth (oneIndexedInputMonth, year) { | |
const zeroIndexedInputMonth = oneIndexedInputMonth - 1 | |
const theNextZeroIndexedMonth = zeroIndexedInputMonth + 1 | |
const theFinalDayOfThePreviousMonth = 0 | |
return new Date(year, theNextZeroIndexedMonth, theFinalDayOfThePreviousMonth).getDate() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment