parse() public method

Parse the string according to the pattern.
public parse ( $value, $defaultToCurrentTime = true ) : integer
return integer date time stamp
Exemplo n.º 1
0
 /**
  * Parse the pair of values into the appropriate value type.
  * @param string value one
  * @param string second value
  * @return array appropriate type of the value pair, array($value1, $value2);
  */
 protected function getComparisonValues($value1, $value2)
 {
     switch ($this->getDataType()) {
         case TValidationDataType::Integer:
             return array(intval($value1), intval($value2));
         case TValidationDataType::Float:
             return array(floatval($value1), floatval($value2));
         case TValidationDataType::Date:
             $dateFormat = $this->getDateFormat();
             if ($dateFormat !== '') {
                 $formatter = new TSimpleDateFormatter($dateFormat);
                 return array($formatter->parse($value1), $formatter->parse($value2));
             } else {
                 return array(strtotime($value1), strtotime($value2));
             }
     }
     return array($value1, $value2);
 }
Exemplo n.º 2
0
 public function testMissingYearPattern()
 {
     $formatter = new TSimpleDateFormatter("MM/dd");
     self::assertEquals(date("Y-10-22"), date('Y-m-d', $formatter->parse("10/22")));
 }
Exemplo n.º 3
0
 /**
  * Gets the date from the text input using TSimpleDateFormatter
  * @return integer current selected date timestamp
  */
 protected function getTimeStampFromText()
 {
     $pattern = $this->getDateFormat();
     $pattern = str_replace(array('MMMM', 'MMM'), array('MM', 'MM'), $pattern);
     $formatter = new TSimpleDateFormatter($pattern);
     return $formatter->parse($this->getText());
 }
Exemplo n.º 4
0
 /**
  * Determine if the date is within the specified range.
  * Uses pradoParseDate and strtotime to get the date from string.
  * @param string date as string to validate
  * @return boolean true if within range.
  */
 protected function isValidDate($value)
 {
     $minValue = $this->getMinValue();
     $maxValue = $this->getMaxValue();
     $valid = true;
     $dateFormat = $this->getDateFormat();
     if ($dateFormat !== '') {
         $formatter = new TSimpleDateFormatter($dateFormat);
         $value = $formatter->parse($value);
         if ($minValue !== '') {
             $valid = $valid && $this->isGreaterThan($value, $formatter->parse($minValue));
         }
         if ($maxValue !== '') {
             $valid = $valid && $this->isLessThan($value, $formatter->parse($maxValue));
         }
         return $valid;
     } else {
         $value = strtotime($value);
         if ($minValue !== '') {
             $valid = $valid && $this->isGreaterThan($value, strtotime($minValue));
         }
         if ($maxValue !== '') {
             $valid = $valid && $this->isLessThan($value, strtotime($maxValue));
         }
         return $valid;
     }
 }