1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenCafe\Tools; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Define Day of current date. |
7
|
|
|
*/ |
8
|
|
|
class DayOf |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var object |
12
|
|
|
*/ |
13
|
|
|
protected $date_time; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var array |
17
|
|
|
*/ |
18
|
|
|
protected $config; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $calendar_type; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var int |
27
|
|
|
*/ |
28
|
|
|
protected $day_of_week; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Constructor of DayOf class |
32
|
|
|
*/ |
33
|
|
|
public function __construct($date_time, $calendar_type = 'gregorian', $day_of_week = null) |
34
|
|
|
{ |
35
|
|
|
|
36
|
|
|
$this->config = include __DIR__.'/CalendarSettings/' . ucfirst($calendar_type) . '.php'; |
37
|
|
|
|
38
|
|
|
$this->calendar_type = $calendar_type; |
39
|
|
|
|
40
|
|
|
$this->date_time = $date_time; |
41
|
|
|
|
42
|
|
|
$this->day_of_week = $day_of_week; |
43
|
|
|
|
44
|
|
|
return $this; |
|
|
|
|
45
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Which day of year is current day. |
50
|
|
|
* |
51
|
|
|
* @since Aug, 03 2015 |
52
|
|
|
* @return integer |
53
|
|
|
*/ |
54
|
|
|
public function year() |
55
|
|
|
{ |
56
|
|
|
|
57
|
|
|
return $this->config[ 'day_of_year' ]( $this->date_time ); |
58
|
|
|
|
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Which day of week is current day. |
64
|
|
|
* |
65
|
|
|
* @since Aug, 09 2015 |
66
|
|
|
* @return integer |
67
|
|
|
*/ |
68
|
|
|
public function week() |
69
|
|
|
{ |
70
|
|
|
return $this->config[ 'day_of_week' ]( $this->date_time, $this->day_of_week ); |
71
|
|
|
|
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Return last day of current month |
76
|
|
|
* |
77
|
|
|
* @since Oct, 18 2016 |
78
|
|
|
* @return integer |
79
|
|
|
*/ |
80
|
|
|
public function lastDayMonth() { |
81
|
|
|
|
82
|
|
|
$days = 0; |
|
|
|
|
83
|
|
|
|
84
|
|
|
switch ( $this->calendar_type ) { |
85
|
|
|
|
86
|
|
View Code Duplication |
case 'gregorian': |
|
|
|
|
87
|
|
|
|
88
|
|
|
$days = ( intval( $this->date_time->format( 'm' ) ) == 2 && |
89
|
|
|
$this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ? |
90
|
|
|
$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 : |
91
|
|
|
$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
92
|
|
|
|
93
|
|
|
break; |
94
|
|
|
|
95
|
|
View Code Duplication |
case 'jalali': |
|
|
|
|
96
|
|
|
|
97
|
|
|
$days = ( intval( $this->date_time->format( 'm' ) ) == 12 && |
98
|
|
|
$this->config[ 'leap_year' ]( $this->date_time->format( 'Y' )) ) ? |
99
|
|
|
$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ] + 1 : |
100
|
|
|
$this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
101
|
|
|
|
102
|
|
|
break; |
103
|
|
|
|
104
|
|
|
default: |
105
|
|
|
|
106
|
|
|
$days = $this->config[ 'month_days_number' ][ intval( $this->date_time->format( 'm' ) ) ]; |
107
|
|
|
|
108
|
|
|
break; |
109
|
|
|
|
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return $days; |
113
|
|
|
|
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|