Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calendar does not display Mar 31 1968

    Hi,
    I seem to have a very funny problem. My calendar control does not display Mar 31 for the years 1968, 1991 . 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.

    Code:
    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

    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!!!
    Last edited by Kor; 07-15-2009 at 10:22 AM. Reason: wrap the code [code][/code]

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,075
    Thanks
    38
    Thanked 498 Times in 492 Posts
    I'm sure those days happen or there may be several forum members who don't get to celebrate birthdays any more!

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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!

  • #4
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,026
    Thanks
    2
    Thanked 315 Times in 307 Posts
    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.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #5
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Firstly, thanks a ton for all your responses.

    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!!!

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    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?

    "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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •