Created
March 16, 2020 03:06
-
-
Save bonniss/b1942ffbeb3bca4f086641553d7c3dc8 to your computer and use it in GitHub Desktop.
Count the days of a given month and year
This file contains 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
// 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