Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
datetime.php
1<?php
2
4
6
7class DateTime extends Date
8{
9 public function __construct($dateFormatted = null, $offset = 0)
10 {
11 $offset = (int) $offset;
12
13 if ($dateFormatted === null)
14 {
15 $this->timestamp = time();
16 }
17 elseif (is_numeric($dateFormatted))
18 {
19 $this->timestamp = (int) $dateFormatted;
20 }
21 else
22 {
23 if (preg_match(static::SERIALIZED_PATTERN, $dateFormatted, $matches))
24 {
25 $dateFormatted = $matches[1];
26 $offset = (int) $matches[2];
27 }
28
29 try
30 {
31 $datetime = new Main\Type\DateTime($dateFormatted);
32 $this->checkYear($datetime);
33
34 $this->timestamp = $datetime->getTimestamp() - $offset;
35 }
36 catch (Main\ObjectException $exception)
37 {
38 try
39 {
40 $this->timestamp = (new Main\Type\DateTime($dateFormatted, DATE_ISO8601))->getTimestamp() - $offset;
41 }
42 catch (Main\ObjectException $exception)
43 {
44 $this->timestamp = null;
45 }
46 }
47 }
48
49 $this->offset = $offset;
50 }
51
52 public function toSystemObject()
53 {
54 return Main\Type\DateTime::createFromTimestamp($this->getTimestamp());
55 }
56
57 public function getFormat()
58 {
59 return Main\Type\DateTime::getFormat();
60 }
61}
checkYear(Main\Type\Date $date)
Definition date.php:101
__construct($dateFormatted=null, $offset=0)
Definition datetime.php:9