-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass-imsakiyah.php
156 lines (128 loc) · 4.1 KB
/
class-imsakiyah.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/**
* Description of Imsakiyah
*
* @author Misbahul D Munir <[email protected]>
*/
class Imsakiyah
{
// panjang 1 tahun rata-rata dalam detik
const YEAR_LENGTH = 31557600;
public $bujur;
public $lintang;
public $date;
public $timestamp;
public $timeZone;
public $rawOffset;
public $ketinggian = 100;
public function rules()
{
return[
[['bujur', 'lintang'], 'required'],
[['date'], 'default', 'value' => date('d/m/Y')],
[['date'], 'date', 'format' => 'dd/MM/yyyy', 'timestampAttribute' => 'timestamp'],
[['lintang'], 'number', 'min' => -90, 'max' => 90],
[['bujur'], 'number', 'min' => -180, 'max' => 180],
[['timeZone'], 'default', 'value' => function() {
return (int) ($this->bujur / 15);
}],
[['timeZone'], 'integer', 'min' => -12, 'max' => 12],
[['rawOffset'], 'default', 'value' => function() {
return $this->timeZone * 3600;
}]
];
}
public function __construct( $args = array() )
{
foreach ($args as $key => $value)
$this->{$key} = $value;
// fill default value, using Jakarta
if ( empty($this->lintang ) )
$this->lintang = -6.2115;
if ( empty($this->bujur ) )
$this->bujur = 106.8452;
if ( empty($this->timestamp ) )
$this->timestamp = date('U');
if ( empty($this->date ) )
$this->date = date('d/m/Y', $this->timestamp);
if ( empty($this->timeZone ) )
$this->timeZone = (int) ($this->bujur / 15);
if ( empty($this->rawOffset ) )
$this->rawOffset = $this->timeZone * 3600;
}
/**
* Sudut deklinasi matahari. Satuan derajat.
* @return float
*/
public function getDelta()
{
$u = ($this->timestamp - ($this->bujur * 240) - 946684800) / self::YEAR_LENGTH;
$T = 2 * pi() * $u;
$delta = 0.37877 + 23.264 * SIN($T - 1.38835706) + 0.3812 * SIN(2 * $T - 1.443073132) + 0.17132 * SIN(3 * $T - 1.042345536);
return $delta;
}
/**
* Equation time. Satuan detik.
* @return float
*/
public function getET()
{
$u = ($this->timestamp - ($this->bujur * 240) - 946684800) / self::YEAR_LENGTH;
$l0 = 2 * pi() * (0.779072417 + 1.000021383 * $u);
$sub1 = -(107.34 + 0.1422 * $u) * SIN($l0) - (428.76 - 0.0372 * $u) * COS($l0);
$sub2 = (596.04 - 0.0084 * $u) * SIN(2 * $l0) - (1.74 + 0.003 * $u) * COS(2 * $l0);
$sub3 = (4.44 + 0.006 * $u) * SIN(3 * $l0) + (19.2 - 0.0024 * $u) * COS(3 * $l0);
$sub4 = - 12.72 * SIN(4 * $l0);
$et = $sub1 + $sub2 + $sub3 + $sub4;
return $et;
}
/**
* Menghitung waktu pada saat matahari pada sudut `$angle` dari titik tertinggi.
* @param float $dzuhur
* @param float $delta
* @param float $angle
* @return float Waktu dalam detik
*/
public function getTimeOfAngle($dzuhur, $delta, $angle)
{
$angle = $angle * pi() / 180;
$delta = $delta * pi() / 180;
$lintang = $this->lintang * pi() / 180;
$cosTeta = (cos($angle) - sin($lintang) * sin($delta)) / (cos($lintang) * cos($delta));
if ($cosTeta < -1 || $cosTeta > 1) {
return;
}
$teta = acos($cosTeta) * 180 / pi();
$time = $teta * 240;
return $angle >= 0 ? $dzuhur + $time : $dzuhur - $time;
}
public function getImsakiyah()
{
// dzuhur
$dzuhur = (12 * 3600) + $this->rawOffset - ($this->bujur * 240) - $this->getET();
$delta = $this->getDelta();
$result = [];
// $alfa = sudut matahari dari posisi tertinggi
// fajar / shubuh, $alfa = -90 - 20
$alfa = -110;
$result['shubuh'] = $this->getTimeOfAngle($dzuhur, $delta, $alfa);
// sudut pembiasan
$sp = 0.833 + 0.0347 * sqrt($this->ketinggian);
// terbit matahari, $alfa = -90 - sudut pembiasan
$alfa = -90 - $sp;
$result['terbit'] = $this->getTimeOfAngle($dzuhur, $delta, $alfa);
// dhuzur
$result['dzuhur'] = $dzuhur;
// ashar, panjang bayangan = panjang benda + panjang bayangan saat dzuhur.
$aAlfa = 1 + abs(tan(($delta - $this->lintang) * pi() / 180));
$alfa = atan($aAlfa) * 180 / pi();
$result['ashar'] = $this->getTimeOfAngle($dzuhur, $delta, $alfa);
// maghrib, $alfa = 90 + sudut pembiasan
$alfa = 90 + $sp;
$result['maghrib'] = $this->getTimeOfAngle($dzuhur, $delta, $alfa);
// isya', $alfa = 90 + 18
$alfa = 108;
$result['isya'] = $this->getTimeOfAngle($dzuhur, $delta, $alfa);
return $result;
}
}