Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
datetime.php
1<?
2
4
5
7
8
10{
12 protected $date;
13
15 protected $dateTime;
16
18 protected $timestamp;
19
20
25 public function __construct($timestamp = "")
26 {
27 $this->timestamp = $timestamp;
28
29 if (empty($this->timestamp))
30 {
31 $this->date = new MainType\Date();
32 $this->timestamp = $this->date->getTimestamp();
33 }
34
35 $this->dateTime = MainType\DateTime::createFromTimestamp($this->timestamp);
36 static::adjustTime($this->dateTime);
37 }
38
39
45 public static function adjustTime(MainType\DateTime $dateTime)
46 {
47 if(\CTimeZone::Enabled())
48 {
49 static $diff = null;
50 if($diff === null)
51 {
52 $diff = \CTimeZone::GetOffset();
53 }
54 if($diff <> 0)
55 {
56 $dateTime->add(($diff > 0? "-":"")."PT".abs($diff)."S");
57 }
58 }
59 }
60
61
62
67 public function month()
68 {
69 $date = new MainType\Date($this->toString());
70 return $date->format("n");
71 }
72
73
78 public function year()
79 {
80 $date = new MainType\Date($this->toString());
81 return $date->format("Y");
82 }
83
84
89 public function quarter()
90 {
91 $date = new MainType\Date($this->toString());
92 return Quarter::get($date);
93 }
94
95
100 public function quarterStart()
101 {
102 $startDate = Quarter::getStartDate($this->quarter(), $this->year());
103 $dateTime = MainType\DateTime::createFromTimestamp(MakeTimeStamp($startDate));
104 static::adjustTime($dateTime);
105 return $dateTime->toString();
106 }
107
108
113 public function quarterEnd()
114 {
115 $endDate = Quarter::getEndDate($this->quarter(), $this->year());
116 $dateTime = MainType\DateTime::createFromUserTime($endDate);
117 $dateTime->add("- 1 second");
118 return $dateTime->toString();
119 }
120
121
127 public function offset($offset)
128 {
129 $date = MainType\DateTime::createFromTimestamp($this->getTimestamp());
130 $date->add($offset);
131 static::adjustTime($date);
132 return $date->toString();
133 }
134
135
140 public function toString()
141 {
142 return $this->dateTime->toString();
143 }
144
145
150 public function getTimestamp()
151 {
152 return $this->timestamp;
153 }
154}
toString(Context\Culture $culture=null)
Definition datetime.php:86
static adjustTime(MainType\DateTime $dateTime)
Definition datetime.php:45