diff --git a/calendar/generate_calendar.php b/calendar/generate_calendar.php index bf2894c..3b341f4 100755 --- a/calendar/generate_calendar.php +++ b/calendar/generate_calendar.php @@ -7,8 +7,8 @@ the date ranges for every week of the three main teaching periods through the year (i.e., summer school, first semester, second semester). Simply set the configuration as outlined below and run the script, saving the output - in a suitable location (ideally only once for all papers, perhaps in - $ALL_PAPERS_ROOT?). + in a suitable location, ideally only once for all papers. A good spot would + be somewhere in the TeX search path. */ // LaTeX macro names can't include numbers, so we have to convert them to words. @@ -26,35 +26,36 @@ breaks (e.g., 13 teaching weeks plus 1 week mid-semester break = 14 weeks). - break_week: The week number that the break (if any) falls in, relative - to num_weeks, so if the break week falls after the sixth - teaching week, then set this to 7. The numbering of teaching - weeks will skip the break week regardless. If there is no - break in the period, then set this to a number larger than - num_weeks. + break_week: A list of week numbers in which breaks from teaching occur. + The list should ideally be in ascending order, but the + script doesn't assume this and sorts the list anyway. The + week number of a break is relative to num_weeks, so if a + break week falls after the sixth then that week is week + number 7. The numbering of teaching weeks will skip the + break weeks regardless. If there are no breaks in the + period, then set this to null. - Note that this currently only supports a single, one week - break per period. Generalising the configuration to - multiple/longer breaks probably isn't that difficult if - needed (a list of week numbers instead of a single value - should cater for all cases). Setting up the LaTeX macros - and teaching week numbering could be tricky, though. + Note that we aren't clever about coalescing contiguous + weeks. For example, if weeks 7 and 8 are indicated as break + weeks, a separate macro will be output for each weak, not + one covering both weeks. It's probably technically feasible, + but not really worth the extra work :). */ $periods = array( 'SummerSchool' => array( - 'start_date' => new DateTime( "2012-01-09" ), - 'num_weeks' => 6, - 'break_week' => 9999, + 'start_date' => new DateTime( "2012-01-09" ), + 'num_weeks' => 6, + 'break_weeks' => null, ), - "SemesterOne" => array( - 'start_date' => new DateTime( "2012-02-27" ), - 'num_weeks' => 14, - 'break_week' => 7, + 'SemesterOne' => array( + 'start_date' => new DateTime( "2012-02-27" ), + 'num_weeks' => 14, + 'break_weeks' => array( 7 ), ), - "SemesterTwo" => array( - 'start_date' => new DateTime( "2012-07-09" ), - 'num_weeks' => 14, - 'break_week' => 8, + 'SemesterTwo' => array( + 'start_date' => new DateTime( "2012-07-09" ), + 'num_weeks' => 14, + 'break_weeks' => array( 8 ), ), ); @@ -69,6 +70,15 @@ { $week_start = clone( $period_data['start_date'] ); + // We need to adjust the teaching week number according to the number + // of break weeks that we've processed. $break_adjustment therefore + // effectively stores the count of break weeks processed so far. + $break_adjustment = 0; + + // Grab the first break week off the front of the list. + sort( $period_data['break_weeks'] ); + $break_week = array_shift( $period_data['break_weeks'] ); + for ( $week = 1; $week <= $period_data['num_weeks']; $week++ ) { $week_end = clone( $week_start ); @@ -79,22 +89,31 @@ $same_month = $week_start->format( 'n' ) == $week_end->format( 'n' ); // Handle break weeks. - if ( $week == $period_data['break_week'] ) + if ( $week == $break_week ) { - printf( "\\newcommand{\\%sMidSemesterBreak}{%s--%s}\n", + // Increment this first before doing anything else, because we use + // it to generate a macro name for this break, and we want the + // macro numbering to start from one, not zero. + $break_adjustment++; + + // Output macro for inclusion in paper calendar. + printf( "\\newcommand{\\%sBreak%s}{%s--%s}\n", $period_name, + ucfirst( $numwords->toWords( $break_adjustment ) ), ( $same_month ) ? $week_start->format( 'j' ) : $week_start->format( 'j M' ), $week_end->format( 'j M' ) ); + + // Grab the next break week off the front of the list. + $break_week = array_shift( $period_data['break_weeks'] ); } // if break week else { - // If we've passed the break week, then we need to subtract one from - // the week count to get the correct teaching week number. - $week_number = ( $week > $period_data['break_week'] ) ? $week - 1 : $week; + $week_number = $week - $break_adjustment; if( $same_month ) { + // Output macro for inclusion in paper calendar. printf( "\\newcommand{\\%sWeek%s}{%s--%s \\\\ %s}\n", $period_name, ucfirst( $numwords->toWords( $week_number ) ), @@ -105,6 +124,7 @@ } // if same month else { + // Output macro for inclusion in paper calendar. printf( "\\newcommand{\\%sWeek%s}{%s \\\\ --%s}\n", $period_name, ucfirst( $numwords->toWords( $week_number ) ),