Javascript Date / boolean isBusinessDay

Good Day Folks,

I have written a quick snippet of code to verify whether or not a date is a holiday/weekend or a valid business day.

I am hung up on an error on this line in my code;

"if (easterday.equals(cdate)) " - Stating that “Object doesn’t support this property or method”

I dont’ understand since both fields are Date fields.

Any help would be appreciated… as this works in LS I just converted it to JS…

Source pasted for all JS below.

function f_Submit(){

if ( document.forms[0].LogOnID.value=="" )  

            { 

	alert ("Please enter your ACF2 or LogOn ID");

	document.forms[0].LogOnID.focus();

                            document.forms[0].LogOnID.select(); 

	return false;

}

if ( document.forms[0].PhoneNumber.value=="" ) { 

	alert ("Please enter your phone number");

	document.forms[0].PhoneNumber.focus();

                            document.forms[0].PhoneNumber.select(); 

	return false;

            }

if (! f_v_PhoneNum(document.forms[0].PhoneNumber.value)){

	alert("Invalid primary contact phone number.  Please format as xxx-xxx-xxxx");

	document.forms[0].PhoneNumber.focus();

	document.forms[0].PhoneNumber.select();

	return false;

}

if (isDate(document.forms[0].DateLaunch.value) ==false){

alert("Please enter the Project Launch Date (mm/dd/yyyy).");

	document.forms[0].DateLaunch.focus();

	document.forms[0].DateLaunch.select();

	return false;

}

if (isDate(document.forms[0].DateStart.value) ==false){

alert("Please enter the Preferred Testing Start date (mm/dd/yyyy).");

	document.forms[0].DateStart.focus();

	document.forms[0].DateStart.select();

	return false;

}

if (isDate(document.forms[0].DateEnd.value) ==false){

alert("Please enter the Preferred Testing End date (mm/dd/yyyy).");

	document.forms[0].DateEnd.focus();

	document.forms[0].DateEnd.select();

	return false;

}

if (isBusinessDay(document.forms[0].DateStart.value) == false){

alert("Please enter a Preferred Testing Start date that falls on a valid business day.");

	document.forms[0].DateStart.focus();

	document.forms[0].DateStart.select();

	return false;

}

if (isBusinessDay(document.forms[0].DateEnd.value) == false){

alert("Please enter a Preferred Testing End date that falls on a valid business day.");

	document.forms[0].DateEnd.focus();

	document.forms[0].DateEnd.select();

	return false;

}

if ( document.forms[0].DateLaunch.value > document.forms[0].DateEnd.value){

alert("Please select a Launch date which follows the End date for testing.");

document.forms[0].DateLaunch.focus();

document.forms[0].DateLaunch.select();

return false;

}

if ( document.forms[0].DateEnd.value < document.forms[0].DateStart.value){

alert("Please select a End date which follows your Start date.");

document.forms[0].DateEnd.focus();

document.forms[0].DateEnd.select();

return false;

}

if (document.forms[0].ProjectName.value==“”) {

alert("Please enter the Project Name.");

document.forms[0].ProjectName.focus();

document.forms[0].ProjectName.select();

return false;

}

if (document.forms[0].ProjectType[0].checked == false

&& document.forms[0].ProjectType[1].checked == false

&& document.forms[0].ProjectType[2].checked == false

&& document.forms[0].ProjectType[3].checked == false) {

alert ("Please select the Type of Project");

return false;

}

if (document.forms[0].ProjectLang[0].checked == false

&& document.forms[0].ProjectLang[1].checked == false

&& document.forms[0].ProjectLang[2].checked == false) {

alert ("Please select the Project Language");

return false;

}

if (document.forms[0].ProjectDesc.value==“”) {

alert("Please enter a description of the Project.");

document.forms[0].ProjectDesc.focus();

document.forms[0].ProjectDesc.select();

return false;

}

document.forms[0].submit();

return true;

}

function f_reset(){

document.forms[0].reset();

}

function isInteger(s){

var i;

for (i = 0; i < s.length; i++){   

    // Check that current character is number.

    var c = s.charAt(i);

    if (((c < "0") || (c > "9"))) return false;

}

// All characters are numbers.

return true;

}

function stripCharsInBag(s, bag){

var i;

var returnString = "";

// Search through string's characters one by one.

// If character is not in bag, append to returnString.

for (i = 0; i < s.length; i++){   

    var c = s.charAt(i);

    if (bag.indexOf(c) == -1) returnString += c;

}

return returnString;

}

function daysInFebruary (year){

// February has 29 days in any year evenly divisible by four,

// EXCEPT for centurial years which are not also divisible by 400.

return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );

}

function DaysArray(n) {

for (var i = 1; i <= n; i++) {

	this[i] = 31

	if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}

	if (i==2) {this[i] = 29}

}

return this

}

function isDate(dtStr){

var dtCh= “/”;

var minYear=2000;

var maxYear=2100;

var daysInMonth = DaysArray(12)

var pos1=dtStr.indexOf(dtCh)

var pos2=dtStr.indexOf(dtCh,pos1+1)

var strMonth=dtStr.substring(0,pos1)

var strDay=dtStr.substring(pos1+1,pos2)

var strYear=dtStr.substring(pos2+1)

strYr=strYear

if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)

if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)

for (var i = 1; i <= 3; i++) {

	if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)

}

month=parseInt(strMonth)

day=parseInt(strDay)

year=parseInt(strYr)

if (pos1==-1 || pos2==-1){

	alert("The date format should be : mm/dd/yyyy")

	return false

}

if (strMonth.length<1 || month<1 || month>12){

	alert("Please enter a valid month")

	return false

}

if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){

	alert("Please enter a valid day")

	return false

}

if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){

	alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)

	return false

}

if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){

	alert("Please enter a valid date")

	return false

}

return true

}

//999-999-9999

function f_v_PhoneNum(elm) {

if ( elm.value == "N/A")

return true;

if ( elm.length != 12)	return false;

for (var i = 0; i < elm.length; i++) {

	if ((i <= 2 && i >= 0 ) || (i >= 4 && i <= 6) || (i>=8 && i <= 11)) {

		if (elm.charAt(i) < "0" || elm.charAt(i) > "9")

		return false;

	}

	else if (elm.charAt(i) != "-")

	return false;

}

return true;

}

var dayA = new Array();

var monthA = new Array();

var yearA = new Array();

var targetfield;

monthA[0]=“January”;

monthA[1]=“February”;

monthA[2]=“March”;

monthA[3]=“April”;

monthA[4]=“May”;

monthA[5]=“June”;

monthA[6]=“July”;

monthA[7]=“August”;

monthA[8]=“September”;

monthA[9]=“October”;

monthA[10]=“November”;

monthA[11]=“December”;

for(var i=1;i<=31;i++)

{

dayA[i]=i;

}

for(var i=0;i<10;i++)

{

yearA[i]=gy(i);

}

function gm(num) {

var mydate = new Date();

mydate.setDate(1);

mydate.setMonth(num-1);

var datestr = “” + mydate;

return datestr.substring(4,7);

}

function gy(num) {

var mydate = new Date();

return (eval(mydate.getYear()) - 4 + num);

}

function ud(mon) {

var i = mon.selectedIndex;

if(mon.options[i].value == “2”) {

document.forms[0].day.options[30] = null; 

document.forms[0].day.options[29] = null; 

var j = document.forms[0].year.selectedIndex; 

var year = eval(document.forms[0].year.options[j].value); 

if ( ((year%400)==0) || (((year%100)!=0) && ((year%4)==0)) ) { 

  if (document.forms[0].day.options[28] == null) { 

    document.forms[0].day.options[28] = new Option("29"); 

    document.forms[0].day.options[28].value = "29"; 

  } 

} else { 

  document.forms[0].day.options[28] = null; 

} 

}

if(mon.options[i].value == “1” ||

 mon.options[i].value == "3" || 

 mon.options[i].value == "5" || 

 mon.options[i].value == "7" || 

 mon.options[i].value == "8" || 

 mon.options[i].value == "10" || 

 mon.options[i].value == "12") 

{

if (document.forms[0].day.options[28] == null) { 

  document.forms[0].day.options[28] = new Option("29"); 

  document.forms[0].day.options[28].value = "29"; 

} 

if (document.forms[0].day.options[29] == null) { 

  document.forms[0].day.options[29] = new Option("30"); 

  document.forms[0].day.options[29].value = "30"; 

} 

if (document.forms[0].day.options[30] == null) { 

  document.forms[0].day.options[30] = new Option("31"); 

  document.forms[0].day.options[30].value = "31"; 

} 

}

if(mon.options[i].value == “4” ||

 mon.options[i].value == "6" || 

 mon.options[i].value == "9" || 

 mon.options[i].value == "11") 

{

if (document.forms[0].day.options[28] == null) { 

  document.forms[0].day.options[28] = new Option("29"); 

  document.forms[0].day.options[28].value = "29"; 

} 

if (document.forms[0].day.options[29] == null) { 

  document.forms[0].day.options[29] = new Option("30"); 

  document.forms[0].day.options[29].value = "30"; 

} 

document.forms[0].day.options[30] = null; 

}

if (document.forms[0].day.selectedIndex == -1)

document.forms[0].day.selectedIndex = 0; 

}

function showdate() {

var i = document.forms[0].month.selectedIndex;

var j = document.forms[0].day.selectedIndex;

var k = document.forms[0].year.selectedIndex;

alert(document.forms[0].day.options[j].value + “/” +

    document.forms[0].month.options[i].value + "/" + 

    document.forms[0].year.options[k].value) 

}

function opencalendar(temptargetfield) {

var field= eval(“document.forms[0].” + temptargetfield);

targetfield = “opener.document.forms[0].” + temptargetfield + “.value”;

var mydate;

if(field.value == “” || field.value.length < 10 || field.value.length >10)

{

mydate = new Date();

}

else

{

var tempday = field.value.charAt(0).toString() + field.value.charAt(1).toString();

var tempmonth = (parseInt((parsemonth(field.value.charAt(3).toString(), field.value.charAt(4).toString())))-1).toString();

var tempyear = (parseInt(field.value.charAt(6).toString() + field.value.charAt(7).toString() + field.value.charAt(8).toString() + field.value.charAt(9).toString())).toString();

mydate = new Date(tempyear, tempmonth, tempday );

}

for(var i=0;i<=monthA.length;i++)

{

if (mydate.getMonth() == i) 

{

	month = i+1;

}

}

year = mydate.getYear();

//yearA[4].toString();

calwin = window.open(“”,“calwin”,“resizable,status,height=250,width=210”);

calccal(calwin,month,year,targetfield);

}

function parsemonth(tmpm1, tmpm2)

{

var m1;

var m2;

var m3;

if (tmpm1 == “0”)

{

m1 = “”;

}

else

{

m1 = “1”;

}

m2 = tmpm2;

m3 = m1.toString() + m2.toString();

return m3;

}

function calccal(targetwin,month,year,targetfield) {

var monthname = new Array(12);

monthname[0] = “January”;

monthname[1] = “February”;

monthname[2] = “March”;

monthname[3] = “April”;

monthname[4] = “May”;

monthname[5] = “June”;

monthname[6] = “July”;

monthname[7] = “August”;

monthname[8] = “September”;

monthname[9] = “October”;

monthname[10] = “November”;

monthname[11] = “December”;

var endday = calclastday(eval(month),eval(year));

mystr = month + “/01/” + year;

mydate = new Date(mystr);

firstday = mydate.getDay();

var cnt = 0;

var day = new Array(6);

for (var i=0; i<6; i++)

day[i] = new Array(7); 

for (var r=0; r<6; r++)

{

for (var c=0; c<7; c++) 

{ 

  if ((cnt==0) && (c!=firstday)) 

    continue; 

  cnt++; 

  day[r][c] = cnt; 

  if (cnt==endday) 

    break; 

} 

if (cnt==endday) 

  break; 

}

targetwin.document.write(“

”);

var prevyear = eval(year) - 1;

targetwin.document.write(“

");

var prevmonth = calcprevmonth(month);

var prevmonthyear = calcprevyear(month,year);

targetwin.document.write(“

");

targetwin.document.write(“

”);

var nextmonth = calcnextmonth(month);

var nextmonthyear = calcnextyear(month,year);

targetwin.document.write(“

");

var nextyear = eval(year) + 1;

targetwin.document.write(“

");

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

targetwin.document.write(“

”);

var selectedmonth = eval(month) - 1;

var today = new Date();

var thisyear = today.getYear();

var selectedyear = eval(year) - thisyear + 4;

var conditionalpadder = “”;

for(r=0; r<6; r++)

{

targetwin.document.write(“

”);

for(c=0; c<7; c++)

{

targetwin.document.write("<TD>"); 

if(day[r][c] != null) { 

  if (day[r][c] < 10) 

    conditionalpadder = "&nbsp;" 

  else 

    conditionalpadder = ""; 

  targetwin.document.write("<INPUT TYPE=BUTTON NAME="+day[r][c]+         " VALUE=" + conditionalpadder + day[r][c] + conditionalpadder +  

" onClick=\"window.close();" +targetfield+"='"+ (selectedmonth+1).toString() + "/" + (day[r][c]).toString() + "/" + yearA[selectedyear.toString()]+"';\";>");    } 

targetwin.document.write("</TD>"); 

}

targetwin.document.write(“

”);

}

targetwin.document.write(“

<INPUT TYPE=BUTTON NAME=prevyearbutton VALUE=‘<<’”+

" onclick=‘document.close();opener.calccal(opener.calwin,“+month+”,“+prevyear+”,"“+targetfield+”")’>

<INPUT TYPE=BUTTON NAME=prevmonthbutton VALUE=’ < '”+

" onclick=‘document.close();opener.calccal(opener.calwin,“+prevmonth+”,“+prevmonthyear+”,"“+targetfield+”")’>

”);

var index = eval(month) - 1;

targetwin.document.write(“” + monthname[index] + " " + year + “

<INPUT TYPE=BUTTON NAME=nextmonthbutton VALUE=’ > '”+

" onclick=‘document.close();opener.calccal(opener.calwin,“+nextmonth+”,“+nextmonthyear+”,"“+targetfield+”")’>

<INPUT TYPE=BUTTON NAME=nextyearbutton VALUE=‘>>’”+

" onclick=‘document.close();opener.calccal(opener.calwin,“+month+”,“+nextyear+”,"“+targetfield+”")’>

Su Mo Tu We Th Fr Sa

”);

}

function calclastday(month,year) {

if ((month==2) && ((year%4)==0))

return 29; 

if ((month==2) && ((year%4)!=0))

return 28; 

if ((month==1) || (month == 3) || (month == 5) || (month == 7) ||

  (month==8) || (month == 10) || (month ==12)) 

return 31; 

return 30;

}

function calcnextmonth(month) {

if (month==“12”)

return "1"; 

else

return (eval(month)+1); 

}

function calcnextyear(month,year) {

if (month==“12”)

return (eval(year)+1); 

else

return (year); 

}

function calcprevmonth(month) {

if (month==“1”)

return "12"; 

else

return (eval(month)-1); 

}

function calcprevyear(month,year) {

if (month==“1”)

return (eval(year)-1); 

else

return (year); 

}

function isBusinessDay(cdate){

fdate = new Date(cdate);

if ( isWeekEnd(fdate) == true | isHoliday(fdate == true )){

return false;

}

else{

return true;

}

}

function isWeekEnd(cdate)

{

if ( fdate.getDay() == 0 | fdate.getDay() == 6)

	{

	return true;

	}

else

	{

	return false;

	}

}

function dateEaster(y) {

var cer, n, k, i, j, l, m, d;

cer = y / 100;

n = y - 19 * ( y / 19 );

k = ( cer - 17 ) / 25;

i = cer - cer / 4 - ( cer - k ) / 3 + 19 * n + 15;

i = i - 30 * ( i / 30 );

i = i - ( i / 28 ) * ( 1 - ( i / 28 ) * ( 29 / ( i + 1 ) ) * ( ( 21 - n ) / 11 ) );

j = y + y / 4 + i + 2 - cer + cer / 4;

j = j - 7 * ( j / 7 );

l = i - j;

m = 3 + ( l + 40 ) / 44;

d = l + 28 - 31 * ( m / 4 );

return new Date( y, m, d );

}

function getFirstDayOfMonth(cdate)

{

var mon, da, rflag = "false" ;

cmpdate = new Date(cdate);

while ( rflag != "true" )

	{	

	if ( cmpdate.getDay() == 0 && cmpdate.getDate() <= 6) 

		{

		num = cmpdate.getDate()-10;

		cmpdate.setDate(num);

		}

	else if ( cmpdate.getDay() == 1 && cmpdate.getDate() <= 7 )

		{

		return cmpdate;

		rflag = "true";

		}

	else if ( cmpdate.getDay() > 1 && cmpdate.getDate() < 6)

		{

		num = cmpdate.getDate()-10;

		cmpdate.setDate(num);

		}

	else if (cmpdate.getDay() != 1 && cmpdate.getDate() <= 7)

		{

		While (cmpdate.GetDay() != 1)

			{

			num = cmpdate.getDate()-1;

			cmpdate.setDate(num);

			}

		return cmpdate;

		rflag - "true"

		}

	}

}

function getLastSundayOfMonth(cdate){

var tmpdate, mnth, dy, num, yr;

tmpdate = GetFirstMondayOfMonth(cdate);

dy	= tmpdate.getDate();

mnth = tmpdate.getMonth();

dy = dy + 10;

mnth = mnth + 1;

tmpdate.setDate(dy);

tmpdate.setMonth(mnth);

tmpdate = GetFirstMondayOfMonth(tmpdate);

dy = tmpdate.getDate();

if (dy ==1)

	{

	mnth = tmpdate.getMonth();

	yr = tmpdate.getYear();

		if (mnth == 2 ) 

		{

			num = daysInFebruary (yr);

			mnth = mnth-1;	

			tmpdate.setDate(num);

			tmpdate.setDate(mnth);

		}

		else   if ((mnth==1) || (mnth == 3) || (mnth == 5) || (mnth == 7) || (mnth==8) || (mnth == 10) || (mnth ==12)) 

		{

			mnth = mnth-1;	

			tmpdate.setDate(31);

			tmpdate.setDate(mnth);

		}

		else 

		{

		mnth = mnth-1;	

		tmpdate.setDate(30);

		tmpdate.setDate(mnth);

		}

	return tmpdate;

	}

else{

dy = dy-1;

tmpdate.setDate(dy);

return tmpdate;

}	

}

function isHoliday(cdate)

{

cmpdate = new Date(cdate);

var hyear = cmpdate.getYear();

var hmnth = cmpdate.getMonth();

var hday = cmpdate.getDate();



if (hmnth == 1 )

	{

	var newYearsDay = new date(hyear,1,1);

	

	if ( newYearsDay.equals(cdate) == true) 

		{

		return true;

		}

	if ( isWeekEnd(newYearsDay) == true) 

		{

		while (isWeekEnd(newYearsDay == true))

			{

			num = newYearsDay.getDate()+1;

			newYearsDay.setDate(num);

			}

		if (newYearsDay.equals(cdate) == true) 

			{

			return true;

			}

		}

	}

	

	

var easterday = new Date(dateEaster(hyear));

num = easterday.getDate()-2;	

easterday.setDate(num);

if (easterday.equals(cdate)) 

		{

		return true;

		}



if (hmnth == 5) 

	{

	victoriaDay = new Date(hyear/5/31);

	

	if ( victoriaDate.getDay() == 1)

		{

		num = victoria.getDate()-7;

		victoriaDay.setDate(num);

		if ( victoriaDay.equals(cdate))

			{

			return true;

			}

		}

	while ( victoriaDay.getDay() != 1)

		{

		num = victoriaDay.getDate()-1;

		victoriaDay.setDate(num);

		}

	num = victoriaDay.getDate()-7;

	victoriaDay.setDate(num);

	if ( victoriaDay.equals(cdate)) 

		{

		return true;

		}	

}	





if (hmnth == 7)

	{

	var canadaday = new Date(hyear,1,1);

	if (canadaday.getDay() == 6 )

		{

		num = canadaday.getDate()+2;

		canadaday.setDate(num);

		if (canadaday.equals(cdate))

			{

			return true;

			}

		}

	if (canadaday.getDay() == 0 )

		{

		num = canadaday.getDate()+1;

		canadaday.setDate(num);

		if (canadaday.equals(cdate))

			{

			return true;

			}

		}

	if (canadaday.equals(cdate))

		{

		return true;

		}

	}





if (hmnth == 8) 

	{

	var civicday = new Date(hyear, 8, 15);

	civicday = getFirstMondayOfMonth(civicday);

	if (civicday.equals(cdate))

		{

		return true;

		}

	}





if (hmnth == 9)

	{

	var labourday = new Date(hyear,9,15);

	labourday = getFirstMondayOfMonth(labourday);

	if ( labourday.equals(cdate))

		{

		return true;

		}

	}





if ( hmnth == 10)

	{

	var turkeyday = new Date(hyear, 10,15);

	turkeyday = getFirstMondayOfMonth(turkeyday);

	num = turkeyday.getDate()+7;

	turkeyday.setDate(num);

	if ( turkeyday.equals(cdate))

		{

		return true;

		}

	}





if ( hmnth == 11)

	{

	var rememberday = new Date(hyear,11,11);

	if (rememberday.getDay() == 6)

		{

		num = rememberday.getDate()+2;

		rememberday.setDate(num);

		if ( rememberday.equals(cdate))

			{

			return true;

			}

		}

	if (rememberday.getDay() == 0 )

		{

		num = rememberday.getDate()+1;

		rememberday.setDate(num);

		if ( rememberday.equals(cdate))

			{

			return true;

			}

		}

	if (rememberday.equals(cdate))

		{

		return true;

		}

	}





if ( hmnth == 12)

	{

	var presentday = new Date(hyear,12,25);

	var boxingday = new Date(hyear,12,26);

	if (presentday.getDay() == 6)

		{

		num = presentday.getDate()+2;

		num2 = boxingday.getDate()+2;

		presentday.setDate(num);

		boxingday.setDate(num2);

		if ( presentday.equals(cdate))

			{

			return true;

			}

		if ( boxingday.equals(cdate))

			{

			return true;

			}

		}

	if (presentday.getDay() == 0)

		{

		num = presentday.getDate()+1;

		num2 = boxingday.getDate()+1;

		presentday.setDate(num);

		boxingday.setDate(num2);

		if ( presentday.equals(cdate))

			{

			return true;

			}

		if ( boxingday.equals(cdate))

			{

			return true;

			}

		}

		if (presentday.getDay() == 5)

		{

		num2 = boxingday.getDate()+2;

		boxingday.setDate(num2);

		if ( presentday.equals(cdate))

			{

			return true;

			}

		if ( boxingday.equals(cdate))

			{

			return true;

			}

		}

	if ( presentday.equals(cdate))

		{

		return true;

		}

	if ( boxingday.equals(cdate))

		{

		return true;

		}

	}

}

Subject: Javascript Date / boolean isBusinessDay

Just change if (easterday.equals(cdate))

to

if( easterday.getTime() == cdate.getTime())

HTH

Adi

Subject: RE: Javascript Date / boolean isBusinessDay

Thanks Adi, that rectified that issue.

I was having an issue that the date is returning 69/11/31 no matter what cdate is being passed into the isHoliday function.

Could someone point me in the right direction here, the code is;

function isHoliday(cdate)

{

cmpdate = new Date(cdate);

var hyear = cmpdate.getYear();

var hmnth = cmpdate.getMonth();

var hday = cmpdate.getDate();

alert(hyear + “/” + hmnth + “/” + hday );

Do I need to clone the date instead of initializing it as above?

Subject: RE: Javascript Date / boolean isBusinessDay

function isHoliday(cdate) { var hyear = cdate.getYear();

var hmnth = cdate.getMonth();

var hday = cdate.getDate();

alert(hyear + “/” + hmnth + “/” + hday );

}

or

function isHoliday(cdate) {

cmpdate = new Date(cdate.getTime();

var hyear = cmpdate.getYear();

var hmnth = cmpdate.getMonth();

var hday = cmpdate.getDate();

alert(hyear + “/” + hmnth + “/” + hday );

}

Note: The input parameter ‘cdate’ must be a valid Javascript Date.

HTH

Adi

Subject: RE: Javascript Date / boolean isBusinessDay

Thanks again Adi, but it looks like I was screwing up elsewhere. and that was causing my issues…

when I was intializing the cdate object(since I have corrected my blatent error of not having a valid javascript date being passed in) I am being returned with a month 1 less then the month I entered in as a string for example;

var fdate = new Date(strMonth +“/”+ strDay +“/”+ strYear);

returns 0/1/2006 when I strMonth = 1…

Anythoughts on this one?

Once this is corrected, I can continue to pass a date object through-out the rest of the functions with out issue.

Subject: RE: Javascript Date / boolean isBusinessDay

Ken,Javascript Date.getMonth() returns the value in the range of 0-11(January = 0). so add 1 to that, to get correct format.

Can i ask you one thing: What are you trying to acheive?.

Adi

Subject: RE: Javascript Date / boolean isBusinessDay

In the end I want a group of functions that will allow me to verify if a selected date in a form is a legal Business day in Ontario. If it is not I want to return false…

My Java skills are a little rusty, so I am having a bit of a challenge getting back into it…

I do have another question for you or anyone;

when I call one of my functions I keep receiving a “Object expected error”

The call is written as follows;

if ( hmnth == 10)

	{

	var tday = new Date("10/15/"+ hyear);

	turkeyday = getFirstMondayOfMonth(tday).getTime();

	num = turkeyday.getDate()+7;

	turkeyday.setDate(num);

	if (turkeyDay.getTime() == cdate.getTime()) 

		{

		return true;

		}

	}

This block of code should goto the function getFirstMondayOfMonth and return a Date object. as shown below;

function getFirstDayOfMonth(cdate)

{

var mon, da, rflag = "false" ;

cmpdate = new Date(cdate.getTime());

while ( rflag != "true" )

	{	

	if ( cmpdate.getDay() == 0 && cmpdate.getDate() <= 6) 

		{

		num = cmpdate.getDate()-10;

		cmpdate.setDate(num);

		}

	else if ( cmpdate.getDay() == 1 && cmpdate.getDate() <= 7 )

		{

		return cmpdate;

		rflag = "true";

		}

	else if ( cmpdate.getDay() > 1 && cmpdate.getDate() < 6)

		{

		num2 = cmpdate.getMonth();

		cmpdate.setDate(15);

		cmpdate.setMonth(num2);

		}

	else if (cmpdate.getDay() != 1 && cmpdate.getDate() <= 7)

		{

		While (cmpdate.GetDay() != 1)

			{

			num = cmpdate.getDate()-1;

			cmpdate.setDate(num);

			}

alert(cmpdate.toLocaleString());

		return cmpdate;

		rflag - "true"

		}

	}

}

Again thanks for all the help so far Adi

Subject: RE: Javascript Date / boolean isBusinessDay

I am indeed a JackXXX as obviously a function has to have the same name as how you are calling it…

Thanks… I’ll post all the code once I am done error checking.

Subject: Javascript isBusinessDay - Canadian Holidays

function isBusinessDay(cdate){

fdate = new Date(cdate);

if ( isWeekEnd(fdate) == true | isHoliday(fdate == true )){

return false;

}

else{

return true;

}

}

function isWeekEnd(cdate)

{

if ( fdate.getDay() == 0 | fdate.getDay() == 6)

	{

	return true;

	}

else

	{

	return false;

	}

}

function dateEaster(y) {

var cer, n, k, i, j, l, m, d;

cer = y / 100;

n = y - 19 * ( y / 19 );

k = ( cer - 17 ) / 25;

i = cer - cer / 4 - ( cer - k ) / 3 + 19 * n + 15;

i = i - 30 * ( i / 30 );

i = i - ( i / 28 ) * ( 1 - ( i / 28 ) * ( 29 / ( i + 1 ) ) * ( ( 21 - n ) / 11 ) );

j = y + y / 4 + i + 2 - cer + cer / 4;

j = j - 7 * ( j / 7 );

l = i - j;

m = 3 + ( l + 40 ) / 44;

d = l + 28 - 31 * ( m / 4 );

return new Date( y, m, d );

}

function getFirstDayOfMonth(cdate)

{

var mon, da, rflag = "false" ;

cmpdate = new Date(cdate);

while ( rflag != "true" )

	{	

	if ( cmpdate.getDay() == 0 && cmpdate.getDate() <= 6) 

		{

		num = cmpdate.getDate()-10;

		cmpdate.setDate(num);

		}

	else if ( cmpdate.getDay() == 1 && cmpdate.getDate() <= 7 )

		{

		return cmpdate;

		rflag = "true";

		}

	else if ( cmpdate.getDay() > 1 && cmpdate.getDate() < 6)

		{

		num = cmpdate.getDate()-10;

		cmpdate.setDate(num);

		}

	else if (cmpdate.getDay() != 1 && cmpdate.getDate() <= 7)

		{

		While (cmpdate.GetDay() != 1)

			{

			num = cmpdate.getDate()-1;

			cmpdate.setDate(num);

			}

		return cmpdate;

		rflag - "true"

		}

	}

}

function getLastSundayOfMonth(cdate){

var tmpdate, mnth, dy, num, yr;

tmpdate = GetFirstMondayOfMonth(cdate);

dy	= tmpdate.getDate();

mnth = tmpdate.getMonth();

dy = dy + 10;

mnth = mnth + 1;

tmpdate.setDate(dy);

tmpdate.setMonth(mnth);

tmpdate = GetFirstMondayOfMonth(tmpdate);

dy = tmpdate.getDate();

if (dy ==1)

	{

	mnth = tmpdate.getMonth();

	yr = tmpdate.getYear();

		if (mnth == 2 ) 

		{

			num = daysInFebruary (yr);

			mnth = mnth-1;	

			tmpdate.setDate(num);

			tmpdate.setDate(mnth);

		}

		else   if ((mnth==1) || (mnth == 3) || (mnth == 5) || (mnth == 7) || (mnth==8) || (mnth == 10) || (mnth ==12)) 

		{

			mnth = mnth-1;	

			tmpdate.setDate(31);

			tmpdate.setDate(mnth);

		}

		else 

		{

		mnth = mnth-1;	

		tmpdate.setDate(30);

		tmpdate.setDate(mnth);

		}

	return tmpdate;

	}

else{

dy = dy-1;

tmpdate.setDate(dy);

return tmpdate;

}	

}

function isHoliday(cdate)

{

cmpdate = new Date(cdate);

var cmpstr = cmpdate.strftime('%m/%d/%y');

var hyear = (Right(cmpstr,4));

var hmnth = (Left(cmpstr, instr(cmpstring,"/")-1));

var tmpstr = (Left(cmpstr, len(cmpstr)-5));

var hday = (Right(tmpstr,(len(tempstr)-instr(tmpstr,"/"))));



if (hmnth == 1 )

	{

	var newYearsDay = new date(hyear,1,1);

	

	if ( newYearsDay.equals(cdate) == true) 

		{

		return true;

		}

	if ( isWeekEnd(newYearsDay) == true) 

		{

		while (isWeekEnd(newYearsDay == true))

			{

			num = newYearsDay.getDate()+1;

			newYearsDay.setDate(num);

			}

		if (newYearsDay.equals(cdate) == true) 

			{

			return true;

			}

		}

	}

	

	

var easterday = new Date(dateEaster(hyear));

num = easterday.getDate()-2;	

easterday.setDate(num);

if (easterday.equals(cdate) == true) 

		{

		return true;

		}



if (hmnth == 5) 

	{

	victoriaDay = new Date(hyear/5/31);

	

	if ( victoriaDate.getDay() == 1)

		{

		num = victoria.getDate()-7;

		victoriaDay.setDate(num);

		if ( victoriaDay.equals(cdate))

			{

			return true;

			}

		}

	while ( victoriaDay.getDay() != 1)

		{

		num = victoriaDay.getDate()-1;

		victoriaDay.setDate(num);

		}

	num = victoriaDay.getDate()-7;

	victoriaDay.setDate(num);

	if ( victoriaDay.equals(cdate)) 

		{

		return true;

		}	

}	





if (hmnth == 7)

	{

	var canadaday = new Date(hyear,1,1);

	if (canadaday.getDay() == 6 )

		{

		num = canadaday.getDate()+2;

		canadaday.setDate(num);

		if (canadaday.equals(cdate))

			{

			return true;

			}

		}

	if (canadaday.getDay() == 0 )

		{

		num = canadaday.getDate()+1;

		canadaday.setDate(num);

		if (canadaday.equals(cdate))

			{

			return true;

			}

		}

	if (canadaday.equals(cdate))

		{

		return true;

		}

	}





if (hmnth == 8) 

	{

	var civicday = new Date(hyear, 8, 15);

	civicday = getFirstMondayOfMonth(civicday);

	if (civicday.equals(cdate))

		{

		return true;

		}

	}





if (hmnth == 9)

	{

	var labourday = new Date(hyear,9,15);

	labourday = getFirstMondayOfMonth(labourday);

	if ( labourday.equals(cdate))

		{

		return true;

		}

	}





if ( hmnth == 10)

	{

	var turkeyday = new Date(hyear, 10,15);

	turkeyday = getFirstMondayOfMonth(turkeyday);

	num = turkeyday.getDate()+7;

	turkeyday.setDate(num);

	if ( turkeyday.equals(cdate))

		{

		return true;

		}

	}





if ( hmnth == 11)

	{

	var rememberday = new Date(hyear,11,11);

	if (rememberday.getDay() == 6)

		{

		num = rememberday.getDate()+2;

		rememberday.setDate(num);

		if ( rememberday.equals(cdate))

			{

			return true;

			}

		}

	if (rememberday.getDay() == 0 )

		{

		num = rememberday.getDate()+1;

		rememberday.setDate(num);

		if ( rememberday.equals(cdate))

			{

			return true;

			}

		}

	if (rememberday.equals(cdate))

		{

		return true;

		}

	}





if ( hmnth == 12)

	{

	var presentday = new Date(hyear,12,25);

	var boxingday = new Date(hyear,12,26);

	if (presentday.getDay() == 6)

		{

		num = presentday.getDate()+2;

		num2 = boxingday.getDate()+2;

		presentday.setDate(num);

		boxingday.setDate(num2);

		if ( presentday.equals(cdate))

			{

			return true;

			}

		if ( boxingday.equals(cdate))

			{

			return true;

			}

		}

	if (presentday.getDay() == 0)

		{

		num = presentday.getDate()+1;

		num2 = boxingday.getDate()+1;

		presentday.setDate(num);

		boxingday.setDate(num2);

		if ( presentday.equals(cdate))

			{

			return true;

			}

		if ( boxingday.equals(cdate))

			{

			return true;

			}

		}

		if (presentday.getDay() == 5)

		{

		num2 = boxingday.getDate()+2;

		boxingday.setDate(num2);

		if ( presentday.equals(cdate))

			{

			return true;

			}

		if ( boxingday.equals(cdate))

			{

			return true;

			}

		}

	if ( presentday.equals(cdate))

		{

		return true;

		}

	if ( boxingday.equals(cdate))

		{

		return true;

		}

	}

}