|
1
|
|
|
<?php namespace Datium\Tools; |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Define Day of current date. |
|
5
|
|
|
*/ |
|
6
|
|
|
class DayOf { |
|
7
|
|
|
|
|
8
|
|
|
protected $date_time; |
|
9
|
|
|
|
|
10
|
|
|
protected $month; |
|
11
|
|
|
|
|
12
|
|
|
protected $day; |
|
13
|
|
|
|
|
14
|
|
|
protected $config; |
|
15
|
|
|
|
|
16
|
|
|
protected $result; |
|
17
|
|
|
|
|
18
|
|
|
protected $calendar_type; |
|
19
|
|
|
|
|
20
|
|
|
protected $geregorian_DayofWeek; |
|
21
|
|
|
|
|
22
|
|
|
public function __construct( $date_time, $calendar_type = 'gregorian' ) { |
|
23
|
|
|
|
|
24
|
|
|
$this->config = include( 'Config.php' ); |
|
25
|
|
|
|
|
26
|
|
|
$this->date_time = $date_time; |
|
27
|
|
|
|
|
28
|
|
|
$this->calendar_type = $calendar_type; |
|
29
|
|
|
|
|
30
|
|
|
$this->day = $this->date_time->format('l'); |
|
31
|
|
|
|
|
32
|
|
|
$this->geregorian_DayofWeek = $this->date_time->format('w'); |
|
33
|
|
|
|
|
34
|
|
|
return $this; |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Which day of year is current day. |
|
40
|
|
|
* @since Aug, 03 2015 |
|
41
|
|
|
* @return integer |
|
42
|
|
|
*/ |
|
43
|
|
|
public function year() { |
|
44
|
|
|
|
|
45
|
|
|
$config = include( 'CalendarSettings/' . ucfirst( $this->calendar_type ) . '.php' ); |
|
46
|
|
|
|
|
47
|
|
|
return $config[ 'day_of_year' ]( $this->date_time ); |
|
48
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Which day of week is current day. |
|
54
|
|
|
* @since Aug, 09 2015 |
|
55
|
|
|
* @return integer |
|
56
|
|
|
*/ |
|
57
|
|
|
public function week() { |
|
58
|
|
|
|
|
59
|
|
|
switch ( $this->calendar_type ) { |
|
60
|
|
|
|
|
61
|
|
|
case 'ir': |
|
62
|
|
|
|
|
63
|
|
|
$this->result = $this->persian_day_of_week(); |
|
64
|
|
|
|
|
65
|
|
|
break; |
|
66
|
|
|
|
|
67
|
|
|
case 'gh': |
|
68
|
|
|
|
|
69
|
|
|
$this->result = $this->islamic_day_of_week(); |
|
70
|
|
|
|
|
71
|
|
|
break; |
|
72
|
|
|
|
|
73
|
|
|
case 'gr': |
|
74
|
|
|
|
|
75
|
|
|
$this->result = date( 'w', strtotime( $this->date_time->format('Y-m-d H:i:s') ) ) + 1; |
|
76
|
|
|
|
|
77
|
|
|
break; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
return $this->result; |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @since Sept, 14 2015 |
|
86
|
|
|
* @return integer |
|
87
|
|
|
*/ |
|
88
|
|
View Code Duplication |
protected function persian_day_of_week() { |
|
|
|
|
|
|
89
|
|
|
|
|
90
|
|
|
$this->day = str_replace( $this->config['week_days_name']['english'], $this->config['week_days_name']['persian'], $this->day); |
|
91
|
|
|
|
|
92
|
|
|
foreach ( $this->config['week_days_name']['persian'] as $key => $value ) { |
|
93
|
|
|
|
|
94
|
|
|
if( $value == $this->day ) return $key += 1; |
|
95
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @since Sept, 14 2015 |
|
102
|
|
|
* @return integer |
|
103
|
|
|
*/ |
|
104
|
|
View Code Duplication |
protected function islamic_day_of_week() { |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
$this->day = str_replace( $this->config['week_days_name']['english'], $this->config['week_days_name']['islamic'][$this->geregorian_DayofWeek], $this->day); |
|
107
|
|
|
|
|
108
|
|
|
foreach ( $this->config['week_days_name']['islamic'] as $key => $value ) { |
|
109
|
|
|
|
|
110
|
|
|
if( $value == $this->day ) return $key += 1; |
|
111
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
|
|
118
|
|
|
} |
|
119
|
|
|
?> |
|
|
|
|
|
|
120
|
|
|
|