function test_updates() { $dateTime = DateAndTime::now(); $this->authorization->updateExpirationDate($dateTime); $this->assertReference($dateTime, $this->authorization->getExpirationDate()); $this->assertFalse($this->authorization->isActiveNow()); $dateTime = DateAndTime::now(); $this->authorization->updateEffectiveDate($dateTime); $this->authorization->updateExpirationDate(DateAndTime::withYearMonthDay(2030, 10, 10)); $this->assertReference($dateTime, $this->authorization->getEffectiveDate()); $this->assertTrue($this->authorization->isActiveNow()); }
/** * 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 Accessing Methods * */ function test_accessing() { $timespan = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10)); // day() $this->assertEqual($timespan->day(), 124); // dayOfMonth() $this->assertEqual($timespan->dayOfMonth(), 4); // dayOfWeek() $this->assertEqual($timespan->dayOfWeek(), 4); // dayOfWeekName() $this->assertEqual($timespan->dayOfWeekName(), 'Wednesday'); // dayOfYear() $this->assertEqual($timespan->dayOfYear(), 124); // daysInMonth() $this->assertEqual($timespan->daysInMonth(), 31); // daysInYear() $this->assertEqual($timespan->daysInYear(), 365); // daysLeftInYear() $this->assertEqual($timespan->daysLeftInYear(), 241); // duration() $temp = Duration::withDays(365); $this->assertTrue($temp->isEqualTo($timespan->duration())); // end() $temp = DateAndTime::withYearMonthDay(2006, 5, 4); $temp = $temp->minus(DateAndTime::clockPrecision()); $this->assertTrue($temp->isEqualTo($timespan->end())); // firstDayOfMonth() $this->assertEqual($timespan->firstDayOfMonth(), 121); // isLeapYear() $this->assertEqual($timespan->isLeapYear(), FALSE); // julianDayNumber() $this->assertEqual($timespan->julianDayNumber(), 2453495); // printableString() $this->assertEqual($timespan->printableString(), '2005-05-04T00:00:00-04:00D365:00:00:00'); // startMonth() $this->assertEqual($timespan->startMonth(), 5); // startMonthAbbreviation() $this->assertEqual($timespan->startMonthAbbreviation(), 'May'); // startMonthIndex() $this->assertEqual($timespan->startMonthIndex(), 5); // startMonthName() $this->assertEqual($timespan->startMonthName(), 'May'); // start() $temp = DateAndTime::withYearMonthDay(2005, 5, 4); $this->assertTrue($temp->isEqualTo($timespan->start())); // startYear() $this->assertEqual($timespan->startYear(), 2005); }
/** * Test aritmatic operations * */ function test_intersect_union() { // intersection() // union() // 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 // 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 // // A |- - - - - - - - - -| // B |-| // C |- - - - - - - - -| // D |- - - -| $timespanA = Timespan::startingDuration(DateAndTime::withYearMonthDay(2005, 5, 4), Duration::withDays(10)); $timespanB = Timespan::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 10, 12, 0, 0, Duration::withHours(-4)), Duration::withDays(1)); $timespanC = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 8), DateAndTime::withYearMonthDay(2005, 5, 17)); $timespanD = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 17), DateAndTime::withYearMonthDay(2005, 5, 21)); // intersection() $duration = Duration::withDays(1); $temp = Timespan::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 10, 12, 0, 0, Duration::withHours(-4)), $duration->minus(DateAndTime::clockPrecision())); $result = $timespanA->intersection($timespanB); $this->assertTrue($temp->isEqualTo($result)); $tempEnd = DateAndTime::withYearMonthDay(2005, 5, 14); $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 8), $tempEnd->minus(DateAndTime::clockPrecision())); $this->assertTrue($temp->isEqualTo($timespanA->intersection($timespanC))); $this->assertEqual($timespanA->intersection($timespanD), NULL); // union() $this->assertTrue($timespanA->isEqualTo($timespanA->union($timespanB))); $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 4), DateAndTime::withYearMonthDay(2005, 5, 17)); $this->assertTrue($temp->isEqualTo($timespanA->union($timespanC))); $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 4), DateAndTime::withYearMonthDay(2005, 5, 21)); $this->assertTrue($temp->isEqualTo($timespanA->union($timespanD))); }
/** * Create a new Year * * @param integer $anInteger * @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 Year * @access public * @since 5/4/05 * @static */ static function withYear($anInteger, $class = 'Year') { $start = DateAndTime::withYearMonthDay($anInteger, 1, 1); eval('$result = ' . $class . '::startingDuration( $start, $null = NULL, $class );'); return $result; }
/** * Test the enumeration methods. */ function test_multipleduration_enumeration() { $schedule = Schedule::startingDuration(DateAndTime::withYearMonthDay(2005, 5, 15), Duration::withDays(7)); $durations = array(); $durations[] = Duration::withDays(1); $durations[] = Duration::withHours(1); $schedule->setSchedule($durations); $this->assertEqual($schedule->getSchedule(), $durations); $datesAndTimes = array(); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 15, 0, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 16, 0, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 16, 1, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 17, 1, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 17, 2, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 18, 2, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 18, 3, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 19, 3, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 19, 4, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 20, 4, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 20, 5, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 21, 5, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 21, 6, 0, 0); $this->assertEqual($schedule->dateAndTimes(), $datesAndTimes); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 21, 5, 0, 0); $this->assertNotEqual($schedule->dateAndTimes(), $datesAndTimes); $datesAndTimes = array(); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 17, 1, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 18, 1, 0, 0); $datesAndTimes[] = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 18, 2, 0, 0); $this->assertEqual($schedule->between(DateAndTime::withYearMonthDay(2005, 5, 17), DateAndTime::withYearMonthDay(2005, 5, 19)), $datesAndTimes); }
/** * Test instance creation from a string. * */ function test_from_string() { $dateAndTime = DateAndTime::withYearMonthDay(2005, 8, 20); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('08/20/2005'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('August 20, 2005'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20aug05'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 8, 20, 15, 25, 10); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25:10'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20050820152510'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20 3:25:10 pm'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('08/20/2005 3:25:10 pm'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('August 20, 2005 3:25:10 pm'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005/08/20 15:25:10'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 8, 20, 15, 25, 0); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 8, 20, 15, 0, 0); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 8, 20, 15, 25, 10, Duration::withHours(-7)); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25:10-07:00'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20050820152510-07'))); $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 8, 20, 15, 25, 10, Duration::zero()); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('2005-08-20T15:25:10Z'))); $this->assertTrue($dateAndTime->isEqualTo(DateAndTime::fromString('20050820152510Z'))); }
function test_create_dated_authorization() { $agentId = new HarmoniId("3827"); $functionId = new HarmoniId("501"); $qualifierId = new HarmoniId("6799"); $date1 = DateAndTime::withYearMonthDay(1987, 10, 24); $date2 = DateAndTime::withYearMonthDay(2014, 6, 25); $authorization = $this->manager->createDatedAuthorization($agentId, $functionId, $qualifierId, $date1, $date2); $this->assertIsA($authorization, "HarmoniAuthorization"); $this->assertReference($agentId, $authorization->getAgentId()); $this->assertReference($functionId, $authorization->_functionId); $this->assertReference($qualifierId, $authorization->_qualifierId); $this->assertIdentical($authorization->getEffectiveDate(), $date1); $this->assertIdentical($authorization->getExpirationDate(), $date2); $this->manager->deleteAuthorization($authorization); }
/** * Create a new instance. * * @param integer $anIntYear * @param integer $anIntOrStringMonth * @param integer $anIntDay * @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. * @access public * @return object TimeStamp * @static * @since 5/4/05 */ static function withYearMonthDay($anIntYear, $anIntOrStringMonth, $anIntDay, $class = 'Timestamp') { $obj = parent::withYearMonthDay($anIntYear, $anIntOrStringMonth, $anIntDay, $class); return $obj; }
/** * Create a new instance. * * @param integer $anIntYear * @param integer $anIntOrStringMonth * @param integer $anIntDay * @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. * @access public * @return object StorableTime * @static * @since 5/4/05 */ static function withYearMonthDay($anIntYear, $anIntOrStringMonth, $anIntDay, $class = 'StorableTime') { return parent::withYearMonthDay($anIntYear, $anIntOrStringMonth, $anIntDay, $class); }