Created
December 21, 2012 04:15
-
-
Save markandey/4350630 to your computer and use it in GitHub Desktop.
Generates monthly time duration to execute some query, helpful when generating monthly reports.
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
function getCurrentYear(){ | |
return (new Date()).getYear()+1900; | |
} | |
function isLeapYear(year) { | |
var d = new Date(year, 1, 29); | |
return d.getMonth() == 1; | |
} | |
function getMonthDays(month,year){ | |
var monthDays=[31,28,31,30,31,30,31,31,30,31,30,31]; | |
month=month%12; | |
if(month==1 && isLeapYear(year)){ | |
return 29; | |
} | |
return monthDays[month]; | |
} | |
function getDurationCalendar(year){ | |
var durationCal=[], | |
monthName=["January","February","March","April","May","June","July","August","September","October","November","December"]; | |
for(var i=0;i<12;i++){ | |
durationCal[durationCal.length]={ | |
'start':new Date(year,i,1,0,0,0,0), | |
'end':new Date(year,i,getMonthDays(i,year),23,59,59,999), | |
'month':monthName[i], | |
} | |
} | |
return durationCal; | |
} | |
function getCurrentYearDurationCalendar(){ | |
return getDurationCalendar(getCurrentYear()); | |
} | |
function testDurationCalendar(){ | |
for(var year=1999;year<2013;year++){ | |
var durationCal=getDurationCalendar(year) | |
for(var i=0;i<durationCal.length;i++){ | |
console.log(year,'within-->',Math.round((durationCal[i].end - durationCal[i].start)/86400000)); | |
if(i>0){ | |
console.log('transition-->',Math.round((durationCal[i].start - durationCal[i-1].end)/86400000)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment