Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
DateTime.php
1<?php
2
4
7
8class DateTime extends Param
9{
14 public function setValue($value): self
15 {
16 if ($value instanceof Main\Type\DateTime)
17 {
18 $this->value = $value;
19 }
20 elseif ($value instanceof \DateTime)
21 {
22 $this->value = Main\Type\DateTime::createFromPhp($value);
23 }
24 else
25 {
26 $this->value = Main\Type\DateTime::createFromTimestamp((int)$value);
27 }
28
29 return $this;
30 }
31
35 public function getValue(): ?Main\Type\DateTime
36 {
37 if (!empty($this->value))
38 {
39 if ($this->value instanceof Main\Type\DateTime)
40 {
41 return $this->value;
42 }
43 else
44 {
45 return Main\Type\DateTime::createFromTimestamp((int)$this->value);
46 }
47 }
48
49 return null;
50 }
51
55 public function toRestFormat(): ?string
56 {
57 if ($this->getValue() instanceof Main\Type\DateTime)
58 {
59 return $this->getValue()->format('c');
60 }
61
62 return null;
63 }
64
69 public function saveValueFilter($value)
70 {
71 if ($value instanceof Main\Type\DateTime)
72 {
73 return $value->getTimestamp();
74 }
75
76 return $value;
77 }
78
83 public function loadValueFilter($value)
84 {
85 if (!($value instanceof Main\Type\DateTime))
86 {
87 return Main\Type\DateTime::createFromTimestamp((int)$value);
88 }
89
90 return $value;
91 }
92}