eZ\Publish\Core\FieldType\Date\Value::fromString PHP Method

fromString() public static method

Creates a Value from the given $dateString.
public static fromString ( string $dateString ) : Value
$dateString string
return Value
    public static function fromString($dateString)
    {
        try {
            return new static(new DateTime($dateString));
        } catch (Exception $e) {
            throw new InvalidArgumentValue('$dateString', $dateString, __CLASS__, $e);
        }
    }

Usage Example

 /**
  * Get hashes and their respective converted values.
  *
  * This is a PHPUnit data provider
  *
  * The returned records must have the the input hash assigned to the
  * first index and the expected value result to the second. For example:
  *
  * <code>
  * array(
  *      array(
  *          array( 'myValue' => true ),
  *          new MyValue( true ),
  *      ),
  *      // ...
  * );
  * </code>
  *
  * @return array
  */
 public function provideFromHashData()
 {
     $dateTime = new DateTime();
     return array(array(array('timestamp' => $dateTime->setTimestamp(123456)->setTime(0, 0, 0)->getTimestamp(), 'rfc850' => $rfc850 = $dateTime->format(DateTime::RFC850)), DateValue::fromString($rfc850)), array(array('timestamp' => $dateTime->setTimestamp($timestamp = 123456)->setTime(0, 0, 0)->getTimestamp(), 'rfc850' => null), DateValue::fromTimestamp($timestamp)));
 }
All Usage Examples Of eZ\Publish\Core\FieldType\Date\Value::fromString