Jump to content

Javascript Calendar problem

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Olain

Olain

    Newbie

  • Members
  • Pip
  • 5 posts
Hello there ! Nice website!

I've been having a problem with a calendar a friends of mine made for me. I cannot seem to figure out what the parameters stands for. Could anyone please help? I would be very happy :)

----------------------------------------------------------------

function buildCal(m, y, cM, cH, cDW, cD, brdr){
var mn=['January','February','March','April','May','June','July','August','September','October','November','December'];
var dim=[31,0,31,30,31,30,31,31,30,31,30,31];

var oD = new Date(y, m-1, 1);
oD.od=oD.getDay()+1;

var todaydate=new Date() //DD added
var scanfortoday=(y==todaydate.getFullYear() && m==todaydate.getMonth()+1)? todaydate.getDate() : 0 //DD added

dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28;
var t='<div class="'+cM+'"><table class="'+cM+'" cols="7" cellpadding="0" border="'+brdr+'" cellspacing="0"><tr align="center">';
t+='<td colspan="7" align="center" class="'+cH+'">'+mn[m-1]+' - '+y+'</td></tr><tr align="center">';
for(s=0;s<7;s++)t+='<td class="'+cDW+'">'+"SMTWTFS".substr(s,1)+'</td>';
t+='</tr><tr align="center">';
for(i=1;i<=42;i++){
var x=((i-oD.od>=0)&&(i-oD.od<dim[m-1]))? i-oD.od+1 : ' ';
if (x==scanfortoday) //DD added
x='<span id="today">'+x+'</span>' //DD added
t+='<td class="'+cD+'">'+x+'</td>';
if(((i)%7==0)&&(i<36))t+='</tr><tr align="center">';
}
return t+='</tr></table></div>';
}

---------------------------------------------------------------

Anyone?

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
That was not too hard to look through (it is simpler than you think if you look where the variables are. The prototype would be like this:
buildCal(month, year, classname, classname, classname, classname , borderwidth);

classnames being class names for the table (like <table class="...">) , td, span (you can see where they are to find what you want to edit);
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
Olain

Olain

    Newbie

  • Members
  • Pip
  • 5 posts
Thanks for the reply Alexander - The problem is the codes inside the script.. I dont get what: dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28; - Means, as i dont know what oD and % and ? is doing in there.. This code is mean to me to: oD.od=oD.getDay()+1; I dont get it.

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
oD appears to be the date object, oD.od appears to be the day of the date, but + 1 days.

% is the modulus operator, 5 % 4 = 1 as 1 is the remainder of 5 / 4.

? and : are ternary operators, think of IF statements

If(name == 'John') {
   age = 23;
} else {
   age = 0;
}
Can be written as:
age = (name == 'John') ? 23 : 0;
This code is very poorly written, so I do not blame you for not getting what it does.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Olain said:

Thanks for the reply Alexander - The problem is the codes inside the script.. I dont get what: dim[1]=(((oD.getFullYear()%100!=0)&&(oD.getFullYear()%4==0))||(oD.getFullYear()%400==0))?29:28; - Means, as i dont know what oD and % and ? is doing in there.. This code is mean to me to: oD.od=oD.getDay()+1; I dont get it.

That first line calculates number of days in February, whether it is a leap year or not
dim[1] means it addresses the second post in dim variable, and if you look at it above in your code, it keeps number of days in each month, but February is set to 0, as its recalculated with this line.
The rules of whether there is a leap year or not is if it's evenly dividable with four, but not if it's evenly dividable with 100, but it is if it's evenly dividable with 400
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users