Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
quarter.php
1<?
2
4
6
7
13{
14 const Q1 = 1;
15 const Q2 = 2;
16 const Q3 = 3;
17 const Q4 = 4;
18 const Q1_START = 1;
19 const Q1_END = 3;
20 const Q2_START = 4;
21 const Q2_END = 6;
22 const Q3_START = 7;
23 const Q3_END = 9;
24 const Q4_START = 10;
25 const Q4_END = 12;
26
27
32 public static function getCurrent()
33 {
34 $date = new Date();
35 return self::get($date);
36 }
37
38
44 public static function get(Date $date)
45 {
46 $currentMonth = $date->format("n");
47 $currentQuarter = self::Q1;
48
49 if ($currentMonth >= self::Q2_START && $currentMonth <= self::Q2_END)
50 {
51 $currentQuarter = self::Q2;
52 }
53
54 if ($currentMonth >= self::Q3_START && $currentMonth <= self::Q3_END)
55 {
56 $currentQuarter = self::Q3;
57 }
58
59 if ($currentMonth >= self::Q4_START && $currentMonth <= self::Q4_END)
60 {
61 $currentQuarter = self::Q4;
62 }
63
64 return $currentQuarter;
65 }
66
67
74 public static function getStartDate($quarter, $year)
75 {
76 $startMonth = constant("self::Q".$quarter."_START");
77 $startDate = Date::createFromTimestamp(mktime(0, 0, 0, $startMonth, 1, $year));
78 $startDateString = $startDate->toString();
79
80 return $startDateString;
81 }
82
83
90 public static function getEndDate($quarter, $year)
91 {
92 $date = Date::createFromTimestamp(\MakeTimeStamp(self::getStartDate($quarter, $year)));
93 $date->add("3 months");
94 return $date->toString();
95 }
96}
static get(Date $date)
Definition quarter.php:44
static getStartDate($quarter, $year)
Definition quarter.php:74
static getEndDate($quarter, $year)
Definition quarter.php:90