コード例 #1
0
 /**
  * Parse the input string and set our elements based on the contents of the
  * input string. Elements not found in the string will be null.
  * 
  * @return void
  * @access private
  * @since 5/24/05
  */
 function parse()
 {
     $term = trim(strtolower($this->input));
     if (in_array($term, $this->nowArray())) {
         $timespan = Timespan::current();
     } else {
         if (in_array($term, $this->todayArray())) {
             $timespan = Date::today();
         } else {
             if (in_array($term, $this->tomorrowArray())) {
                 $timespan = Date::tomorrow();
             } else {
                 if (in_array($term, $this->yesterdayArray())) {
                     $timespan = Date::yesterday();
                 }
             }
         }
     }
     $dateAndTime = $timespan->start();
     $offset = $dateAndTime->offset();
     $this->setYear($dateAndTime->year());
     $this->setMonth($dateAndTime->month());
     $this->setDay($dateAndTime->dayOfMonth());
     $this->setHour($dateAndTime->hour());
     $this->setMinute($dateAndTime->minute());
     $this->setSecond($dateAndTime->second());
     $this->setOffsetHour($offset->hours());
     $this->setOffsetMinute($offset->minutes());
     $this->setOffsetSecond($offset->seconds());
 }
コード例 #2
0
 /**
  * Test the methods.
  */
 function test_yesterday()
 {
     $parser = new KeywordStringParser('yesterday');
     $this->assertTrue($parser->canHandle());
     $date = Date::yesterday();
     $dateAndTime = $date->start();
     $offset = $dateAndTime->offset();
     $this->assertEqual($parser->year(), $dateAndTime->year());
     $this->assertEqual($parser->month(), $dateAndTime->month());
     $this->assertEqual($parser->day(), $dateAndTime->dayOfMonth());
     $this->assertEqual($parser->hour(), 0);
     $this->assertEqual($parser->minute(), 0);
     $this->assertEqual($parser->second(), 0);
     $this->assertEqual($parser->offsetHour(), $offset->hours());
     $this->assertEqual($parser->offsetMinute(), $offset->minutes());
     $this->assertEqual($parser->offsetSecond(), $offset->seconds());
 }