Created
April 24, 2013 08:59
-
-
Save fupslot/5450755 to your computer and use it in GitHub Desktop.
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
// returns total amount of the days that passed since Jan 1 2000 | |
function getDay(aDate) { | |
if (typeof aDate === "string") { | |
aDate = new Date(aDate); | |
} | |
var zeroYear = 2000; | |
var totalYears = aDate.getFullYear() - zeroYear; | |
// calculate all days that passed | |
// since Jan 1 2000 till current time | |
var leapYear; | |
var daysInMonth; | |
var day = 0; | |
for (var j = 0; j < totalYears + 1; j++) { | |
// is current year leap | |
leapYear = ((j + zeroYear) % 4 == 0); | |
// total month in current year | |
var totalMonth = (j == totalYears) ? aDate.getMonth() : 11; | |
for (var i = 1, l = totalMonth + 1; i <= l; i++) { | |
if ((j == totalYears) && (i == l)) { | |
day += aDate.getDate(); | |
} else { | |
day += getDaysByMonth(i, leapYear); | |
} | |
} | |
} | |
return day; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment