/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ function getNthWeekday(n,strDay,iMonth,iYear){ var targetDay, seekDay; if(strDay=="Sunday") seekDay = 0; if(strDay=="Monday") seekDay = 1; if(strDay=="Tuesday") seekDay = 2; if(strDay=="Wednesday") seekDay = 3; if(strDay=="Thursday") seekDay = 4; if(strDay=="Friday") seekDay = 5; if(strDay=="Saturday") seekDay = 6; var targetDay = new Date(iYear, iMonth+1, 0); // last day of the month var daysInMonth = targetDay.getDate(); targetDay = new Date(iYear, iMonth, 1) var nthDay = (7+seekDay-targetDay.getDay())%7 + 7*(n-1) + 1; if ( nthDay <= daysInMonth ) { targetDay.setDate(nthDay); return targetDay; } else return false; }//end getNthWeekday JS function function niceDate(thisDate) { var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; var iDate = thisDate.getDate(); var ord; if ( iDate == 1 || iDate == 21 || iDate == 31 ) { ord = "st"; } else if (iDate == 2 || iDate == 22) { ord = "nd"; } else if (iDate == 3 || iDate == 23) { ord = "rd"; } else { ord = "th"; } return days[thisDate.getDay()] + ' ' + thisDate.getDate() + ord + ' ' + months[thisDate.getMonth()]; } // end of function function getNextRadwinterCafe() { var today = new Date(); // today = new Date(today.getFullYear(), today.getMonth(),27); var nextMeet; var i = 0; do { nextMeet = getNthWeekday(++i, "Wednesday", today.getMonth(), today.getFullYear()); } while ( nextMeet.getDate() < today.getDate() && i<4 ); if (nextMeet.getDate() < today.getDate()) { // first of next month i = 1; nextMeet = getNthWeekday(1, "Wednesday", today.getMonth()+1, today.getFullYear()); } var venue = " in the Pavilion"; if ( i==1 || i ==3 ) venue = " in the Village Hall"; if (today.getDate() == nextMeet.getDate() ) { return "Today" + venue; } else { return niceDate(nextMeet) + venue; } }