Created by
Steven Berlan
| function sundays(startYear, startMonth, startDay, endYear, endMonth, endDay) {
var start = ;
var end = ;
return count(endYear, endMonth, endDay) - count(startYear, startMonth, startDay);
function count(year, month, day) {
var monthDays = [ 31, isLeap(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
for (var days = 0, i = 1900; i < year; ++i) {
days += isLeap(year) ? 366 : 365;
}
days += monthDays.slice(0, month-1).reduce(function(start, days) {
return start + days;
}, day);
return days / 7 | 0;
}
function isLeap(year) {
return (year % 4) && ((year % 100) > 0 || !(year % 400));
}
}
sundays(1901, 1, 1, 2000, 12, 31);
|