Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
lengthpropertytype.php
1<?php
2
3
5
6
8{
9 private $interval;
10
11 public static function getInstance($names, \DateInterval $interval): LengthPropertyType
12 {
13 return new self($names, $interval);
14 }
15
16 public function invert(): LengthPropertyType
17 {
18 $this->interval->invert = 1;
19
20 return $this;
21 }
22
29 public function __construct($names, \DateInterval $interval)
30 {
31 parent::__construct($names);
32
33 $this->interval = $interval;
34 }
35
36 public function getValue(): string
37 {
38 $value = $this->interval->invert ? '-P' : 'P';
39
40 if ($this->interval->d > 0) {
41 $value .= "{$this->interval->d}D";
42 }
43
44 if ($this->interval->s > 0 || $this->interval->i > 0 || $this->interval->h > 0) {
45 $value .= 'T';
46 }
47
48 if ($this->interval->h > 0) {
49 $value .= "{$this->interval->h}H";
50 }
51
52 if ($this->interval->i > 0) {
53 $value .= "{$this->interval->i}M";
54 }
55
56 if ($this->interval->s > 0) {
57 $value .= "{$this->interval->s}S";
58 }
59
60 return $value;
61 }
62
63 public function getOriginalValue(): \DateInterval
64 {
65 return $this->interval;
66 }
67}
__construct($names, \DateInterval $interval)
static getInstance($names, \DateInterval $interval)