1C-Bitrix
25.700.0
Загрузка...
Поиск...
Не найдено
date.php
См. документацию.
1
<?php
2
3
namespace
Bitrix\Bizproc\BaseType\Value
;
4
5
use
Bitrix\Main
;
6
7
class
Date
implements
\JsonSerializable
8
{
9
protected
$timestamp
;
10
protected
$offset
;
11
12
const
SERIALIZED_PATTERN
=
'#(.+)\s\[([0-9\-]+)\]#i'
;
13
14
public
function
__construct
($dateFormatted =
null
,
$offset
= 0)
15
{
16
$offset
= (int)
$offset
;
17
18
if
($dateFormatted ===
null
)
19
{
20
$this->timestamp = (
new
Main\Type\Date
())->
getTimestamp
();
21
}
22
elseif
(is_numeric($dateFormatted))
23
{
24
$this->timestamp = (int) $dateFormatted;
25
}
26
else
27
{
28
if
(preg_match(static::SERIALIZED_PATTERN, $dateFormatted,
$matches
))
29
{
30
$dateFormatted =
$matches
[1];
31
$offset
= (int)
$matches
[2];
32
}
33
34
try
35
{
36
$date =
new
Main\Type\Date
($dateFormatted);
37
$this->
checkYear
($date);
38
39
$this->timestamp = $date->getTimestamp() -
$offset
;
40
}
41
catch
(
Main
\
ObjectException
$exception)
42
{
43
try
44
{
45
$this->timestamp = (
new
Main\Type\Date
($dateFormatted, DATE_ISO8601))->
getTimestamp
() -
$offset
;
46
}
47
catch
(
Main
\
ObjectException
$exception)
48
{
49
$this->timestamp =
null
;
50
}
51
}
52
}
53
54
$this->offset =
$offset
;
55
}
56
57
public
function
getTimestamp
()
58
{
59
return
$this->timestamp;
60
}
61
62
public
function
getOffset
()
63
{
64
return
$this->offset;
65
}
66
67
public
function
__toString
()
68
{
69
return
date($this->
getFormat
(), $this->
getTimestamp
() + $this->offset);
70
}
71
72
public
static
function
fromSystemObject
(
Main
\
Type
\
Date
$date)
73
{
74
return
new
static
($date->getTimestamp());
75
}
76
77
public
function
toSystemObject
()
78
{
79
return
Main\Type\Date::createFromTimestamp
($this->
getTimestamp
() + $this->offset);
80
}
81
82
public
function
serialize
()
83
{
84
return
sprintf(
'%s [%d]'
, $this->
__toString
(), $this->offset);
85
}
86
87
public
static
function
isSerialized
($dateString)
88
{
89
if
(is_string($dateString) && preg_match(static::SERIALIZED_PATTERN, $dateString))
90
{
91
return
true
;
92
}
93
return
false
;
94
}
95
96
public
function
getFormat
()
97
{
98
return
Main\Type\Date::getFormat
();
99
}
100
101
protected
function
checkYear
(
Main
\
Type
\
Date
$date)
102
{
103
if
($date->getTimestamp() < 0)
104
{
105
$y = (int) $date->format(
'Y'
);
106
$m = (int) $date->format(
'm'
);
107
$d = (int) $date->format(
'd'
);
108
if
(0 <= $y && $y <= 69)
109
{
110
$y += 2000;
111
$date->setDate($y, $m, $d);
112
}
113
elseif
(70 <= $y && $y <= 100)
114
{
115
$y += 1900;
116
$date->setDate($y, $m, $d);
117
}
118
}
119
}
120
121
public
function
jsonSerialize
()
122
{
123
return
$this->
serialize
();
124
}
125
}
Bitrix\Bizproc\BaseType\Value\Date\checkYear
checkYear(Main\Type\Date $date)
Определения
date.php:101
Bitrix\Bizproc\BaseType\Value\Date\$timestamp
$timestamp
Определения
date.php:9
Bitrix\Bizproc\BaseType\Value\Date\toSystemObject
toSystemObject()
Определения
date.php:77
Bitrix\Bizproc\BaseType\Value\Date\isSerialized
static isSerialized($dateString)
Определения
date.php:87
Bitrix\Bizproc\BaseType\Value\Date\fromSystemObject
static fromSystemObject(Main\Type\Date $date)
Определения
date.php:72
Bitrix\Bizproc\BaseType\Value\Date\serialize
serialize()
Определения
date.php:82
Bitrix\Bizproc\BaseType\Value\Date\__toString
__toString()
Определения
date.php:67
Bitrix\Bizproc\BaseType\Value\Date\SERIALIZED_PATTERN
const SERIALIZED_PATTERN
Определения
date.php:12
Bitrix\Bizproc\BaseType\Value\Date\getTimestamp
getTimestamp()
Определения
date.php:57
Bitrix\Bizproc\BaseType\Value\Date\jsonSerialize
jsonSerialize()
Определения
date.php:121
Bitrix\Bizproc\BaseType\Value\Date\getFormat
getFormat()
Определения
date.php:96
Bitrix\Bizproc\BaseType\Value\Date\$offset
$offset
Определения
date.php:10
Bitrix\Bizproc\BaseType\Value\Date\getOffset
getOffset()
Определения
date.php:62
Bitrix\Bizproc\BaseType\Value\Date\__construct
__construct($dateFormatted=null, $offset=0)
Определения
date.php:14
Bitrix\Main\ObjectException
Определения
ObjectException.php:9
Bitrix\Main\Type\Date
Определения
date.php:9
Bitrix\Main\Type\Date\createFromTimestamp
static createFromTimestamp($timestamp)
Определения
date.php:402
Bitrix\Main\Type\Date\getFormat
static getFormat(Context\Culture $culture=null)
Определения
date.php:264
Bitrix\Main\Type\Date\__toString
__toString()
Определения
date.php:252
Bitrix\Main\Type\Date\getTimestamp
getTimestamp()
Определения
date.php:218
Bitrix\Bizproc\BaseType\Value
Определения
date.php:3
Bitrix\Main\Type
Определения
collection.php:2
Bitrix\Main
elseif
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения
prolog_main_admin.php:393
$matches
$matches
Определения
index.php:22
bitrix
modules
bizproc
lib
basetype
value
date.php
Создано системой
1.14.0