Ejemplo n.º 1
0
 /**
  * Test Converting Methods
  * 
  */
 function test_converting()
 {
     // Converting
     $timespan = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10));
     // asDate()
     $temp = $timespan->asDate();
     $this->assertTrue($temp->isEqualTo(Date::withYearMonthDay(2005, 5, 4)));
     // asDateAndTime()
     $temp = $timespan->asDateAndTime();
     $this->assertTrue($temp->isEqualTo(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 00, 00, 00)));
     // asDuration()
     $temp = $timespan->asDuration();
     $this->assertTrue($temp->isEqualTo(Duration::withDays(365)));
     // asMonth()
     $temp = $timespan->asMonth();
     $this->assertTrue($temp->isEqualTo(Month::withMonthYear(5, 2005)));
     // asTime()
     $temp = $timespan->asTime();
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0);
     $this->assertTrue($temp->isEqualTo($dateAndTime->asTime()));
     // asTimeStamp()
     $temp = $timespan->asTimeStamp();
     $this->assertTrue($temp->isEqualTo(TimeStamp::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0)));
     // asWeek()
     $temp = $timespan->asWeek();
     $this->assertTrue($temp->isEqualTo(Week::starting(Date::withYearMonthDay(2005, 5, 1))));
     // asYear()
     $temp = $timespan->asYear();
     $this->assertTrue($temp->isEqualTo(Year::starting(Date::withYearMonthDay(2005, 5, 4))));
     // to()
     $temp = $timespan->to(Date::withYearMonthDay(2005, 10, 1));
     $comparison = Timespan::startingEnding(DateAndTime::withYearMonthDayHourMinuteSecond(2005, 5, 4, 0, 0, 0), Date::withYearMonthDay(2005, 10, 1));
     $this->assertTrue($temp->isEqualTo($comparison));
 }
 /**
  * Test conversion to the PHP built-in DateTime
  * 
  * @return void
  * @access public
  * @since 11/21/08
  */
 public function test_php_datetime()
 {
     print "<h3>conversion to PHP DateTime</h3>";
     $ref = new ReflectionClass('DateTimeZone');
     printpre($ref->getMethods());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 2, 4, 15, 25, 10, Duration::withHours(-4));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(1423, 2, 4, 15, 25, 10, Duration::withHours(0));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(732, 6, 3, 8, 0, 0, Duration::withHours(0));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(2, 6, 3, 8, 0, 0, Duration::withHours(0));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(0, 6, 3, 8, 0, 0, Duration::withHours(0));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(-460, 6, 3, 8, 0, 0, Duration::withHours(0));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::withYearMonthDayHourMinuteSecondOffset(-8460, 6, 3, 8, 0, 0, Duration::withHours(0));
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
     $dateAndTime = DateAndTime::now();
     $this->checkEquality($dateAndTime, $dateAndTime->asDateTime());
 }
Ejemplo n.º 3
0
 /**
  * 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);
 }
Ejemplo n.º 4
0
 /**
  * Answer a DateAndTime equivalent to the reciever, but at UTC (offset = 0)
  * 
  * @return object DateAndTime
  * @access public
  * @since 5/4/05
  */
 function asUTC()
 {
     $obj = $this->utcOffset(Duration::withHours(0));
     return $obj;
 }
Ejemplo n.º 5
0
 /**
  * Return an Array of TimeZones
  * 
  * @return array
  * @access public
  * @since 5/3/05
  * @static
  */
 static function timeZones()
 {
     $array = array(TimeZone::offsetNameAbbreviation(Duration::withHours(0), 'Universal Time', 'UTC'), TimeZone::offsetNameAbbreviation(Duration::withHours(0), 'Greenwich Mean Time', 'GMT'), TimeZone::offsetNameAbbreviation(Duration::withHours(0), 'British Summer Time', 'BST'), TimeZone::offsetNameAbbreviation(Duration::withHours(-5), 'Eastern Standard Time', 'EST'), TimeZone::offsetNameAbbreviation(Duration::withHours(-4), 'Eastern Daylight Time', 'EDT'), TimeZone::offsetNameAbbreviation(Duration::withHours(-6), 'Central Standard Time', 'CST'), TimeZone::offsetNameAbbreviation(Duration::withHours(-5), 'Central Daylight Time', 'CDT'), TimeZone::offsetNameAbbreviation(Duration::withHours(-7), 'Mountain Standard Time', 'MST'), TimeZone::offsetNameAbbreviation(Duration::withHours(-6), 'Mountain Daylight Time', 'MDT'), TimeZone::offsetNameAbbreviation(Duration::withHours(-8), 'Pacific Standard Time', 'PST'), TimeZone::offsetNameAbbreviation(Duration::withHours(-7), 'Pacific Daylight Time', 'PDT'));
     return $array;
 }
Ejemplo n.º 6
0
 /**
  * Test the creation based on a times other than a day.
  */
 function test_non_day_creation()
 {
     // 5 hours
     $duration = Duration::withDaysHoursMinutesSeconds(0, 5, 0, 0);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 5);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 3600 * 5);
     $this->assertTrue($duration->isEqualTo(Duration::withHours(5)));
     // 15 minutes
     $duration = Duration::withDaysHoursMinutesSeconds(0, 0, 15, 0);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 15);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 15 * 60);
     $this->assertTrue($duration->isEqualTo(Duration::withMinutes(15)));
     // 35 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(0, 0, 0, 35);
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 35);
     $this->assertEqual($duration->asSeconds(), 35);
     $this->assertTrue($duration->isEqualTo(Duration::withSeconds(35)));
     // 3 days, 2 hours, 23 minutes, and 12 seconds
     $duration = Duration::withDaysHoursMinutesSeconds(3, 2, 23, 12);
     $this->assertEqual($duration->days(), 3);
     $this->assertEqual($duration->hours(), 2);
     $this->assertEqual($duration->minutes(), 23);
     $this->assertEqual($duration->seconds(), 12);
     $this->assertEqual($duration->asSeconds(), ((3 * 24 + 2) * 60 + 23) * 60 + 12);
     // 48 hours
     $duration = Duration::withDaysHoursMinutesSeconds(0, 48, 0, 0);
     $this->assertEqual($duration->days(), 2);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $this->assertEqual($duration->asSeconds(), 86400 * 2);
     // Month
     $duration = Duration::withMonth('June');
     $this->assertEqual($duration->days(), 30);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withMonth('July');
     $this->assertEqual($duration->days(), 31);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withMonth(9);
     $this->assertEqual($duration->days(), 30);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     // Weeks
     $duration = Duration::withWeeks(1);
     $this->assertEqual($duration->days(), 7);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(5);
     $this->assertEqual($duration->days(), 35);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.5);
     $this->assertEqual($duration->days(), 10);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.5);
     $this->assertEqual($duration->days(), 10);
     $this->assertEqual($duration->hours(), 12);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
     $duration = Duration::withWeeks(1.374);
     $this->assertEqual($duration->days(), 9);
     $this->assertEqual($duration->hours(), 14);
     $this->assertEqual($duration->minutes(), 49);
     $this->assertEqual($duration->seconds(), 55);
     $duration = Duration::withWeeks(-1.374);
     $this->assertEqual($duration->days(), -9);
     $this->assertEqual($duration->hours(), -14);
     $this->assertEqual($duration->minutes(), -49);
     $this->assertEqual($duration->seconds(), -55);
     //Zero
     $duration = Duration::zero();
     $this->assertEqual($duration->days(), 0);
     $this->assertEqual($duration->hours(), 0);
     $this->assertEqual($duration->minutes(), 0);
     $this->assertEqual($duration->seconds(), 0);
 }
Ejemplo n.º 7
0
 /**
  * Answer the delay (in seconds) that the modification time should be cached without
  * checking the source again. 
  * 
  * @return object Duration
  * @access public
  * @since 6/18/08
  */
 public function getCacheDuration()
 {
     // A default of 1 minute is used. Override this method to add longer
     // or shorter times.
     return Duration::withHours(2);
 }
Ejemplo n.º 8
0
 /**
  * Test utcOffset
  * 
  */
 function test_utcOffset()
 {
     $dateAndTime = TimeStamp::withYearMonthDayHourMinuteSecondOffset(2005, 6, 4, 15, 25, 10, Duration::withHours(-5));
     $atUTC = $dateAndTime->utcOffset(Duration::withHours(0));
     $this->assertEqual($dateAndTime->julianDayNumber(), 2453526);
     $this->assertEqual($atUTC->julianDayNumber(), 2453526);
     $this->assertEqual($dateAndTime->seconds, 55510);
     $this->assertEqual($atUTC->seconds, 73510);
     $this->assertEqual($dateAndTime->offset->seconds, -18000);
     $this->assertEqual($atUTC->offset->seconds, 0);
     $this->assertEqual($dateAndTime->printableString(), '4 June 2005 3:25:10 pm');
     $this->assertEqual($atUTC->printableString(), '4 June 2005 8:25:10 pm');
 }