Reply
Yearly Calendar
Old 10-15-2007, 01:00 PM Yearly Calendar
Average Talker

Posts: 20
Name: Levi
I have to make a yearly calendar for a class and I wrote the script out and I am just kind of lost with the logic I think because I'm missing something. All of my months are title December and the first day of the months don't change. Any help would be appreciated. Scroll down a bit, I added a comment in for where I started coding and where it was already given to me.

Code:
function writeMonth(calendarDay, currentTime) {
   document.write("<table class='monthly_table'>");
   writeMonthTitle(calendarDay);
   writeDayNames()
   writeMonthDays(calendarDay, currentTime);
   document.write("</table>");
}

function writeMonthTitle(calendarDay) {
   var monthName = new Array("January", "February", "March", "April", "May", 
   "June", "July", "August", "September", "October", "November", "December");

   var thisMonth=calendarDay.getMonth();

   document.write("<tr>");
   document.write("<th class='monthly_title' colspan='7'>");
   document.write(monthName[thisMonth]);
   document.write("</th>");
   document.write("</tr>");
}

function writeDayNames() {
   var dayName = new Array("S","M","T","W","T","F","S");  
   document.write("<tr>");
   for (var i=0;i<dayName.length;i++) {
      document.write("<th class='monthly_weekdays'>"+dayName[i]+"</th>");
   }
   document.write("</tr>");
}

function daysInMonth(calendarDay) {
   var thisYear = calendarDay.getFullYear();
   var thisMonth = calendarDay.getMonth();
   var dayCount = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
   if ((thisYear % 4 == 0)&&((thisYear % 100 !=0) || (thisYear % 400 == 0))) {
         dayCount[1] = 29;
   }
   return dayCount[thisMonth];
}

function writeMonthDays(calendarDay, currentTime) {

   var weekDay = calendarDay.getDay();

   document.write("<tr>");
   for (var i=0; i < weekDay; i++) {
      document.write("<td></td>");
   }

   var totalDays = daysInMonth(calendarDay);
   for (var dayCount=1; dayCount<=totalDays; dayCount++) {

      calendarDay.setDate(dayCount);
      weekDay = calendarDay.getDay();
      writeDay(weekDay, dayCount, calendarDay, currentTime);
   }
   
   document.write("</tr>");
}

function writeDay(weekDay, dayCount, calendarDay, currentTime) {
   if (weekDay == 0) document.write("<tr>");
   if (calendarDay.getTime() == currentTime) {
      document.write("<td class='monthly_dates' id='today'>"+dayCount+"</td>");
   } else {
      document.write("<td class='monthly_dates'>"+dayCount+"</td>");
   }
   if (weekDay == 6) document.write("</tr>");
}

// Begin Assignment, Everything above this was given to me so I assume its right?

function writeMonthCell(calendarDay, currentTime)
{
    document.write("<td class=\"yearly_months\">");
    writeMonth(calendarDay, currentTime);
    document.write("</td>");
}

function yearly(calDate)
{
            if (calDate == null)
            {
                calendarDay = new Date();
            }
            else 
            {
                calendarDay ="";
          }
    var currentTime = calendarDay.getTime();
    var thisYear = calendarDay.getFullYear();
    
    document.write("<table id=\"yearly_table\">");
    document.write("<tr>");
    document.write("<th id=\"yearly_title\" colspan=\"4\">");
    document.write("</th>");
    document.write("</tr>");

var monthNum = (-1);

for (i=1; i<4; i++)
{
document.write("<tr>");

                for (j=1; j<5; j++)
                {
                    document.write("<td>");
                    monthNum = monthNum++;
                    calendarDay.setTime(1);
                    calendarDay.setMonth(monthNum);
                    writeMonthCell(calendarDay, currentTime);
                    document.write("</td>");
                }
                
document.write("</tr>");
}

document.write("</table>");
}
Levi_ is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 10-19-2007, 10:27 PM Re: Yearly Calendar
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
Replace

HTML Code:
monthNum = monthNum++;
with

HTML Code:
monthNum++;
You have another problem with the wrapping of the calendar, but this will get you started.

Also, this code was very hard to follow. You may want to consider not having your functions setup so that you have to go 4 levels deep just to get the title of the month.
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Old 10-19-2007, 10:59 PM Re: Yearly Calendar
JeremyMiller's Avatar
Full-Time TeraTasker

Posts: 984
Name: Jeremy Miller
Location: Reno, NV
I wrote this to help you:

HTML Code:
<script>
    function calendarYear(this_year) {      
      if (this_year == null) {
        this_year_date = new Date();
        this_year = this_year_date.getYear();
      }
      
      months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
      weekdays = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
      
      for (this_month=0;this_month < 12;this_month++) {
        calendar_month = new Date(this_year, this_month, 1, 1, 0, 0, 0);
        
        days_in_month_date = new Date(this_year, this_month+1, 1, 1, 0, 0, 0);
        days_in_month = new Date(days_in_month_date.getTime() - 5*60*60*1000);
        
        document.write('<table class="calendar_month" border="1">');
        document.write('<tr><th colspan="7" align="center">'+months[this_month]+' '+calendar_month.getFullYear()+'</th></tr>');
        document.write('<tr><th>Sunday</th><th>Monday</th><th>Tuesday</th><th>Wednesday</th><th>Thursday</th><th>Friday</th><th>Saturday</th></tr>');
        
        current_weekday=0;
        for (day_of_month=1;day_of_month<=days_in_month.getDate();day_of_month++) {
          if ((day_of_month+calendar_month.getDay()-1)%7 == 0) {
            document.write('<tr>');
          }
          if (day_of_month == 1 && current_weekday < calendar_month.getDay()) {
            for (empty_cells=0;empty_cells < calendar_month.getDay();empty_cells++) {
              document.write('<td>&nbsp;</td>');
              current_weekday++;
            }
          }
          document.write('<td>'+day_of_month+'</td>');
          if ((day_of_month+calendar_month.getDay())%7 == 0) {
            document.write('</tr>');
          }
          
        }
        document.write('</table>');
      }
    }
    calendarYear(2007);
    </script>
__________________
Jeremy Miller - TeraTask Technologies, LLC
Content Farmer - Automated Posting for Content & Blog Sites
JeremyMiller is offline
Reply With Quote
View Public Profile Visit JeremyMiller's homepage!
 
Reply     « Reply to Yearly Calendar
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.12615 seconds with 12 queries