Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Core/FieldType/Time/Value.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Time;
8
9 use eZ\Publish\Core\FieldType\Value as BaseValue;
10 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue;
11 use Exception;
12 use DateTime;
13
17 class Value extends BaseValue
18 {
24 public $time;
25
31 public $stringFormat = 'H:i:s';
32
38 public function __construct($seconds = null)
39 {
40 $this->time = $seconds;
41 }
42
50 public static function fromDateTime(DateTime $dateTime)
51 {
52 $dateTime = clone $dateTime;
53
54 return new static($dateTime->getTimestamp() - $dateTime->setTime(0, 0, 0)->getTimestamp());
55 }
56
66 public static function fromString($timeString)
67 {
68 try {
69 return static::fromDateTime(new DateTime($timeString));
70 } catch (Exception $e) {
71 throw new InvalidArgumentValue('$timeString', $timeString, __CLASS__, $e);
72 }
73 }
74
84 public static function fromTimestamp($timestamp)
85 {
86 try {
87 $dateTime = new DateTime("@{$timestamp}");
88
89 return static::fromDateTime($dateTime);
90 } catch (Exception $e) {
91 throw new InvalidArgumentValue('$timestamp', $timestamp, __CLASS__, $e);
92 }
93 }
94
98 public function __toString()
99 {
100 if ($this->time === null) {
101 return '';
102 }
103
104 $dateTime = new DateTime("@{$this->time}");
105
106 return $dateTime->format($this->stringFormat);
107 }
108 }
eZ\Publish\API\Repository\Values\Content\Query\Criterion\Value
Struct that stores extra value information for a Criterion object.
Definition: API/Repository/Values/Content/Query/Criterion/Value.php:13
eZ\Publish\Core\Base\Exceptions\InvalidArgumentValue
Invalid Argument Type Exception implementation.
Definition: Base/Exceptions/InvalidArgumentValue.php:17
eZ\Publish\Core\FieldType\Time\Value\$stringFormat
$stringFormat
Definition: Core/FieldType/Time/Value.php:31
eZ\Publish\Core\FieldType\Time\Value\__toString
__toString()
Definition: Core/FieldType/Time/Value.php:98
eZ\Publish\Core\FieldType\Time\Value\__construct
__construct($seconds=null)
Construct a new Value object and initialize it with $seconds as number of seconds from beginning of d...
Definition: Core/FieldType/Time/Value.php:38
eZ\Publish\Core\FieldType\Time\Value\fromTimestamp
static fromTimestamp($timestamp)
Creates a Value from the given $timestamp.
Definition: Core/FieldType/Time/Value.php:84
eZ\Publish\Core\FieldType\Time\Value\$time
$time
Definition: Core/FieldType/Time/Value.php:24
eZ\Publish\Core\FieldType\Time\Value\fromString
static fromString($timeString)
Creates a Value from the given $timeString.
Definition: Core/FieldType/Time/Value.php:66
eZ\Publish\Core\FieldType\Time\Value\fromDateTime
static fromDateTime(DateTime $dateTime)
Creates a Value from the given $dateTime.
Definition: Core/FieldType/Time/Value.php:50
eZ\Publish\Core\FieldType\Value
Abstract class for all field value classes.
Definition: Core/FieldType/Value.php:17
eZ\Publish\Core\FieldType\Time
Definition: Time/SearchField.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.