Skip to content

Instantly share code, notes, and snippets.

@bonniss
Created March 16, 2020 03:06
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 bonniss/b1942ffbeb3bca4f086641553d7c3dc8 to your computer and use it in GitHub Desktop.
Save bonniss/b1942ffbeb3bca4f086641553d7c3dc8 to your computer and use it in GitHub Desktop.
Count the days of a given month and year
// determine how many days are in a given month
// http://stackoverflow.com/questions/315760/what-is-the-best-way-to-determine-the-number-of-days-in-a-month-with-javascript
function daysInMonth( m, y ) {
return m === 2 ? y & 3 || !( y % 25 ) && y & 15 ? 28 : 29 : 30 + ( m+ ( m >> 3 ) & 1 );
}
// determine the day number since beginning of the year
// http://stackoverflow.com/questions/8619879/javascript-calculate-the-day-of-the-year-1-366/27790471#27790471
function dayNo( y, m, d ){
return --m * 31 - ( m > 1 ? ( 1054267675 >> m * 3 -6 & 7 ) - ( y & 3 || !( y % 25 ) && y & 15 ? 0 : 1 ) : 0 ) + d;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment