1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
datetimefield.php
См. документацию.
1<?php
8
9namespace Bitrix\Main\ORM\Fields;
10
11use Bitrix\Main\ArgumentException;
12use Bitrix\Main\ArgumentTypeException;
13use Bitrix\Main\DB\SqlExpression;
14use Bitrix\Main\Type\DateTime;
15
22{
24 protected $useTimezone = true;
25
34 public function __construct($name, $parameters = array())
35 {
36 ScalarField::__construct($name, $parameters);
37 }
38
43 public function configureUseTimezone($use = true)
44 {
45 $this->useTimezone = (bool) $use;
46
47 return $this;
48 }
49
54 public function configureDefaultValueNow(): self
55 {
56 return $this->configureDefaultValue(static fn() => new DateTime());
57 }
58
62 public function getFetchDataModifiers()
63 {
64 $modifiers = parent::getFetchDataModifiers();
65
66 if (!$this->useTimezone)
67 {
68 $modifiers[] = [__CLASS__, 'disableTimezoneFetchModifier'];
69 }
70
71 return $modifiers;
72 }
73
80 public function cast($value)
81 {
82 if ($value instanceof SqlExpression)
83 {
84 return $value;
85 }
86
87 if (!empty($value) && !($value instanceof DateTime))
88 {
89 $value = new DateTime($value);
90 }
91
92 if ($value instanceof DateTime)
93 {
94 $this->useTimezone
95 ? $value->enableUserTime()
96 : $value->disableUserTime();
97 }
98
99 return $value;
100 }
101
109 public function convertValueFromDb($value)
110 {
111 return $this->getConnection()->getSqlHelper()->convertFromDbDateTime($value);
112 }
113
121 public function convertValueToDb($value)
122 {
123 if ($value instanceof SqlExpression)
124 {
125 return $value;
126 }
127
128 try
129 {
130 return $value === null && $this->is_nullable
131 ? $value
132 : $this->getConnection()->getSqlHelper()->convertToDbDateTime($value);
133 }
134 catch (ArgumentTypeException $e)
135 {
136 $exceptionMsg = $this->entity
137 ? "Type error in `{$this->name}` of `{$this->entity->getFullName()}`"
138 : "Type error in `{$this->name}`";
139
140 throw new ArgumentException(
141 "{$exceptionMsg}: {$e->getMessage()}"
142 );
143 }
144 }
145
152 public static function disableTimezoneFetchModifier($time)
153 {
154 if ($time !== null)
155 {
156 $time->disableUserTime();
157 }
158
159 return $time;
160 }
161
165 public function getGetterTypeHint()
166 {
167 return $this->getNullableTypeHint('\\'.DateTime::class);
168 }
169
173 public function getSetterTypeHint()
174 {
175 return $this->getNullableTypeHint('\\'.DateTime::class);
176 }
177}
configureUseTimezone($use=true)
Определения datetimefield.php:43
__construct($name, $parameters=array())
Определения datetimefield.php:34
static disableTimezoneFetchModifier($time)
Определения datetimefield.php:152
getConnection()
Определения field.php:638
configureDefaultValue($value)
Определения scalarfield.php:248
__construct($name, $parameters=array())
Определения scalarfield.php:53
getNullableTypeHint(string $type)
Определения scalarfield.php:301
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$time
Определения payment.php:61