/////////////////////////////////////////////////////////////////////////////////////////// // // Program : diary.js // Purpose : To provide an events diary where only today and future events are displayed to // reduce the update time required. Translates dates into standard format // e.g. Friday 15 February 2002. // Author : Greg Griffiths (greg.griffiths@greggriffiths.org) // Version : 1.0 // Release Date : 15 February 2002 // URL : http://www.greggriffiths.org/webdev/clientside/javascript/eventsdiary/ // // © Copyright : Greg Griffiths (2002) // // This Javascript script is for freeware use, however, the owner would appreciate a mention on the // users site including a link back to his site as well as being told where his code is being used. // /////////////////////////////////////////////////////////////////////////////////////////// // Object constructor function eventInfo(day, month, year, time, event) { this.day = day; this.month = month; this.year = year; this.time = time; this.event = event; } // this function builds the table component of the page function display_diary() { var eventDiary = new Array(); var today = new Date(); var aday; var amonth; var ayear; var printit; var bgcol; // set other local variables aday = today.getDate(); amonth = today.getMonth() + 1; ayear = today.getFullYear(); bgcol="#CCCCCC"; // this is the diary, one row per event, remember that the first row must be eventDiary[0] eventDiary[0] = new eventInfo("17","02","2002","10:30","Rev John Perkins (Holy Communion)"); eventDiary[1] = new eventInfo("17","02","2002","6:30","Mr Tom Parkinson"); eventDiary[2] = new eventInfo("24","02","2002","10:30","Mrs Ann Parkinson"); eventDiary[3] = new eventInfo("24","02","2002","6:30","Mr J Scott"); eventDiary[4] = new eventInfo("03","03","2002","10:30","Mr J Whitehead"); eventDiary[5] = new eventInfo("03","03","2002","2:30","Circuit Service at Kniveton Rev Trevor Staniforth"); eventDiary[6] = new eventInfo("10","03","2002","10:30","Miss Diana Whitmill"); eventDiary[7] = new eventInfo("10","03","2002","6:30","Sister Merle Wilde"); eventDiary[8] = new eventInfo("17","03","2002","10:30","Rev Trevor Staniforth"); eventDiary[9] = new eventInfo("17","03","2002","6:30","Mrs S Massey"); eventDiary[10] = new eventInfo("24","03","2002","10:30","Mr John Turner"); eventDiary[11] = new eventInfo("24","03","2002","6:30","Rev K Cupit"); eventDiary[12] = new eventInfo("29","03","2002","11.00","Mr Tim Dutton"); eventDiary[13] = new eventInfo("29","03","2002","12:30","ACT Walk of Witness, Victoria Square"); eventDiary[14] = new eventInfo("30","03","2002"," ","Milldale Walk"); eventDiary[15] = new eventInfo("30","07","2002","2:30","Service at Milldale - Rev Trevor Staniforth"); eventDiary[16] = new eventInfo("31","08","2002","8.00","Rev John Perkins"); eventDiary[17] = new eventInfo("31","09","2002","10:30","Rev Wesley Blakey"); eventDiary[18] = new eventInfo("31","10","2002","6:30","Mr John Turner"); // set a local variable equal to the length of the array var maxEntries=eventDiary.length; // print out the header document.write(""); document.write("") // check to see if the row shold be printed. for (i=0;i=ayear) { // if the year in the Plan is equal to the current year if (eventDiary[i].year==ayear) { // is the month in the Plan greater than or equal to the current month if (eventDiary[i].month==amonth) { if (aday>eventDiary[i].day) { printit=0; } else { printit=1; } } else { if (eventDiary[i].month>amonth) { printit=1; } else { printit=0; } } } else { printit=1; } } else { printit=0; } // if the row should be printed if (printit==1) { // build a date var myDate = new Date (eventDiary[i].year,eventDiary[i].month,eventDiary[i].day); whichDay = myDate.getDay(); // convert the day value to a proper day value switch (whichDay) { case 0: whichDayName="Sunday"; break; case 1: whichDayName="Monday"; break; case 2: whichDayName="Tuesday"; break; case 3: whichDayName="Wednesday"; break; case 4: whichDayName="Thursday"; break; case 5: whichDayName="Friday"; break; case 6: whichDayName="Saturday"; break; } // convert the month value to a proper month value whichMonth = myDate.getMonth(); switch(whichMonth) { case 0: whichMonthName="January"; break; case 1: whichMonthName="February"; break; case 2: whichMonthName="March"; break; case 3: whichMonthName="April"; break; case 4: whichMonthName="May"; break; case 5: whichMonthName="June"; break; case 6: whichMonthName="July"; break; case 7: whichMonthName="August"; break; case 8: whichMonthName="September"; break; case 9: whichMonthName="October"; break; case 10: whichMonthName="November"; break; case 11: whichMonthName="December"; break; } document.write("") // change bgcol if (bgcol=="#CCCCCC") { bgcol="white"; } else { bgcol="#CCCCCC"; } } } // close the table document.write("
DateTimeEvent
" + whichDayName + " " + eventDiary[i].day + " " + whichMonthName + " " + eventDiary[i].year + "" + eventDiary[i].time + "" + eventDiary[i].event + "
"); }