1 | <?php |
||
5 | abstract class Season |
||
6 | { |
||
7 | const WINTER = 'winter'; |
||
8 | const SPRING = 'spring'; |
||
9 | const SUMMER = 'summer'; |
||
10 | const FALL = 'fall'; |
||
11 | |||
12 | 31 | public static function getSeason(DateTime $dateTime) |
|
13 | { |
||
14 | return [ |
||
15 | 31 | 'season' => self::getCurrentSeason((int)$dateTime->format('n')), |
|
16 | 31 | 'year' => (int)$dateTime->format('Y'), |
|
17 | ]; |
||
18 | } |
||
19 | |||
20 | 31 | public static function getCurrentSeason($month = null) |
|
21 | { |
||
22 | 31 | if ($month === null) { |
|
23 | 29 | $month = Carbon::now()->month; |
|
24 | } |
||
25 | |||
26 | 31 | if (1 <= $month && $month <= 3) { |
|
27 | return self::WINTER; |
||
28 | 31 | } elseif (4 <= $month && $month <= 6) { |
|
29 | return self::SPRING; |
||
30 | 31 | } elseif (7 <= $month && $month <= 9) { |
|
31 | 31 | return self::SUMMER; |
|
32 | } |
||
33 | |||
34 | return self::FALL; |
||
35 | } |
||
36 | |||
37 | 30 | public static function getCurrentSeasonRange($season = null) |
|
38 | { |
||
39 | 30 | if ($season === null) { |
|
40 | $season = self::getCurrentSeason(); |
||
41 | } |
||
42 | |||
43 | switch ($season) { |
||
44 | 30 | case self::WINTER: |
|
45 | return self::getWinterSeason(); |
||
46 | |||
47 | 30 | case self::SPRING: |
|
48 | return self::getSpringSeason(); |
||
49 | |||
50 | 30 | case self::SUMMER: |
|
51 | 30 | return self::getSummerSeason(); |
|
52 | |||
53 | default: |
||
54 | return self::getFallSeason(); |
||
55 | } |
||
56 | } |
||
57 | |||
58 | public static function getWinterSeason() |
||
62 | |||
63 | public static function getSpringSeason() |
||
64 | { |
||
67 | |||
68 | 30 | public static function getSummerSeason() |
|
69 | { |
||
70 | 30 | return (new MonthDateRange('July', 'September')); |
|
71 | } |
||
72 | |||
73 | public static function getFallSeason() |
||
77 | } |
||
78 |