コード例 #1
0
 /**
  * @brief Perform tests on the academic calendar functions.
  * @return The number of errors detected.
  *
  * Runs through every day in the academic calendar checking that the term
  * number and week number functions are correct and that days are
  * consecutive when calculated using Academic_calendar::Academic.
  */
 function PerformTests()
 {
     // Store the previous date so can see how many days have elapsed
     $prev_date = 0;
     $errors = 0;
     // Go through academic years
     for ($year = 2004; $year < 2012; ++$year) {
         // Go through all 6 academic terms
         for ($term_counter = 0; $term_counter < 6; ++$term_counter) {
             // Go through every week in the term
             $term_days = Academic_time::LengthOfAcademicTerm($year, $term_counter);
             $term_day = 0;
             $dow_counter = Academic_time::DayOfStartOfAcademicTerm($year, $term_counter) + 1;
             for ($week_counter = 1; $term_day < $term_days; ++$week_counter) {
                 // Go through every day in the week
                 for ($dow_counter = $dow_counter; $dow_counter <= 7 && $term_day < $term_days; ++$dow_counter) {
                     // Create a date object from academic year/term/week/day_of_week
                     $actime = $this->Academic($year, $term_counter, $week_counter, $dow_counter);
                     // Create a date object from academic year/term/day_of_term
                     $actime2 = $this->AcademicDayOfTerm($year, $term_counter, $term_day);
                     // Detect any inconsistencies
                     $error_detected = FALSE;
                     // Do Academic and AcademicDayOfTerm give the same result?
                     if ($actime != $actime2) {
                         echo '!!Academic and AcademicDayOfTerm give different results!!<br/>';
                         ++$errors;
                         $error_detected = TRUE;
                     }
                     // Has more than one day elapsed?
                     if (0 !== $prev_date && 1 !== Academic_time::DaysBetweenTimestamps($prev_date->Timestamp(), $actime->Timestamp())) {
                         echo '!!days not consecutive!!<br/>';
                         ++$errors;
                         $error_detected = TRUE;
                     }
                     // Is the calculated academic year consistent?
                     if ($year != $actime->AcademicYear()) {
                         echo '!!year doesn\'t match!!<br/>';
                         ++$errors;
                         $error_detected = TRUE;
                     }
                     // Is the calculated academic term consistent?
                     if ($term_counter != $actime->AcademicTerm()) {
                         echo '!!term doesn\'t match!!<br/>';
                         ++$errors;
                         $error_detected = TRUE;
                     }
                     // Is the calculated academic week consistent?
                     if ($week_counter != $actime->AcademicWeek()) {
                         echo '!!week doesn\'t match!!<br/>';
                         ++$errors;
                         $error_detected = TRUE;
                     }
                     if ($error_detected) {
                         // an error has been detected so print date information
                         if (0 !== $prev_date) {
                             // starting with previous date
                             echo '&nbsp;&nbsp;prev date: ' . $prev_date->Format(DATE_RFC822) . '<br/>';
                             //*/
                             // elapsed days
                             echo '&nbsp;&nbsp;days between: ' . Academic_time::DaysBetweenTimestamps($prev_date->Timestamp(), $actime->Timestamp()) . '<br/>';
                             //*/;
                         }
                         // academic date input
                         echo '&nbsp;&nbsp;Year: ' . $year . ', Term: ' . $term_counter . ', Week: ' . $week_counter . ', Day of week: ' . $dow_counter . ', Day of term: ' . $term_day . '<br/>';
                         //*/
                         // standard date output
                         echo '&nbsp;&nbsp;date1: ' . $actime->Format(DATE_RFC822) . '<br/>';
                         //*/
                         echo '&nbsp;&nbsp;date2: ' . $actime2->Format(DATE_RFC822) . '<br/>';
                         //*/
                         // gregorian & academic date output
                         echo '&nbsp;&nbsp;date: ' . $actime->DayOfMonth() . '/' . $actime->Month() . '/' . $actime->Year() . ': ' . $actime->AcademicWeek() . ',' . $actime->AcademicTermName() . ',' . $actime->AcademicYearName() . '<br/>';
                         //*/
                         // data from inside DaysBetweenTimestamps function
                         // probably no longer required now its fixed
                         echo '&nbsp;&nbsp;&nbsp;Day of year of first: ' . (int) date('z', $prev_date->Timestamp()) . '<br/>';
                         echo '&nbsp;&nbsp;&nbsp;Day of year of second: ' . (int) date('z', $actime->Timestamp()) . '<br/>';
                         $difference = (int) date('z', $actime->Timestamp()) - (int) date('z', $prev_date->Timestamp());
                         if ($difference < 0) {
                             echo '&nbsp;&nbsp;&nbsp;Days of year of first: ' . (365 + (int) date('L', $prev_date->Timestamp())) . '<br/>';
                         }
                         // New line to seperate error dates
                         echo '<br/>';
                     }
                     $prev_date = $actime;
                     ++$term_day;
                 }
                 $dow_counter = 1;
             }
         }
     }
     return $errors;
 }