1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: ignatenkov |
5
|
|
|
* Date: 21.08.15 |
6
|
|
|
* Time: 1:28 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace YaWeather\Models; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Day{ |
13
|
|
|
|
14
|
|
|
const TYPE_MORNING = 1; |
15
|
|
|
const TYPE_DAY = 2; |
16
|
|
|
const TYPE_EVENING = 3; |
17
|
|
|
const TYPE_NIGHT = 4; |
18
|
|
|
const TYPE_DAY_SHORT = 5; |
19
|
|
|
const TYPE_NIGHT_SHORT = 6; |
20
|
|
|
|
21
|
|
|
const HOUR_NIGHT = 6; |
22
|
|
|
const HOUR_MORNING = 12; |
23
|
|
|
const HOUR_DAY = 18; |
24
|
|
|
const HOUR_EVENING = 23; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
public $sunrise; |
28
|
|
|
public $sunset; |
29
|
|
|
public $moon_phase; |
30
|
|
|
|
31
|
|
|
public $morning; |
32
|
|
|
public $day; |
33
|
|
|
public $evening; |
34
|
|
|
public $night; |
35
|
|
|
public $day_short; |
36
|
|
|
public $night_short; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* |
40
|
|
|
* @param $value |
41
|
|
|
* @param bool $weekend |
42
|
|
|
* @return bool |
43
|
|
|
*/ |
44
|
|
|
public static function CheckWeekend($value, $weekend = false) |
45
|
|
|
{ |
46
|
|
|
$dayNumber = date('w', strtotime($value)); |
47
|
|
|
if($weekend && ($dayNumber == 0 || $dayNumber == 6)) |
48
|
|
|
return true; |
49
|
|
|
elseif ($weekend == false && $dayNumber == 0) |
|
|
|
|
50
|
|
|
return true; |
51
|
|
|
else |
52
|
|
|
return false; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public static function getDayNumber($value) { |
56
|
|
|
return $str = date('j', strtotime($value)); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public static function getMonthName($value) { |
60
|
|
|
$listMonths = ['','января','февраля','марта','апреля','мая','июня','июля','августа','сентября','октября','ноября','декабря']; |
61
|
|
|
return $listMonths[date("n", strtotime($value))]; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public static function getDayName($value) { |
65
|
|
|
$str = ""; |
|
|
|
|
66
|
|
|
|
67
|
|
|
$listDays = ['вс','пн', 'вт', 'ср', 'чт', 'пт', 'сб']; |
68
|
|
|
|
69
|
|
|
$date = Date('d.m.Y', strtotime("+1 days")); |
70
|
|
|
$match_date = date('d.m.Y', strtotime($value)); |
71
|
|
|
|
72
|
|
|
if($date == $match_date) |
73
|
|
|
$str = "Завтра"; |
74
|
|
|
else { |
75
|
|
|
$str = $listDays[date("w", strtotime($value))]; |
76
|
|
|
|
77
|
|
|
//return $this->days[date('w', $date)].', '.(int)date('d',$date).' '.$this->months[date('n', $date)]; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
return $str; |
82
|
|
|
|
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function AdditionalState() |
86
|
|
|
{ |
87
|
|
|
$arrAdditionWeather = []; |
88
|
|
|
$hour = date("G"); |
89
|
|
View Code Duplication |
if ($hour > self::HOUR_EVENING OR $hour <= self::HOUR_NIGHT) { |
|
|
|
|
90
|
|
|
$arrAdditionWeather["Утром"] = $this->morning; |
91
|
|
|
$arrAdditionWeather["Днём"] = $this->day; |
92
|
|
|
} |
93
|
|
View Code Duplication |
if ($hour > self::HOUR_NIGHT && $hour <= self::HOUR_MORNING) { |
|
|
|
|
94
|
|
|
$arrAdditionWeather["Днём"] = $this->day; |
95
|
|
|
$arrAdditionWeather["Вечером"] = $this->evening; |
96
|
|
|
} |
97
|
|
View Code Duplication |
if ($hour > self::HOUR_MORNING && $hour <= self::HOUR_DAY) { |
|
|
|
|
98
|
|
|
$arrAdditionWeather["Вечером"] = $this->evening; |
99
|
|
|
$arrAdditionWeather["Ночью"] = $this->night; |
100
|
|
|
} |
101
|
|
View Code Duplication |
if ($hour > self::HOUR_DAY && $hour <= self::HOUR_EVENING) { |
|
|
|
|
102
|
|
|
$arrAdditionWeather["Ночью"] = $this->night; |
103
|
|
|
$arrAdditionWeather["Утром"] = $this->morning; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $arrAdditionWeather; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getListDetail() { |
110
|
|
|
return ["Утром" => $this->morning, "Днём" => $this->day, "Вечером" => $this->evening, "Ночью" => $this->night]; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
} |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.