diff --git a/calendar/generate_calendar.php b/calendar/generate_calendar.php new file mode 100755 index 0000000..bf2894c --- /dev/null +++ b/calendar/generate_calendar.php @@ -0,0 +1,121 @@ + array( + 'start_date' => new DateTime( "2012-01-09" ), + 'num_weeks' => 6, + 'break_week' => 9999, + ), + "SemesterOne" => array( + 'start_date' => new DateTime( "2012-02-27" ), + 'num_weeks' => 14, + 'break_week' => 7, + ), + "SemesterTwo" => array( + 'start_date' => new DateTime( "2012-07-09" ), + 'num_weeks' => 14, + 'break_week' => 8, + ), +); + +// A couple of handy date intervals: four days to the end of the current week, +// and seven days to the start of next week. +$plus_four_days = new DateInterval( 'P4D' ); +$plus_seven_days = new DateInterval( 'P7D' ); + +$numwords = new Numbers_Words(); + +foreach ( $periods as $period_name => $period_data ) +{ + $week_start = clone( $period_data['start_date'] ); + + for ( $week = 1; $week <= $period_data['num_weeks']; $week++ ) + { + $week_end = clone( $week_start ); + $week_end->add( $plus_four_days ); + + // If the week start and end dates are in the same month, we only + // need to output the month name once. + $same_month = $week_start->format( 'n' ) == $week_end->format( 'n' ); + + // Handle break weeks. + if ( $week == $period_data['break_week'] ) + { + printf( "\\newcommand{\\%sMidSemesterBreak}{%s--%s}\n", + $period_name, + ( $same_month ) ? $week_start->format( 'j' ) : $week_start->format( 'j M' ), + $week_end->format( 'j M' ) + ); + } // 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; + + if( $same_month ) + { + printf( "\\newcommand{\\%sWeek%s}{%s--%s \\\\ %s}\n", + $period_name, + ucfirst( $numwords->toWords( $week_number ) ), + $week_start->format( 'j' ), + $week_end->format( 'j' ), + $week_end->format( 'M' ) + ); + } // if same month + else + { + printf( "\\newcommand{\\%sWeek%s}{%s \\\\ --%s}\n", + $period_name, + ucfirst( $numwords->toWords( $week_number ) ), + $week_start->format( 'j M' ), + $week_end->format( 'j M' ) + ); + } // else different months + } // else normal teaching week + + $week_start->add( $plus_seven_days ); + } // for each week +} // foreach teaching period + +?>