Last active
August 29, 2015 13:56
-
-
Save davidglezz/8897869 to your computer and use it in GitHub Desktop.
Gets the number of days in a month (0-11)
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
// without lookup table | |
function getMonthDays_A (month, year) | |
{ | |
if (month === 1) | |
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28; | |
if (month % 2) | |
return month > 6 ? 31 : 30; | |
return month > 6 ? 30 : 31; | |
} | |
// with lookup table | |
function getMonthDays_B (month, year) | |
{ | |
if (month === 1 && year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) | |
return 29; | |
return [31,28,31,30,31,30,31,31,30,31,30,31][month]; | |
} | |
// mini | |
function getMonthDays_C (month, year) | |
{ | |
return (month === 1 && year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) ? 29 : [31,28,31,30,31,30,31,31,30,31,30,31][month]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment