コード例 #1
0
ファイル: Month.class.php プロジェクト: adamfranco/harmoni
 /**
  * Answer the days in this month on a given year.
  * 
  * @param string $indexOrNameString
  * @param ingteger $yearInteger
  * @return integer
  * @access public
  * @since 5/5/05
  * @static
  */
 static function daysInMonthForYear($indexOrNameString, $yearInteger)
 {
     if (is_numeric($indexOrNameString)) {
         $index = $indexOrNameString;
     } else {
         $index = Month::indexOfMonth($indexOrNameString);
     }
     if ($index < 1 | $index > 12) {
         $errorString = $index . " is not a valid month index.";
         if (function_exists('throwError')) {
             throwError(new Error($errorString));
         } else {
             die($errorString);
         }
     }
     $monthDays = ChronologyConstants::DaysInMonth();
     $days = $monthDays[$index];
     if ($index == 2 && Year::isYearLeapYear($yearInteger)) {
         return $days + 1;
     } else {
         return $days;
     }
 }
コード例 #2
0
ファイル: Year.class.php プロジェクト: adamfranco/harmoni
 /**
  *  Return the number of days in a year.
  * 
  * @param integer $anInteger
  * @return integer
  * @access public
  * @since 10/15/08
  * @static
  */
 public static function getDaysInYear($anInteger)
 {
     if (is_null($anInteger)) {
         throw new InvalidArgumentException("Cannot execute daysInYear for NULL.");
     }
     if (Year::isYearLeapYear($anInteger)) {
         return 365 + 1;
     } else {
         return 365;
     }
 }
コード例 #3
0
 /**
  * Test some leap years.
  * 
  */
 function test_leap_years()
 {
     // recent leap years
     $this->assertTrue(Year::isYearLeapYear(1980));
     $this->assertTrue(Year::isYearLeapYear(1984));
     $this->assertTrue(Year::isYearLeapYear(1988));
     $this->assertTrue(Year::isYearLeapYear(1992));
     $this->assertTrue(Year::isYearLeapYear(1996));
     $this->assertTrue(Year::isYearLeapYear(2000));
     $this->assertTrue(Year::isYearLeapYear(2004));
     $this->assertTrue(Year::isYearLeapYear(2008));
     // divisible-by 100 years
     $this->assertTrue(Year::isYearLeapYear(1600));
     $this->assertFalse(Year::isYearLeapYear(1700));
     $this->assertFalse(Year::isYearLeapYear(1800));
     $this->assertFalse(Year::isYearLeapYear(1900));
     $this->assertTrue(Year::isYearLeapYear(2000));
     $this->assertFalse(Year::isYearLeapYear(2100));
     $this->assertFalse(Year::isYearLeapYear(2200));
     $this->assertFalse(Year::isYearLeapYear(2300));
     $this->assertTrue(Year::isYearLeapYear(2400));
     // Non-leap years
     $this->assertFalse(Year::isYearLeapYear(1981));
     $this->assertFalse(Year::isYearLeapYear(1979));
     $this->assertFalse(Year::isYearLeapYear(1999));
     $this->assertFalse(Year::isYearLeapYear(2003));
     $this->assertFalse(Year::isYearLeapYear(2001));
     $this->assertFalse(Year::isYearLeapYear(1789));
     $this->assertFalse(Year::isYearLeapYear(2002));
     $this->assertFalse(Year::isYearLeapYear(1998));
     $this->assertFalse(Year::isYearLeapYear(2005));
     $aYear = Year::starting(DateAndTime::withYearDay(1980, 55));
     $this->assertEqual($aYear->startYear(), 1980);
     $this->assertEqual($aYear->dayOfYear(), 55);
     $this->assertEqual($aYear->daysInYear(), 366);
     $aYear = Year::withYear(1980);
     $this->assertEqual($aYear->startYear(), 1980);
     $this->assertEqual($aYear->dayOfYear(), 1);
     $this->assertEqual($aYear->daysInYear(), 366);
     $aYear = Year::withYear(2000);
     $this->assertEqual($aYear->startYear(), 2000);
     $this->assertEqual($aYear->dayOfYear(), 1);
     $this->assertEqual($aYear->daysInYear(), 366);
 }
コード例 #4
0
 /**
  * Return if this year is a leap year
  * 
  * @return boolean
  * @access public
  * @since 5/4/05
  */
 function isLeapYear()
 {
     return Year::isYearLeapYear($this->year());
 }