/**
  * 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()
 {
     preg_match(self::getRegex(), $this->input, $timeMatches);
     $timeComponent = $timeMatches[0];
     // The date is anything before the time
     $dateComponent = trim(str_replace($timeComponent, '', $this->input));
     $timeParser = new TimeStringParser($timeComponent);
     $dateParser = StringParser::getParserFor($dateComponent);
     // Merge the two results into our fields
     if ($dateParser) {
         $this->setYear($dateParser->year());
         $this->setMonth($dateParser->month());
         $this->setDay($dateParser->day());
     }
     $this->setHour($timeParser->hour());
     $this->setMinute($timeParser->minute());
     $this->setSecond($timeParser->second());
     if (!is_null($timeParser->offsetHour())) {
         $this->setOffsetHour($timeParser->offsetHour());
     }
     if (!is_null($timeParser->offsetMinute())) {
         $this->setOffsetMinute($timeParser->offsetMinute());
     }
     if (!is_null($timeParser->offsetSecond())) {
         $this->setOffsetSecond($timeParser->offsetSecond());
     }
 }
 /**
  * Returns true if this component (and all child components if applicable) have valid values.
  * By default, this will just return TRUE. Validate should be called usually before a save event
  * is handled, to make sure everything went smoothly. 
  * @access public
  * @return boolean
  */
 function validate()
 {
     $parse = StringParser::getParserFor($this->_value);
     if (!$parse) {
         $this->_showError = true;
         return false;
     }
     return true;
 }
Esempio n. 3
0
    /**
     * Read a Time from the stream in the forms:
     *		- <hour24>:<minute>:<second>
     *		- <hour>:<minute>:<second> <am/pm>
     *		- <minute>, <second> or <am/pm> may be omitted.  e.g. 1:59:30 pm; 8AM; 15:30
     * 
     * @param string $aString
     * @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 Time
     * @access public
     * @static
     * @since 5/24/05
     */
    static function fromString($aString, $class = 'Time')
    {
        $parser = StringParser::getParserFor($aString);
        if (!is_string($aString) || !preg_match('/[^\\W]/', $aString) || !$parser) {
            $null = null;
            return $null;
            // die("'".$aString."' is not in a valid format.");
        }
        eval('$result = ' . $class . '::withHourMinuteSecond($parser->hour(),
						$parser->minute(), $parser->second(), $class);');
        return $result;
    }
Esempio n. 4
0
    /**
     * Read a month from the stream in any of the forms:
     *
     *		- July 1998
     * 
     * @param string $aString
     * @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/10/05
     * @static
     */
    static function fromString($aString, $class = 'Month')
    {
        $parser = StringParser::getParserFor($aString);
        if (!is_string($aString) || !preg_match('/[^\\W]/', $aString) || !$parser) {
            $null = null;
            return $null;
            // die("'".$aString."' is not in a valid format.");
        }
        eval('$result = ' . $class . '::withMonthYear($parser->month(), 
					$parser->year(), $class);');
        return $result;
    }
Esempio n. 5
0
    /**
     * Answer a new instance represented by a string:
     * 
     *	- '-1199-01-05T20:33:14.321-05:00' 
     *	- ' 2002-05-16T17:20:45.00000001+01:01' 
     *	- ' 2002-05-16T17:20:45.00000001' 
     *	- ' 2002-05-16T17:20' 
     *	- ' 2002-05-16T17:20:45' 
     *	- ' 2002-05-16T17:20:45+01:57' 
     *	- ' 2002-05-16T17:20:45-02:34' 
     *	- ' 2002-05-16T17:20:45+00:00' 
     *	- ' 1997-04-26T01:02:03+01:02:3'  
     *
     * @param string $aString The input string.
     * @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 DateAndTime
     * @access public
     * @since 5/12/05
     * @static
     */
    static function fromString($aString, $class = 'DateAndTime')
    {
        $parser = StringParser::getParserFor($aString);
        if (!is_string($aString) || !preg_match('/[^\\W]/', $aString) || !$parser) {
            $null = null;
            return $null;
            // die("'".$aString."' is not in a valid format.");
        }
        if (!is_null($parser->offsetHour())) {
            eval('$result = ' . $class . '::withYearMonthDayHourMinuteSecondOffset(
				$parser->year(), $parser->month(), $parser->day(), $parser->hour(),
				$parser->minute(), $parser->second(), 
				Duration::withDaysHoursMinutesSeconds(0, $parser->offsetHour(),
				$parser->offsetMinute(), $parser->offsetSecond()), $class);');
        } else {
            if (!is_null($parser->hour())) {
                eval('$result = ' . $class . '::withYearMonthDayHourMinuteSecond(
				$parser->year(), $parser->month(), $parser->day(), $parser->hour(),
				$parser->minute(), $parser->second(), $class);');
            } else {
                eval('$result = ' . $class . '::withYearMonthDay(
				$parser->year(), $parser->month(), $parser->day(), $class);');
            }
        }
        return $result;
    }