Ejemplo n.º 1
0
 /**
  * Takes a single database row, which would contain the columns added by alterQuery()
  * and extracts the values to setup the object with the appropriate data.
  *
  * All times are stored in the database as UTC.
  *
  * @param array $dbRow
  * @access public
  * @return object StorableTime
  * @static
  */
 static function createAndPopulate($dbRow)
 {
     $date = StorableTime::withJulianDayNumber($dbRow["time_jdn"]);
     $timeComponent = Duration::withSeconds($dbRow["time_seconds"]);
     $date = $date->plus($timeComponent);
     // The date in the DB was UTC, so be sure to set the offset to zero here.
     $date = $date->withOffset(Duration::zero());
     // Convert the time to the local offset, maintain equivalent time to the
     // UTC version
     return $date->asLocal();
 }
Ejemplo n.º 2
0
 /**
  * Test aritmatic operations
  * 
  */
 function test_operations()
 {
     // Operations
     // plus()
     // minus()
     // 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 3 0 0 0
     // 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 9 0 1 2 3 4
     //
     // A  |- - - - - - - - - -|
     // B              |-|
     // C                                  |- - - - - - - - -|
     // D                                                          |- - - -|
     $timespanA = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 4, 15, 25, 10, Duration::withHours(-4)), Duration::withDays(10));
     $timespanB = Year::startingDuration(DateAndTime::withYearMonthDayHourMinuteSecondOffset(2005, 5, 10, 12, 0, 0, Duration::withHours(-4)), Duration::withDays(1));
     $timespanC = Year::starting(DateAndTime::withYearMonthDay(2005, 5, 20));
     $timespanD = Year::starting(DateAndTime::withYearMonthDay(2005, 6, 1));
     // plus()
     $temp = Year::starting(DateAndTime::withYearMonthDay(2005, 5, 24));
     $result = $timespanC->plus(Duration::withDays(4));
     $this->assertEqual(strtolower(get_class($result)), "year");
     $this->assertTrue($temp->isEqualTo($result));
     // minus()
     // Subtracting an object that implemnts asDateAndTime
     $temp = Year::starting(DateAndTime::withYearMonthDay(2005, 5, 15));
     $result = $timespanC->minus(Duration::withDays(5));
     $this->assertEqual(strtolower(get_class($result)), "year");
     $this->assertTrue($temp->isEqualTo($result));
     $tempDuration = Duration::withDays(-12);
     $this->assertTrue($tempDuration->isEqualTo($timespanC->minus($timespanD)));
     $tempDuration = Duration::zero();
     $this->assertTrue($tempDuration->isEqualTo($timespanA->minus($timespanA)));
 }
Ejemplo n.º 3
0
 /**
  * Test aritmatic operations
  * 
  */
 function test_operations()
 {
     // Operations
     // plus()
     // minus()
     // 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));
     // plus()
     $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 12), DateAndTime::withYearMonthDay(2005, 5, 21));
     $this->assertTrue($temp->isEqualTo($timespanC->plus(Duration::withDays(4))));
     $this->assertTrue($temp->isEqualTo($timespanC->plus($timespanD->asDuration())));
     // minus()
     // Subtracting an object that implemnts asDateAndTime
     $temp = Timespan::startingEnding(DateAndTime::withYearMonthDay(2005, 5, 3), DateAndTime::withYearMonthDay(2005, 5, 12));
     $this->assertTrue($temp->isEqualTo($timespanC->minus(Duration::withDays(5))));
     $tempDuration = Duration::withDays(4);
     $this->assertTrue($tempDuration->isEqualTo($timespanC->minus($timespanA)));
     $tempDuration = Duration::withDays(-4);
     $this->assertTrue($tempDuration->isEqualTo($timespanA->minus($timespanC)));
     $tempDuration = Duration::zero();
     $this->assertTrue($tempDuration->isEqualTo($timespanA->minus($timespanA)));
 }
Ejemplo n.º 4
0
 /**
  * Answer the duration of this object (always zero)
  * 
  * @return object Duration
  * @access public
  * @since 5/5/05
  */
 function duration()
 {
     $obj = Duration::zero();
     return $obj;
 }
Ejemplo n.º 5
0
 /**
  * Test the creation methods.
  */
 function test_creation()
 {
     // class methods - instance creation
     // current()
     // epoch()
     // starting()
     // startingDuration()
     // startingEnding()
     $timespan = Schedule::current();
     $this->assertEqual($timespan->startYear(), intval(date('Y')));
     $this->assertEqual($timespan->startMonth(), intval(date('n')));
     $this->assertEqual($timespan->dayOfMonth(), intval(date('j')));
     $duration = $timespan->duration();
     $this->assertTrue($duration->isEqualTo(Duration::zero()));
     $this->assertEqual(strtolower(get_class($timespan)), 'schedule');
     $timespan = Schedule::epoch();
     $this->assertEqual($timespan->startYear(), 1901);
     $this->assertEqual($timespan->startMonth(), 1);
     $this->assertEqual($timespan->dayOfMonth(), 1);
     $duration = $timespan->duration();
     $this->assertTrue($duration->isEqualTo(Duration::zero()));
     $this->assertEqual(strtolower(get_class($timespan)), 'schedule');
 }
 /**
  * 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')));
 }
Ejemplo n.º 7
0
 /**
  * Test accessing methods
  * 
  */
 function test_accessing()
 {
     $time = Time::withHourMinuteSecond(15, 25, 10);
     // duration ()
     $temp = $time->duration();
     $this->assertTrue($temp->isEqualTo(Duration::zero()));
     // hour ()
     $this->assertEqual($time->hour(), 15);
     // hour12 ()
     $this->assertEqual($time->hour12(), 3);
     // hour24 ()
     $this->assertEqual($time->hour24(), 15);
     // meridianAbbreviation ()
     $this->assertEqual($time->meridianAbbreviation(), 'PM');
     // minute ()
     $this->assertEqual($time->minute(), 25);
     // string12 ()
     $this->assertEqual($time->string12(), '3:25:10 pm');
     // string24 ()
     $this->assertEqual($time->string24(), '15:25:10');
     // printableString ()
     $this->assertEqual($time->printableString(), '3:25:10 pm');
     // second ()
     $this->assertEqual($time->second(), 10);
 }
Ejemplo n.º 8
0
 /**
  * Class constructor.
  */
 public function __construct()
 {
     $this->duration = Duration::zero();
 }
Ejemplo n.º 9
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.º 10
0
 /**
  * Answer the reciever as a UNIX timestamp - The number of seconds since the 
  * Unix Epoch (January 1 1970 00:00:00 GMT/UTC).
  * 
  * @return integer
  * @access public
  * @since 5/27/05
  */
 function asUnixTimeStamp()
 {
     $sinceUnixEpoch = $this->minus(TimeStamp::withYearMonthDayHourMinuteSecondOffset(1970, 1, 1, 0, 0, 0, Duration::zero()));
     return $sinceUnixEpoch->asSeconds();
 }