diff --git a/calendar/generate_lecturedates.php b/calendar/generate_lecturedates.php new file mode 100755 index 0000000..f39e81d --- /dev/null +++ b/calendar/generate_lecturedates.php @@ -0,0 +1,102 @@ + array( + new DateTime( "2012-02-27" ), + new DateTime( "2012-04-02" ), + new DateTime( "2012-07-09" ), + new DateTime( "2012-09-03" ), + ); + + $period_lengths + A list of integers representing the length in weeks of each period + specifed in $start_dates. Both $start_dates and $period_lengths must + therefore have the same length! + + Example (INFO 405 2012): + + $period_lengths => array( 6, 7, 7, 6 ); + + $class_offsets: + For each class in a week, specify the offset interval from the start + of week (Monday). Thus, a class on Monday will be 'P0D', Wednesday + 'P2D', Friday 'P4D', etc. Include as many entries in the list as there + are classes per week (e.g., two lectures => two entries). + + Example (INFO 405 2012, one lecture per week, on Monday): + + $class_offsets => array( + new DateInterval( 'P0D' ), + ); +*/ +include( 'lecturedates_config.php' ); + +$numwords = new Numbers_Words(); + +// A handy date interval: seven days to the start of next week. +$plus_seven_days = new DateInterval( 'P7D' ); + +$week_num = 1; + +for ( $period = 0; $period < count( $start_dates ); $period++ ) +{ + $period_start = $start_dates[$period]; + $week_start = clone( $start_dates[$period] ); + + for ( $week = 0; $week < $period_lengths[$period]; $week++ ) + { + $lecture_num = 1; + + foreach ( $class_offsets as $class ) + { + $class_date = clone( $week_start ); + $class_date->add( $class ); + + // Note that the toWords() method generates hyphens in the result, + // so we need to strip these out for LaTeX to be happy. Larger + // numbers may well include spaces and commas, but it's pretty + // unlikely that we'll ever get that high! + printf( "\\newcommand{\\DateWeek%sLecture%s}{%s}\n", + ucfirst( str_replace( '-', '', $numwords->toWords( $week_num ) ) ), + ucfirst( str_replace( '-', '', $numwords->toWords( $lecture_num ) ) ), + $class_date->format( 'j F' ) + ); + $lecture_num++; + } // for every class in week + + $week_start->add( $plus_seven_days ); + $week_num++; + } // for every week in period +} // for every period