<!doctype html>
<html lang="en">
<head>
<meta charset= "utf-8">
<title>nth days</title>
</head>
<body>
<ul>
<script>
/*
You can use an nthofmonth script, where you can call for the 3rd
or third Monday of January,
for example, for a specified year.
This is an example that may give you an approach.
It returns:
Martin Luther King Day: Monday, January 21, 2013
Presidents Day: Monday, February 18, 2013
Arbor Day: Friday, April 26, 2013
Mothers Day: Sunday, May 12, 2013
Memorial Day: Monday, May 27, 2013
Fathers Day: Sunday, June 16, 2013
Labor Day: Monday, September 02, 2013
Columbus Day: Monday, October 14, 2013
Thanksgiving: Thursday, November 28, 2013
*/
(function(){
var D2={
dayShortNames:['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'],
monthShortNames:['jan', 'feb', 'mar', 'apr', 'may', 'jun',
'jul', 'aug', 'sep', 'oct', 'nov', 'dec'],
nthDay: function(ds, y){
var D, strA, nth, D2= new Date(), wday, m, strA,
days= Date.dayShortNames,
months= Date.monthShortNames,
ords= ['las', 'fir', 'sec', 'thi', 'fou', 'fif'];
if(!y) y= D2.getFullYear();
strA= ds.toLowerCase().replace(/\b(in|of|the)\b/g, '');
strA= strA.replace(/\b([a-z]{3})[a-z]*/g, '$1').trim().split(/\s+/);
nth= strA[0];
nth= (parseInt(nth, 10) || ords.indexOf(nth))-1;
wday= days.indexOf(strA[1]);
m= months.indexOf(strA[2]);
if(nth=== -1) m+= 1;
D2.setFullYear(y, m, 1);
while(D2.getDay()!= wday) D2.setDate(D2.getDate()+1);
D2.setDate(D2.getDate()+(7*nth));
return D2;
},
nthHolidays:[
['Columbus ', 'second Mon in Oct'],
['Arbor ', 'last Friday in April'],
['Thanksgiving', '4th Thurs in Nov', 1863],
['Labor ', 'first Monday in Sept', 1882],
['Memorial ', 'last Mon in May', 1911],
['Presidents ', 'third Mon in Feb', 1968],
['Mothers ', '2nd Sun in May', 1968],
['Fathers ', '3rd Sun in June', 1968],
['Martin Luther King ', '3rd Mon in Jan', 1986]
]
}
for(var p in D2){
if(D2.hasOwnProperty(p)) Date[p]= D2[p];
}
})();
//sample code, y=4 digit year
(function (y){
if(!y) y= new Date().getFullYear();
var list= Date.nthHolidays.map(function(itm){
if(!itm[2] || y>= itm[2]) return [itm[0], Date.nthDay(itm[1], y)];
}).sort(function(a, b){
return a[1]-b[1]
}).map(function(itm){
return itm[0].replace(/ $/, ' Day')+': '+itm[1].toLocaleDateString();
});
document.write('<li>'+ list.join('</li><li><br>')+'</li>');
})()
</script>
</ul>
</body>
</html>