PluginProbe ʕ •ᴥ•ʔ
WP Popular Posts / 5.2.2
WP Popular Posts v5.2.2
4.0.8 4.0.9 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 5.0.0 5.0.1 5.0.2 5.1.0 5.2.0 5.2.1 5.2.2 5.2.3 5.2.4 5.3.0 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.3.6 5.4.0 5.4.1 5.4.2 5.5.0 5.5.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.1.2 6.1.3 6.1.4 6.2.0 6.2.1 6.3.0 6.3.1 6.3.2 6.3.3 6.3.4 6.4.0 6.4.1 6.4.2 7.0.0 7.0.1 7.1.0 7.2.0 7.3.0 7.3.1 7.3.2 7.3.3 7.3.4 7.3.5 7.3.6 7.3.7 7.3.8 7.4.0 trunk 2.3.7 3.0.0 3.0.1 3.0.2 3.0.3 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.2 4.0.3 4.0.5 4.0.6
wordpress-popular-posts / src / Moment / MomentHelper.php
wordpress-popular-posts / src / Moment Last commit date
CustomFormats 5 years ago Locales 5 years ago FormatsInterface.php 5 years ago LICENSE.md 5 years ago Moment.php 5 years ago MomentException.php 5 years ago MomentFromVo.php 5 years ago MomentHelper.php 5 years ago MomentLocale.php 5 years ago MomentPeriodVo.php 5 years ago
MomentHelper.php
70 lines
1 <?php
2
3 namespace WordPressPopularPosts\Moment;
4
5 /**
6 * MomentHelper
7 * @package Moment
8 * @author Tino Ehrich (tino@bigpun.me)
9 */
10 class MomentHelper
11 {
12 /**
13 * @param $quarter
14 * @param $year
15 * @param string $timeZoneString
16 *
17 * @return MomentPeriodVo
18 * @throws MomentException
19 */
20 public static function getQuarterPeriod($quarter, $year, $timeZoneString = 'UTC')
21 {
22 switch ($quarter)
23 {
24 case 1:
25 $startMonth = 1;
26 $endMonth = 3;
27 break;
28 case 2:
29 $startMonth = 4;
30 $endMonth = 6;
31 break;
32 case 3:
33 $startMonth = 7;
34 $endMonth = 9;
35 break;
36 case 4:
37 $startMonth = 10;
38 $endMonth = 12;
39 break;
40 default:
41 throw new MomentException('Invalid quarter. The range of quarters is 1 - 4. You asked for: ' . $quarter);
42 }
43
44 // set start
45 $start = new Moment();
46 $start
47 ->setTimezone($timeZoneString)
48 ->setYear($year)
49 ->setMonth($startMonth)
50 ->setDay(1)
51 ->setTime(0, 0, 0);
52
53 // set end
54 $end = new Moment();
55 $end
56 ->setTimezone($timeZoneString)
57 ->setYear($year)
58 ->setMonth($endMonth)
59 ->setDay($end->format('t'))
60 ->setTime(23, 59, 59);
61
62 // set period vo
63 $momentPeriodVo = new MomentPeriodVo();
64
65 return $momentPeriodVo
66 ->setInterval($quarter)
67 ->setStartDate($start)
68 ->setEndDate($end);
69 }
70 }