Пример #1
0
 /**
  * Answer a Duration that represents this object, the duration since
  * midnight.
  * 
  * @return object Duration
  * @access public
  * @since 5/4/05
  */
 function asDuration()
 {
     $obj = Duration::withSeconds($this->seconds);
     return $obj;
 }
Пример #2
0
 /**
  * Save an XML string to the feed cache
  * 
  * @param string $url
  * @param string $feedXml
  * @return void
  * @access protected
  * @since 7/8/08
  */
 protected function cacheXmlString($url, $feedXml)
 {
     $dbc = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('segue_plugins_rssfeed_cache');
     $query->addWhereEqual('url', $url);
     $query->addWhereRawLessThan('cache_time', $dbc->toDBDate(DateAndTime::now()->minus(Duration::withSeconds(600)), IMPORTER_CONNECTION), _OR);
     try {
         $result = $dbc->query($query, IMPORTER_CONNECTION);
     } catch (NoSuchTableDatabaseException $e) {
         $this->createCacheTable();
     }
     $query = new InsertQuery();
     $query->setTable('segue_plugins_rssfeed_cache');
     $query->addValue('url', $url);
     $query->addValue('feed_data', $feedXml);
     $dbc->query($query, IMPORTER_CONNECTION);
 }
 /**
  * Magnitude operations
  * 
  */
 function test_magnitude_ops()
 {
     // Plus a Duration
     $dateAndTime = DateAndTime::withYearDayHourMinuteSecond(2005, 100, 0, 0, 0);
     $result = $dateAndTime->plus(Duration::withSeconds(1));
     $this->assertEqual(strtolower(get_class($result)), 'dateandtime');
     $this->assertTrue($result->isEqualTo(DateAndTime::withYearDayHourMinuteSecond(2005, 100, 0, 0, 1)));
     // minus a Duration
     $dateAndTime = DateAndTime::withYearDayHourMinuteSecond(2005, 100, 0, 0, 0);
     $result = $dateAndTime->minus(Duration::withSeconds(1));
     $this->assertEqual(strtolower(get_class($result)), 'dateandtime');
     $this->assertEqual($result->year(), 2005);
     $this->assertEqual($result->dayOfYear(), 99);
     $this->assertEqual($result->hour(), 23);
     $this->assertEqual($result->minute(), 59);
     $this->assertEqual($result->second(), 59);
     $this->assertTrue($result->isEqualTo(DateAndTime::withYearDayHourMinuteSecond(2005, 99, 23, 59, 59)));
     // Minus a DateAndTime
     $dateAndTime = DateAndTime::withYearDayHourMinuteSecond(2006, 100, 0, 0, 0);
     $result = $dateAndTime->minus(DateAndTime::withYearDayHourMinuteSecond(2005, 100, 0, 0, 0));
     $this->assertEqual(strtolower(get_class($result)), 'duration');
     $this->assertTrue($result->isEqualTo(Duration::withDays(365)));
     // Minus a DateAndTime over a leap year
     $dateAndTime = DateAndTime::withYearDayHourMinuteSecond(2005, 10, 0, 0, 0);
     $result = $dateAndTime->minus(DateAndTime::withYearDayHourMinuteSecond(2004, 10, 0, 0, 0));
     $this->assertEqual(strtolower(get_class($result)), 'duration');
     $this->assertTrue($result->isEqualTo(Duration::withDays(366)));
     // Plus a DateAndTime
     $dateAndTime = DateAndTime::withYearDayHourMinuteSecond(2000, 100, 5, 15, 30);
     $result = $dateAndTime->plus(DateAndTime::withYearDayHourMinuteSecond(2000, 100, 5, 30, 15));
     $this->assertEqual(strtolower(get_class($result)), 'dateandtime');
     $this->assertEqual($result->year(), 2000);
     $this->assertEqual($result->dayOfYear(), 100);
     $this->assertEqual($result->hour(), 10);
     $this->assertEqual($result->minute(), 45);
     $this->assertEqual($result->second(), 45);
 }
Пример #4
0
 /**
  * Update the modification date and set the creation date if needed.
  *
  * WARNING: NOT IN OSID
  * 
  * @return void
  * @access public
  * @since 5/4/06
  */
 function updateModificationDate()
 {
     // Only update our modification time if we will be adding more than a
     // minute (to save on many repeated updates while changing lots of values
     // at once).
     if (isset($this->_modifyDate) && is_object($this->_modifyDate)) {
         $now = DateAndTime::now();
         $minute = Duration::withSeconds(60);
         if ($minute->isGreaterThan($now->minus($this->_modifyDate))) {
             return;
         }
     }
     $this->_loadDates();
     $this->_storeDates();
 }
Пример #5
0
 /**
  * Test converting methods
  * 
  */
 function test_converting()
 {
     $time = Time::withHourMinuteSecond(15, 25, 10);
     // asDate ()
     $temp = $time->asDate();
     $this->assertTrue($temp->isEqualTo(Date::today()));
     $this->assertEqual(strtolower(get_class($temp)), 'date');
     // asDateAndTime ()
     $temp = $time->asDateAndTime();
     $comparison = DateAndTime::midnight();
     $comparison = $comparison->plus(Duration::withSeconds(55510));
     $this->assertTrue($temp->isEqualTo($comparison));
     $this->assertEqual(strtolower(get_class($temp)), 'dateandtime');
     // asDuration ()
     $temp = $time->asDuration();
     $this->assertTrue($temp->isEqualTo(Duration::withSeconds(55510)));
     $this->assertEqual(strtolower(get_class($temp)), 'duration');
     // asMonth ()
     $temp = $time->asMonth();
     $this->assertTrue($temp->isEqualTo(Month::starting(Date::today())));
     $this->assertEqual(strtolower(get_class($temp)), 'month');
     // asSeconds ()
     $this->assertEqual($time->asSeconds(), 55510);
     // asTime ()
     $temp = $time->asTime();
     $this->assertTrue($temp->isEqualTo($time));
     $this->assertEqual(strtolower(get_class($temp)), 'time');
     // asTimeStamp ()
     $temp = $time->asTimeStamp();
     $comparison = TimeStamp::midnight();
     $comparison = $comparison->plus(Duration::withSeconds(55510));
     $this->assertTrue($temp->isEqualTo($comparison));
     $this->assertEqual(strtolower(get_class($temp)), 'timestamp');
     // asWeek ()
     $temp = $time->asWeek();
     $this->assertTrue($temp->isEqualTo(Week::starting(Date::today())));
     $this->assertEqual(strtolower(get_class($temp)), 'week');
     // asYear ()
     $temp = $time->asYear();
     $this->assertTrue($temp->isEqualTo(Year::starting(Date::today())));
     $this->assertEqual(strtolower(get_class($temp)), 'year');
     // to ()
     $today = DateAndTime::today();
     $tomorrow = DateAndTime::tomorrow();
     $result = $time->to($tomorrow);
     $this->assertEqual(strtolower(get_class($result)), 'timespan');
     $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 34, 50))));
     $result = $time->to(Time::withHourMinuteSecond(23, 25, 10));
     $this->assertEqual(strtolower(get_class($result)), 'timespan');
     $this->assertTrue($result->isEqualTo(Timespan::startingDuration($today->plus(Duration::withSeconds(55510)), Duration::withDaysHoursMinutesSeconds(0, 8, 0, 0))));
 }
Пример #6
0
 /**
  * Answer a string version of this time zone
  * 
  * @return string
  * @access public
  * @since 10/15/08
  */
 public function printableString()
 {
     if ($this->offset->isLessThan(Duration::withSeconds(0))) {
         $string = '-';
     } else {
         $string = '+';
     }
     $string .= str_pad(abs($this->offset->hours()), 2, '0', STR_PAD_LEFT);
     $string .= ':' . str_pad(abs($this->offset->minutes()), 2, '0', STR_PAD_LEFT);
     return $string;
 }
Пример #7
0
 /**
  * Test the negation
  */
 function test_negation()
 {
     $duration = Duration::withDays(5);
     $neg = $duration->negated();
     $this->assertEqual($neg->seconds(), 0);
     $this->assertEqual($neg->days(), -5);
     $ticks = $neg->ticks();
     $this->assertEqual($ticks[0], -5);
     $this->assertEqual($ticks[1], 0);
     $duration = Duration::withSeconds(1);
     $neg = $duration->negated();
     $this->assertEqual($neg->seconds(), -1);
     $this->assertEqual($neg->days(), 0);
     $ticks = $neg->ticks();
     $this->assertEqual($ticks[0], 0);
     $this->assertEqual($ticks[1], -1);
 }
Пример #8
0
 /**
  * Answer a TimeStamp which is anInteger seconds after the receiver.
  * 
  * @param integer $anInteger
  * @return object TimeStamp
  * @access public
  * @since 5/13/05
  */
 function plusSeconds($anInteger)
 {
     $obj = $this->plus(Duration::withSeconds($anInteger));
     return $obj;
 }
Пример #9
0
    /**
     * Create a new TimeStamp from a UNIX timestamp.
     * 
     * @param integer $aUnixTimeStamp The number of seconds since the Unix Epoch 
     *		(January 1 1970 00:00:00 GMT/UTC)
     * @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 Timestamp
     * @access public
     * @since 5/27/05
     */
    function fromUnixTimeStamp($aUnixTimeStamp, $class = 'StorableTime')
    {
        $sinceUnixEpoch = Duration::withSeconds($aUnixTimeStamp);
        eval('$unixEpoch = ' . $class . '::withYearMonthDayHourMinuteSecondOffset(
						1970, 1, 1, 0, 0, 0, Duration::zero());');
        return $unixEpoch->plus($sinceUnixEpoch);
    }