|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
Author: Irfa Ardiansyah <[email protected]> |
|
4
|
|
|
version: 1.1 |
|
5
|
|
|
https://github.com/irfaardy/php-hari-libur |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace Irfa\HariLibur\Func; |
|
8
|
|
|
|
|
9
|
|
|
use Irfa\HariLibur\Core\Libur; |
|
10
|
|
|
use Irfa\HariLibur\Core\DateHelpers; |
|
11
|
|
|
use Irfa\HariLibur\Core\ConfigLoader; |
|
12
|
|
|
|
|
13
|
|
|
class HariLibur extends Libur |
|
14
|
|
|
{ |
|
15
|
|
|
private $date; |
|
16
|
|
|
/** |
|
17
|
|
|
* Method ini berfungsi sebagai setter untuk $date |
|
18
|
|
|
* |
|
19
|
|
|
* @param string $date |
|
20
|
|
|
* @return object |
|
21
|
|
|
*/ |
|
22
|
|
|
public function date($date) |
|
23
|
|
|
{ |
|
24
|
|
|
$date_helper = new DateHelpers(); |
|
25
|
|
|
$this->date = $date_helper->convertDate($date); |
|
26
|
|
|
return $this; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Method ini berfungsi untuk mengecek hari libur nasional |
|
31
|
|
|
* |
|
32
|
|
|
* @return boolean |
|
33
|
|
|
*/ |
|
34
|
|
|
public function isHoliday() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->checkDate(); |
|
37
|
|
|
return $this->checkHoliday($this->date); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Method ini berfungsi untuk mengecek akhir pekan (sabtu, minggu) |
|
42
|
|
|
* |
|
43
|
|
|
* @return boolean |
|
44
|
|
|
*/ |
|
45
|
|
|
public function isWeekend() |
|
46
|
|
|
{ |
|
47
|
|
|
$this->checkDate(); |
|
48
|
|
|
return $this->checkWeekend($this->date); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Method ini berfungsi untuk mengecek hari akhir pekan dan hari libur nasional |
|
53
|
|
|
* |
|
54
|
|
|
* @return boolean |
|
55
|
|
|
*/ |
|
56
|
|
|
public function isDayOff() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->checkDate(); |
|
59
|
|
|
return $this->checkOffDay($this->date); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Method ini berfungsi untuk mengambil data hari libur nasional |
|
64
|
|
|
* |
|
65
|
|
|
* @return object |
|
66
|
|
|
*/ |
|
67
|
|
|
public function get() |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->fetchHolidays(); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Method ini berfungsi untuk mengambil informasi libur |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
public function getInfo() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->checkDate(); |
|
79
|
|
|
return $this->gettingInfo($this->date); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Method ini berfungsi untuk mengecek tanggal sudah diisi apa belum |
|
84
|
|
|
* |
|
85
|
|
|
* @return mixed |
|
86
|
|
|
*/ |
|
87
|
|
|
public function region($region) |
|
88
|
|
|
{ |
|
89
|
|
|
$this->setRegion($region); |
|
90
|
|
|
return $this; |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Method ini berfungsi untuk menampilkan data libur sebelum tanggal yang telah di atur di parameter date. |
|
95
|
|
|
* |
|
96
|
|
|
* @return object |
|
97
|
|
|
*/ |
|
98
|
|
|
public function nextHoliday() |
|
99
|
|
|
{ |
|
100
|
|
|
$next = $this->getnextHolidays($this->date); |
|
101
|
|
|
return $next; |
|
|
|
|
|
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Method ini berfungsi untuk menampilkan data libur setelah tanggal yang telah di atur di parameter date. |
|
106
|
|
|
* |
|
107
|
|
|
* @return object |
|
108
|
|
|
*/ |
|
109
|
|
|
public function prevHoliday() |
|
110
|
|
|
{ |
|
111
|
|
|
$prev = $this->getPrevHolidays($this->date); |
|
112
|
|
|
return $prev; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Method ini berfungsi untuk mengecek tanggal sudah diisi apa belum |
|
117
|
|
|
* |
|
118
|
|
|
* @return mixed |
|
119
|
|
|
*/ |
|
120
|
|
|
private function checkDate() |
|
121
|
|
|
{ |
|
122
|
|
|
if(empty($this->date)) |
|
123
|
|
|
{ |
|
124
|
|
|
throw new \Exception('Parameter date must be provided.'); |
|
125
|
|
|
return false; |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|