1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
durationmanager.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Calendar\Core\Managers\Duration
;
4
5
use
Bitrix\Calendar\Core\Base\Date
;
6
7
class
DurationManager
8
{
9
private
const
MINUTE_LENGTH = 60;
10
private
const
HOUR_LENGTH = 60 * self::MINUTE_LENGTH;
11
private
const
DAY_LENGTH = 24 * self::HOUR_LENGTH;
12
13
private
Date
$start;
14
private
Date
$end;
15
16
public
function
__construct
(
Date
$start,
Date
$end)
17
{
18
$this->start = $start;
19
$this->end = $end;
20
}
21
26
public
function
getFormattedDuration
(): string
27
{
28
$duration = $this->
getDuration
();
29
if
(!$this->
isPositiveDuration
())
30
{
31
$result
=
FormatDate
(
'idiff'
, time(), time());
32
}
33
34
if
(empty(
$result
))
35
{
36
$result
=
''
;
37
if
($duration >= self::DAY_LENGTH)
38
{
39
$result
.=
FormatDate
(
'ddiff'
, time(), $duration + time()) .
" "
;
40
}
41
$duration = $duration % self::DAY_LENGTH;
42
if
($duration >= self::HOUR_LENGTH)
43
{
44
$result
.=
FormatDate
(
'Hdiff'
, time(), $duration + time()) .
" "
;
45
}
46
$duration = $duration % self::HOUR_LENGTH;
47
if
($duration >= self::MINUTE_LENGTH)
48
{
49
$result
.=
FormatDate
(
'idiff'
, time(), $duration + time());
50
}
51
}
52
53
return
trim(
$result
);
54
}
55
60
public
function
isPositiveDuration
(): bool
61
{
62
return
$this->
getDuration
() >= self::MINUTE_LENGTH;
63
}
64
69
public
function
getDuration
(): int
70
{
71
return
$this->calculateDuration($this->start->getTimestamp(), $this->end->getTimestamp());
72
}
73
79
private
function
calculateDuration(
int
$start
,
int
$end): int
80
{
81
return
$end -
$start
;
82
}
83
89
public
function
areDurationsEqual
(
Date
$start,
Date
$end): bool
90
{
91
return
$this->
getDuration
() === $this->calculateDuration($start->getTimestamp(), $end->getTimestamp());
92
}
93
}
Bitrix\Calendar\Core\Managers\Duration\DurationManager
Определения
durationmanager.php:8
Bitrix\Calendar\Core\Managers\Duration\DurationManager\getFormattedDuration
getFormattedDuration()
Определения
durationmanager.php:26
Bitrix\Calendar\Core\Managers\Duration\DurationManager\isPositiveDuration
isPositiveDuration()
Определения
durationmanager.php:60
Bitrix\Calendar\Core\Managers\Duration\DurationManager\__construct
__construct(Date $start, Date $end)
Определения
durationmanager.php:16
Bitrix\Calendar\Core\Managers\Duration\DurationManager\getDuration
getDuration()
Определения
durationmanager.php:69
Bitrix\Calendar\Core\Managers\Duration\DurationManager\areDurationsEqual
areDurationsEqual(Date $start, Date $end)
Определения
durationmanager.php:89
Bitrix\Main\Type\Date
Определения
date.php:9
$result
$result
Определения
get_property_values.php:14
$start
$start
Определения
get_search.php:9
FormatDate
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
Определения
tools.php:871
Bitrix\Calendar\Core\Managers\Duration
Определения
durationmanager.php:3
bitrix
modules
calendar
lib
core
managers
duration
durationmanager.php
Создано системой
1.14.0