function classSchedule(startday,startmonth,endday,endmonth,weekdays,startYear,endYear, specialDays) % Create schedule.html which contains a class calendar % % startday (integer) The first day of classes (e.g. 9) % startmonth (string) The first month of classes (e.g. 'Sep') % endday (integer) The last day of classes( e.g. 27) % endmonth (string) The last month of classes( e.g. 'Nov') % weekdays (cell array) The days of the week the class is on, (e.g. {'Tue','Thu'}) % Must use 3 letter abbreviations! % % OPTIONAL % % startYear (integer)[default = current year] optional start year e.g. 2008 % endYear (integer)[default = current year] optional end year e.g. 2008 % specialDays cell array of cell arrays, % specialDays{i} should have form {month, date range, string} % Prints this string on any matching date eg for holidays or exams % % EXAMPLES % % classSchedule(9,'Sep',27,'Nov',{'Tue','Thu'}); % classSchedule(4,'Jan',15,'Apr',{'Tue','Thu'},2010,2010, ... % { {'Feb',15:26, 'olympics'}, {'Apr', 2, 'Good Friday'} } ); % Written by Matt Dunham and Kevin Murphy, 15 December 2009 if nargin < 8 specialDays = {}; end specialDaysHT = containers.Map; % hash table for i=1:length(specialDays) month = specialDays{i}{1}; days = specialDays{i}{2}; % could be a vector of numbers str = specialDays{i}{3}; for j=1:length(days) key = sprintf('%s-%d', month, days(j)); specialDaysHT(key) = str; end end months = {'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'}; days = {'Sun','Mon','Tue','Wed','Thu','Fri','Sat'}; import java.util.*; cal = GregorianCalendar(TimeZone.getTimeZone('Canada/Pacific')); cal.set(Calendar.DAY_OF_MONTH,startday) if(ischar(startmonth)) startmonth = find(strcmpi(startmonth,months)); end cal.set(Calendar.MONTH,startmonth-1); if(ischar(endmonth)) endmonth = find(strcmpi(endmonth,months)); end lastDay = GregorianCalendar(TimeZone.getTimeZone('Canada/Pacific')); lastDay.set(Calendar.DAY_OF_MONTH,endday); lastDay.set(Calendar.MONTH,endmonth-1); if(nargin > 5) cal.set(Calendar.YEAR,startYear); lastDay.set(Calendar.YEAR,endYear); end lecID = 0; fid = fopen('schedule.html','w'); writeHeader(fid); while(true) if(cal.compareTo(lastDay) > 0) break; end dayOfWeek = days{cal.get(Calendar.DAY_OF_WEEK)}; if(ismember(dayOfWeek,weekdays)) lecID = lecID + 1; month = months{cal.get(Calendar.MONTH) + 1}; dom = cal.get(Calendar.DAY_OF_MONTH); key = sprintf('%s-%d', month, dom); if isKey(specialDaysHT, key) topic = specialDaysHT(key); else topic = []; end writeEntry(dayOfWeek,month,dom,lecID, topic); end cal.add(Calendar.DAY_OF_YEAR,1) end writeFooter(fid); fclose(fid); fprintf('\ntext written to schedule.html successfully\n'); function writeEntry(weekday,month,day,lecID, slides) fprintf(fid,'\n'); fprintf(fid,'\n'); fprintf(fid,'L%d\n',lecID); fprintf(fid,' %s %s %d
\n',weekday,month,day); if isempty(slides) fprintf(fid,' . \n'); else fprintf(fid,' %s \n', slides); end fprintf(fid,' . \n'); fprintf(fid,'.\n'); fprintf(fid,'\n'); end function writeHeader(fid) lines = {'', ... '', ... '', ... '', ... '', ... '', ... '', ... ''}; for i=1:length(lines) fprintf(fid, '%s\n', lines{i}); end end function writeFooter(fid) fprintf(fid, '
L#DateSlidesReadingHomework
\n'); end end