Skip to content

Instantly share code, notes, and snippets.

@c7tincu
Created December 8, 2014 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c7tincu/73e1d51845389f4e4351 to your computer and use it in GitHub Desktop.
Save c7tincu/73e1d51845389f4e4351 to your computer and use it in GitHub Desktop.
getMaxDateImpl =
// Returns the maximum valid month day, given a year and a month.
function (year, month) {
return (
indexOf([ 0, 2, 4, 6, 7, 9, 11 ], month) !== - 1 ?
// January, March, May, July, August, October, or December.
31 :
indexOf([ 3, 5, 8, 10 ], month) !== - 1 ?
// April, June, September, or November.
30 :
year % 400 === 0 || year % 100 !== 0 && year % 4 === 0 ?
// February, leap year.
29 :
// February, common year.
28
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment