Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
datetimepropertytype.php
1<?php
2
3
5
8
10{
11 private $dateTime;
12 private $withTime;
13 private $withTimezone;
14 private $isUTC;
15
16 public static function getInstance(
17 $names,
18 Date $dateTime,
19 bool $withTime = false,
20 bool $withTimezone = false,
21 bool $isUTC = false
22 ): DateTimePropertyType
23 {
24 return new self($names, $dateTime, $withTime, $withTimezone, $isUTC);
25 }
26
27 public function __construct(
28 $names,
29 Date $dateTime,
30 bool $withTime = false,
31 bool $withTimezone = false,
32 bool $isUTC = false
33 )
34 {
35 parent::__construct($names);
36
37 $this->dateTime = $dateTime;
38 $this->withTimezone = $withTimezone;
39 $this->withTime = $withTime;
40 $this->isUTC = $isUTC;
41
42 if ($this->withTimezone && $this->dateTime instanceof DateTime)
43 {
44 $timezone = $this->dateTime->getTimezone()->getName();
45 $this->addParameter(new Parameter('TZID', $timezone));
46 }
47 elseif (!$this->withTime)
48 {
49 $this->addParameter(new Parameter('VALUE', 'DATE'));
50 }
51 }
52
53 public function getValue(): string
54 {
55 if ($this->isUTC)
56 {
57 $format = 'Ymd\THis\Z';
58 }
59 else
60 {
61 $format = $this->withTime ? 'Ymd\THis' : 'Ymd';
62 }
63
64 return $this->dateTime->format($format);
65 }
66
67 public function getOriginalValue(): Date
68 {
69 return $this->dateTime;
70 }
71}
static getInstance( $names, Date $dateTime, bool $withTime=false, bool $withTimezone=false, bool $isUTC=false)
__construct( $names, Date $dateTime, bool $withTime=false, bool $withTimezone=false, bool $isUTC=false)