/** * Create a new object starting now, with a given duration. * Override - as each month has a defined duration * * @param object DateAndTime $aDateAndTime * @param object Duration $aDuration * @param optional string $class DO NOT USE OUTSIDE OF PACKAGE. * This parameter is used to get around the limitations of not being * able to find the class of the object that recieved the initial * method call. * @return object Month * @access public * @since 5/5/05 * @static */ static function startingDuration($aDateAndTime, $aDuration, $class = 'Month') { // Validate our passed class name. if (!(strtolower($class) == strtolower('Month') || is_subclass_of(new $class(), 'Month'))) { die("Class, '{$class}', is not a subclass of 'Month'."); } $start = $aDateAndTime->asDateAndTime(); $adjusted = DateAndTime::withYearMonthDay($start->year(), $start->month(), 1); $days = Month::daysInMonthForYear($adjusted->month(), $adjusted->year()); $month = new $class(); $month->setStart($adjusted); $month->setDuration(Duration::withDays($days)); return $month; }
/** * Test days in month */ function test_days_In_Month() { $this->assertEqual(Month::daysInMonthForYear(1, 1999), 31); $this->assertEqual(Month::daysInMonthForYear(2, 1999), 28); $this->assertEqual(Month::daysInMonthForYear(3, 1999), 31); $this->assertEqual(Month::daysInMonthForYear(4, 1999), 30); $this->assertEqual(Month::daysInMonthForYear(5, 1999), 31); $this->assertEqual(Month::daysInMonthForYear(6, 1999), 30); $this->assertEqual(Month::daysInMonthForYear(7, 1999), 31); $this->assertEqual(Month::daysInMonthForYear(8, 1999), 31); $this->assertEqual(Month::daysInMonthForYear(9, 1999), 30); $this->assertEqual(Month::daysInMonthForYear(10, 1999), 31); $this->assertEqual(Month::daysInMonthForYear(11, 1999), 30); $this->assertEqual(Month::daysInMonthForYear(12, 1999), 31); $this->assertEqual(Month::daysInMonthForYear(1, 2000), 31); $this->assertEqual(Month::daysInMonthForYear(2, 2000), 29); $this->assertEqual(Month::daysInMonthForYear(3, 2000), 31); $this->assertEqual(Month::daysInMonthForYear(4, 2000), 30); $this->assertEqual(Month::daysInMonthForYear(5, 2000), 31); $this->assertEqual(Month::daysInMonthForYear(6, 2000), 30); $this->assertEqual(Month::daysInMonthForYear(7, 2000), 31); $this->assertEqual(Month::daysInMonthForYear(8, 2000), 31); $this->assertEqual(Month::daysInMonthForYear(9, 2000), 30); $this->assertEqual(Month::daysInMonthForYear(10, 2000), 31); $this->assertEqual(Month::daysInMonthForYear(11, 2000), 30); $this->assertEqual(Month::daysInMonthForYear(12, 2000), 31); }