...

View Full Version : Calendar does not display Mar 31 1968



akila76
07-15-2009, 07:33 AM
Hi,
I seem to have a very funny problem. My calendar control does not display Mar 31 for the years 1968, 1991 :confused: . There maybe a few other years where it is not being displayed, but this has been noticed.

Here is the code that we are using.



function constructCalendar () {
var dateMessage
var startDate = new Date (yearSelected,monthSelected,1)
var endDate = new Date (yearSelected,monthSelected+1,1);
endDate = new Date (endDate - (24*60*60*1000));
numDaysInMonth = endDate.getDate()

datePointer = 0
dayPointer = startDate.getDay() - startAt

if (dayPointer<0)
{
dayPointer = 6
}

sHTML = "<table border=0 class='body-style'><tr>"

if (showWeekNumber==1)
{
sHTML += "<td width=27><b>" + weekString + "</b></td><td width=1 rowspan=7 class='weeknumber-div-style'><img src='"+imgDir+"divider.gif' width=1></td>"
}

for (i=0; i<7; i++) {
sHTML += "<td width='27' align='right'><B>"+ dayName[i]+"</B></td>"
}
sHTML +="</tr><tr>"

if (showWeekNumber==1)
{
sHTML += "<td align=right>" + WeekNbr(startDate) + "&nbsp;</td>"
}

for ( var i=1; i<=dayPointer;i++ )
{
sHTML += "<td>&nbsp;</td>"
}

for ( datePointer=1; datePointer<=numDaysInMonth; datePointer++ )
{
dayPointer++;
sHTML += "<td align=right>"

var sStyle="normal-day-style"; //regular day

if ((datePointer==dateNow)&&(monthSelected==monthNow)&&(yearSelected==yearNow)) //today
{ sStyle = "current-day-style"; }
else if (dayPointer % 7 == (startAt * -1) +1) //end-of-the-week day
{ sStyle = "end-of-weekday-style"; }

//selected day
if ((datePointer==odateSelected) && (monthSelected==omonthSelected) && (yearSelected==oyearSelected))
{ sStyle += " selected-day-style"; }

sHint = ""
for (k=0;k<HolidaysCounter;k++)
{
if ((parseInt(Holidays[k].d)==datePointer)&&(parseInt(Holidays[k].m)==(monthSelected+1)))
{
if ((parseInt(Holidays[k].y)==0)||((parseInt(Holidays[k].y)==yearSelected)&&(parseInt(Holidays[k].y)!=0)))
{
sStyle += " holiday-style";
sHint+=sHint==""?Holidays[k].desc:"\n"+Holidays[k].desc
}
}
}

var regexp= /\"/g
sHint=sHint.replace(regexp,"&quot;")

dateMessage = "onmousemove='window.status=\""+selectDateMessage.replace("[date]",constructDate(datePointer,monthSelected,yearSelected))+"\"' onmouseout='window.status=\"\"' "

sHTML += "<a class='"+sStyle+"' "+dateMessage+" title=\"" + sHint + "\" href='javascript:dateSelected="+datePointer+";closeCalendar();'>&nbsp;" + datePointer + "&nbsp;</a>"

sHTML += ""
if ((dayPointer+startAt) % 7 == startAt) {
sHTML += "</tr><tr>"
if ((showWeekNumber==1)&&(datePointer<numDaysInMonth))
{
sHTML += "<td align=right>" + (WeekNbr(new Date(yearSelected,monthSelected,datePointer+1))) + "&nbsp;</td>"
}
}
}

document.getElementById("content").innerHTML = sHTML
document.getElementById("spanMonth").innerHTML = "&nbsp;" + monthName[monthSelected] + "&nbsp;<IMG id='changeMonth' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
document.getElementById("spanYear").innerHTML = "&nbsp;" + yearSelected + "&nbsp;<IMG id='changeYear' SRC='"+imgDir+"drop1.gif' WIDTH='12' HEIGHT='10' BORDER=0>"
}




Can anybody help pleease :o

The more confusing part is that, this problem does not occur in our development environment. It occurs in the user's test as well as production environment.

This is what I found:

Problem is with the statement
endDate = new Date (endDate - (24*60*60*1000));

This returns the enddate as Mar 30 for the year 1968, 1991 in client server. Whereas it returns. Mar 31 in our local server. I even tried changing the regional settings of my local machine as well as local server (db server) to the same as in our client server. But that did not help. Now I am all the more confused!!!

jmrker
07-15-2009, 08:26 PM
I'm sure those days happen or there may be several forum members who don't get to celebrate birthdays any more!

Philip M
07-15-2009, 10:11 PM
A long shot -

Comment out this line and see what happens:
endDate = new Date (endDate - (24*60*60*1000));

or change it to

endDate = new Date (endDate - (24*60*60*1000) +1);

But I don't have a clue why your problem is only Mar 31 for the years 1968 and 1991!

CFMaBiSmAd
07-15-2009, 10:20 PM
I did not read through all the code, but it sounds like you are off by one month. The months in a Date object are from 0-11. If your code is using 3 for March, that is actually April and it does not have 31 days in it.

akila76
07-16-2009, 07:18 AM
Firstly, thanks a ton for all your responses. :D

Here is my finding on this issue. When the statement

var endDate = new Date (yearSelected,monthSelected+1,1);

is executed, it returns the first day of the next month. In my case, it returns 01 April 1968 (along with the time, which is something like UTC+01.00 00.00.00)

When the next statement

endDate = new Date (endDate - (24*60*60*1000));

is executed, it returns 30 March 1968!!! So, we just lose a day for no reason. The most puzzling thing is, it works perfectly in my development system.

Obviously, here we are subtracting a day. So, I just tried

endDate = new Date (endDate - (1));

and it seems to work so far!!! But somehow, this does not seem the best way to do this!!!:(

Philip M
07-16-2009, 08:24 AM
I did not read through all the code, but it sounds like you are off by one month. The months in a Date object are from 0-11. If your code is using 3 for March, that is actually April and it does not have 31 days in it.

But why (only) 1968 and 1991? :confused::confused:

"This returns the enddate as Mar 30 for the year 1968, 1991 in client server. Whereas it returns. Mar 31 in our local server." That suggests something wrong with the client server!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum