1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ianrizky\MoslemPray\Response\MyQuran; |
4
|
|
|
|
5
|
|
|
use Ianrizky\MoslemPray\Contracts\Response\HasPrayerTime; |
6
|
|
|
use Ianrizky\MoslemPray\Support\Timezone; |
7
|
|
|
use Illuminate\Http\Client\Response; |
8
|
|
|
use Illuminate\Support\Carbon; |
9
|
|
|
use Spatie\DataTransferObject\DataTransferObject; |
10
|
|
|
|
11
|
|
|
class PrayerTime extends DataTransferObject implements HasPrayerTime |
12
|
|
|
{ |
13
|
|
|
/** @var \Ianrizky\MoslemPray\Response\MyQuran\City */ |
14
|
|
|
public $city; |
15
|
|
|
|
16
|
|
|
/** @var \Illuminate\Support\Carbon */ |
17
|
|
|
public $date; |
18
|
|
|
|
19
|
|
|
/** @var \Illuminate\Support\Carbon */ |
20
|
|
|
public $imsak; |
21
|
|
|
|
22
|
|
|
/** @var \Illuminate\Support\Carbon */ |
23
|
|
|
public $subuh; |
24
|
|
|
|
25
|
|
|
/** @var \Illuminate\Support\Carbon */ |
26
|
|
|
public $terbit; |
27
|
|
|
|
28
|
|
|
/** @var \Illuminate\Support\Carbon */ |
29
|
|
|
public $dhuha; |
30
|
|
|
|
31
|
|
|
/** @var \Illuminate\Support\Carbon */ |
32
|
|
|
public $dzuhur; |
33
|
|
|
|
34
|
|
|
/** @var \Illuminate\Support\Carbon */ |
35
|
|
|
public $ashar; |
36
|
|
|
|
37
|
|
|
/** @var \Illuminate\Support\Carbon */ |
38
|
|
|
public $maghrib; |
39
|
|
|
|
40
|
|
|
/** @var \Illuminate\Support\Carbon */ |
41
|
|
|
public $isya; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* {@inheritDoc} |
45
|
|
|
*/ |
46
|
1 |
|
public static function fromResponse(Response $response) |
47
|
|
|
{ |
48
|
1 |
|
$city = data_get($response->json(), 'data.lokasi'); |
49
|
1 |
|
$timezone = Timezone::getTimezone($city, 'Asia/Jakarta'); |
50
|
1 |
|
$date = Carbon::parse(data_get($response->json(), 'data.jadwal.date'), $timezone); |
51
|
|
|
|
52
|
1 |
|
return new static([ |
53
|
|
|
'city' => [ |
54
|
1 |
|
'id' => data_get($response->json(), 'data.id'), |
55
|
|
|
'coordinate' => [ |
56
|
1 |
|
'latitude' => data_get($response->json(), 'data.koordinat.lat'), |
57
|
1 |
|
'longitude' => data_get($response->json(), 'data.koordinat.lon'), |
58
|
1 |
|
'latitude_degree' => data_get($response->json(), 'data.koordinat.lintang'), |
59
|
1 |
|
'longitude_degree' => data_get($response->json(), 'data.koordinat.bujur'), |
60
|
|
|
], |
61
|
1 |
|
'name' => $city, |
62
|
1 |
|
'region' => data_get($response->json(), 'data.daerah'), |
63
|
|
|
], |
64
|
1 |
|
'date' => $date, |
65
|
1 |
|
'imsak' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.imsak')), |
66
|
1 |
|
'subuh' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.subuh')), |
67
|
1 |
|
'terbit' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.terbit')), |
68
|
1 |
|
'dhuha' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.dhuha')), |
69
|
1 |
|
'dzuhur' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.dzuhur')), |
70
|
1 |
|
'ashar' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.ashar')), |
71
|
1 |
|
'maghrib' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.maghrib')), |
72
|
1 |
|
'isya' => $date->copy()->setTimeFromTimeString(data_get($response->json(), 'data.jadwal.isya')), |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* {@inheritDoc} |
78
|
|
|
*/ |
79
|
|
|
public function getImsak(): Carbon |
80
|
|
|
{ |
81
|
|
|
return $this->imsak; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritDoc} |
86
|
|
|
*/ |
87
|
|
|
public function getSubuh(): Carbon |
88
|
|
|
{ |
89
|
|
|
return $this->subuh; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* {@inheritDoc} |
94
|
|
|
*/ |
95
|
|
|
public function getSunrise(): Carbon |
96
|
|
|
{ |
97
|
|
|
return $this->terbit; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* {@inheritDoc} |
102
|
|
|
*/ |
103
|
|
|
public function getDhuha(): Carbon |
104
|
|
|
{ |
105
|
|
|
return $this->dhuha; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* {@inheritDoc} |
110
|
|
|
*/ |
111
|
|
|
public function getDzuhur(): Carbon |
112
|
|
|
{ |
113
|
|
|
return $this->dzuhur; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritDoc} |
118
|
|
|
*/ |
119
|
|
|
public function getAshar(): Carbon |
120
|
|
|
{ |
121
|
|
|
return $this->ashar; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* {@inheritDoc} |
126
|
|
|
*/ |
127
|
|
|
public function getMaghrib(): Carbon |
128
|
|
|
{ |
129
|
|
|
return $this->maghrib; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* {@inheritDoc} |
134
|
|
|
*/ |
135
|
|
|
public function getIsya(): Carbon |
136
|
|
|
{ |
137
|
|
|
return $this->isya; |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|