1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
datetime.php
См. документацию.
1
<?php
2
9
10
namespace
Bitrix\Socialnetwork\Helper\UI
;
11
12
use
Bitrix\Main\Context
;
13
14
class
DateTime
15
{
16
public
static
function
getDateValue
(?\
Bitrix
\
Main
\
Type
\
DateTime
$value
=
null
): string
17
{
18
if
(
$value
===
null
)
19
{
20
return
''
;
21
}
22
23
$timestamp = static::getDateTimestamp(
$value
);
24
$format = static::getHumanDateTimeFormat($timestamp);
25
26
return
static::formatDateTime($timestamp, $format);
27
}
28
35
protected
static
function
formatDateTime
($stamp, ?
string
$format =
null
): string
36
{
37
$simple =
false
;
38
39
// accept also FORMAT_DATE and FORMAT_DATETIME as ones of the legal formats
40
if
(
41
(defined(
'FORMAT_DATE'
) && $format ===
FORMAT_DATE
)
42
|| (defined(
'FORMAT_DATETIME'
) && $format ===
FORMAT_DATETIME
))
43
{
44
$format = \CDatabase::dateFormatToPHP($format);
45
$simple =
true
;
46
}
47
48
$default = static::getDateTimeFormat();
49
if
($format ===
false
)
50
{
51
$format = $default;
52
$simple =
true
;
53
}
54
55
if
($simple)
56
{
57
// its a simple format, we can use a simpler function
58
return
date($format, $stamp);
59
}
60
61
return
FormatDate
($format, $stamp);
62
}
63
64
protected
static
function
getDateTimeFormat
()
65
{
66
$format = (defined(
'FORMAT_DATETIME'
) ?
FORMAT_DATETIME
: \CSite::getDateFormat());
67
68
return \CDatabase::dateFormatToPHP($format);
69
}
70
75
protected
static
function
getDateTimestamp
(\
Bitrix
\
Main
\
Type
\
DateTime
$date): int
76
{
77
$timestamp =
MakeTimeStamp
($date);
78
79
if
($timestamp ===
false
)
80
{
81
$timestamp = strtotime($date);
82
if
($timestamp !==
false
)
83
{
84
$timestamp += \CTimeZone::getOffset() -
\Bitrix\Main\Type\DateTime::createFromTimestamp
($timestamp)->getSecondGmt();
85
}
86
}
87
88
return
$timestamp;
89
}
90
91
protected
static
function
getHumanDateTimeFormat
(
int
$timestamp): string
92
{
93
$dateFormat = static::getHumanDateFormat($timestamp);
94
$timeFormat = static::getHumanTimeFormat($timestamp);
95
96
return
$dateFormat . ($timeFormat ?
", {$timeFormat}"
:
''
);
97
}
98
99
protected
static
function
getHumanDateFormat
(
int
$timestamp): string
100
{
101
$culture
= Context::getCurrent()->getCulture();
102
103
if
(date(
'Y'
) !== date(
'Y'
, $timestamp))
104
{
105
return
$culture
->getLongDateFormat();
106
}
107
108
return
$culture
->getDayMonthFormat();
109
}
110
111
protected
static
function
getHumanTimeFormat
(
int
$timestamp): string
112
{
113
$timeFormat =
''
;
114
$culture
= Context::getCurrent()->getCulture();
115
116
if
(date(
'Hi'
, $timestamp) > 0)
117
{
118
$timeFormat =
$culture
->getShortTimeFormat();
119
}
120
121
return
$timeFormat;
122
}
123
124
}
Bitrix\Main\Type\Date\$value
$value
Определения
date.php:11
Bitrix\Main\Type\DateTime
Определения
datetime.php:9
Bitrix\Main\Type\DateTime\createFromTimestamp
static createFromTimestamp($timestamp)
Определения
datetime.php:246
Bitrix\Socialnetwork\Helper\UI\DateTime\getHumanDateTimeFormat
static getHumanDateTimeFormat(int $timestamp)
Определения
datetime.php:91
Bitrix\Socialnetwork\Helper\UI\DateTime\getHumanDateFormat
static getHumanDateFormat(int $timestamp)
Определения
datetime.php:99
Bitrix\Socialnetwork\Helper\UI\DateTime\getDateTimeFormat
static getDateTimeFormat()
Определения
datetime.php:64
Bitrix\Socialnetwork\Helper\UI\DateTime\getDateTimestamp
static getDateTimestamp(\Bitrix\Main\Type\DateTime $date)
Определения
datetime.php:75
Bitrix\Socialnetwork\Helper\UI\DateTime\getHumanTimeFormat
static getHumanTimeFormat(int $timestamp)
Определения
datetime.php:111
Bitrix\Socialnetwork\Helper\UI\DateTime\getDateValue
static getDateValue(?\Bitrix\Main\Type\DateTime $value=null)
Определения
datetime.php:16
Bitrix\Socialnetwork\Helper\UI\DateTime\formatDateTime
static formatDateTime($stamp, ?string $format=null)
Определения
datetime.php:35
FORMAT_DATETIME
const FORMAT_DATETIME
Определения
include.php:64
FORMAT_DATE
const FORMAT_DATE
Определения
include.php:63
$culture
$culture
Определения
include.php:61
FormatDate
FormatDate($format="", $timestamp=false, $now=false, ?string $languageId=null)
Определения
tools.php:871
MakeTimeStamp
MakeTimeStamp($datetime, $format=false)
Определения
tools.php:538
Bitrix\Main\Context
Определения
culture.php:9
Bitrix\Main\Type
Определения
collection.php:2
Bitrix\Main
Bitrix\Socialnetwork\Helper\UI
Определения
datetime.php:10
Bitrix
bitrix
modules
socialnetwork
lib
helper
ui
datetime.php
Создано системой
1.14.0