Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
observance.php
1<?php
2
3
5
6
9use DateTimeZone;
10
11abstract class Observance extends BasicComponent
12{
13 protected $start;
14 protected $offsetFrom;
15 protected $offsetTo;
16 protected $timezone;
17
18 public static function createInstance(): Observance
19 {
20 return new static();
21 }
22
23 public function getProperties(): array
24 {
25 return [
26 'DTSTART',
27 'TZOFFSETFROM',
28 'TZOFFSETTO',
29 ];
30 }
31
36 public function setDTStart($start = null): Observance
37 {
38 $this->start = $start ? $start : Helper::getIcalDateTimeShort('19700101T000000');
39
40 return $this;
41 }
42
47 public function setOffsetFrom(DateTimeZone $tz): Observance
48 {
49 $time = Util::getDateObject(null, false, $tz->getName());
50 $this->offsetFrom = $time->format('O');
51
52 return $this;
53 }
54
55 public function setOffsetFromValue(string $value): Observance
56 {
57 $this->offsetFrom = $value;
58 return $this;
59 }
60
65 public function setOffsetTo(DateTimeZone $tz): Observance
66 {
67 $time = Util::getDateObject(null, false, $tz->getName());
68 $this->offsetTo = $time->format('O');
69 return $this;
70 }
71
72 public function setOffsetToValue(string $value): Observance
73 {
74 $this->offsetTo = $value;
75 return $this;
76 }
77
78 public function setAbbrTimezone($tz): Observance
79 {
80 $exp = (new \DateTime($tz))->format('T');
81 $this->timezone = (new \DateTime())->setTimeZone(new DateTimeZone($tz))->format('T');
82 return $this;
83 }
84
85 public function setTimezoneFromAbbr(?string $abbr): Observance
86 {
87 $this->timezone = $abbr;
88 return $this;
89 }
90
91 public function setContent(): Content
92 {
93 return Content::getInstance($this->getType())
94 ->dateTimeProperty('DTSTART', $this->start, true, false)
95 ->textProperty('TZOFFSETFROM', $this->offsetFrom)
96 ->textProperty('TZOFFSETTO', $this->offsetTo)
97 ->textProperty('TZNAME', $this->timezone);
98 }
99}
static getInstance(string $type)
Definition content.php:13
dateTimeProperty( $names, Date $value, bool $withTime=false, bool $withTimeZone=false, bool $isUTC=false)
Definition content.php:32
static getIcalDateTimeShort(string $dateTime=null, string $tz='UTC')
Definition helper.php:761
static getDateObject(string $date=null, ?bool $fullDay=true, ?string $tz='UTC')
Definition util.php:102