eZ\Publish\Core\FieldType\Time\Value::fromDateTime PHP Method

fromDateTime() public static method

Creates a Value from the given $dateTime.
public static fromDateTime ( DateTime $dateTime ) : Value
$dateTime DateTime
return Value
    public static function fromDateTime(DateTime $dateTime)
    {
        $dateTime = clone $dateTime;
        return new static($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp());
    }

Usage Example

Example #1
0
 /**
  * {@inheritDoc}
  *
  * @return TimeValue
  */
 public function convertFieldValueFromForm($data)
 {
     if ($data instanceof DateTime) {
         return TimeValue::fromDateTime($data);
     }
     if (is_int($data)) {
         return new TimeValue($data);
     }
     return new TimeValue(null);
 }
All Usage Examples Of eZ\Publish\Core\FieldType\Time\Value::fromDateTime