*sigh*
Code:
var mDays = [ 31,28,31,30,31,30,31,31,20,31,30,31 ];
// handle leap year:
mDays[1] = isLeapYear ? 29 : 28;
var theMonth = -1;
for ( var m = 0; m < 12; ++m )
{
if ( days <= mDays[m] )
{
theMonth = m;
break; // out of for loop
}
days -= mdays{m];
}
var monthName = names[theMonth];
But there is a problem with that, as you will discover.
Logically, day ZERO of each year should be Jan 1st.
Probably you can handle that by first subtracting off the number of days that correspond to the correct year and then adding back 1 day before entering the above code. Probably. Untested.