/** * {@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); }
/** * Inspects given $inputValue and potentially converts it into a dedicated value object. * * @param string|int|\DateTime|\eZ\Publish\Core\FieldType\Time\Value $inputValue * * @return \eZ\Publish\Core\FieldType\Time\Value The potentially converted and structurally plausible value. */ protected function createValueFromInput($inputValue) { if (is_string($inputValue)) { $inputValue = Value::fromString($inputValue); } if (is_int($inputValue)) { $inputValue = Value::fromTimestamp($inputValue); } if ($inputValue instanceof DateTime) { $inputValue = Value::fromDateTime($inputValue); } return $inputValue; }
/** * Data provider for valid input to acceptValue(). * * Returns an array of data provider sets with 2 arguments: 1. The valid * input to acceptValue(), 2. The expected return value from acceptValue(). * For example: * * <code> * return array( * array( * null, * null * ), * array( * __FILE__, * new BinaryFileValue( array( * 'path' => __FILE__, * 'fileName' => basename( __FILE__ ), * 'fileSize' => filesize( __FILE__ ), * 'downloadCount' => 0, * 'mimeType' => 'text/plain', * ) ) * ), * // ... * ); * </code> * * @return array */ public function provideValidInputForAcceptValue() { $dateTime = new DateTime(); $secondsInDay = 24 * 60 * 60; return array(array(null, new TimeValue()), array('2012-08-28 12:20', new TimeValue(44400)), array('2012-08-28 12:20 Europe/Berlin', new TimeValue(44400)), array('2012-08-28 12:20 Asia/Sakhalin', new TimeValue(44400)), array($dateTime->setTimestamp(1372896001)->getTimestamp(), new TimeValue(($secondsInDay + $dateTime->getOffset() + 1) % $secondsInDay)), array(TimeValue::fromTimestamp($timestamp = 1346149200), new TimeValue($dateTime->setTimestamp($timestamp)->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp())), array(clone $dateTime, new TimeValue($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp()))); }
/** * Get data to test to hash method * * This is a PHPUnit data provider * * The returned records must have the the original value assigned to the * first index and the expected hash result to the second. For example: * * <code> * array( * array( * new MyValue( true ), * array( 'myValue' => true ), * ), * // ... * ); * </code> * * @return array */ public function provideToHashData() { $dateTime = new DateTime(); return array(array(TimeValue::fromTimestamp(123456), $dateTime->setTimestamp(123456)->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp())); }