blib/lib/Religion/Islam/PrayTime.pm

filter: Statementstmt 5.8% 17 / 289 Branchbran 0.0% 0 / 66 Conditioncond 0.0% 0 / 23 MC/DCmcdc 0.0% 0 / 13 Subroutinesub 8.6% 5 / 58 Podpod 0.0% 0 / 53 totaltotal 4.3% 22 / 502 CC 42 SCAR 28.8
CC
42
Cov
4%
adjustHighLatTimes
90.0
floatToTime12
30.0
adjustTimes
30.0
CRAP 17.9
↑ Summary
1 #=Copyright Infomation
2 #==========================================================
3 #Module Name : Religion::Islam::PrayTime
4 #Program Author : Dr. Ahmed Amin Elsheshtawy, Ph.D. Physics, E.E.
5 #Home Page : http://www.islamware.com, http://www.mewsoft.com
6 #Contact Email : support@islamware.com, support@mewsoft.com
7 #Copyrights 2013-2014 IslamWare. All rights reserved.
8 #==========================================================
9 package Religion::Islam::PrayTime;
10  
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Time::Local;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use constant PI => 4 * atan2(1, 1); #3.1415926535897932
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 our $VERSION = '1.06';
18 #=========================================================#
19 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
20 0 my ($class, $methodID) = @_;
21
22 0 my $self = bless {}, $class;
23 #------------------------ Constants --------------------------
24 # Calculation Methods
25 0 $self->{Jafari} = 0; # Ithna Ashari
26 0 $self->{Karachi} = 1; # University of Islamic Sciences, Karachi
27 0 $self->{ISNA} = 2; # Islamic Society of North America (ISNA)
28 0 $self->{MWL} = 3; # Muslim World League (MWL)
29 0 $self->{Makkah} = 4; # Umm al-Qura, Makkah
30 0 $self->{Egypt} = 5; # Egyptian General Authority of Survey
31 0 $self->{Tehran} = 6; # Institute of Geophysics, University of Tehran
32 0 $self->{Custom} = 7; # Custom Setting
33  
34 # Juristic Methods
35 0 $self->{Shafii} = 0; # Shafii (standard)
36 0 $self->{Hanafi} = 1; # Hanafi
37  
38 # Adjusting Methods for Higher Latitudes
39 0 $self->{None} = 0; # No adjustment
40 0 $self->{MidNight} = 1; # middle of night
41 0 $self->{OneSeventh} = 2; # 1/7th of night
42 0 $self->{AngleBased} = 3; # angle/60th of night
43  
44 # Time Formats
45 0 $self->{Time24} = 0; # 24-hour format
46 0 $self->{Time12} = 1; # 12-hour format
47 0 $self->{Time12NS} = 2; # 12-hour format with no suffix
48 0 $self->{Float} = 3; # floating point number
49  
50 0 $self->{decimal_size} = 2; # decimal size for Float time format
51  
52 # Time Names
53 0 $self->{timeNames} = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Sunset', 'Maghrib', 'Isha'];
54  
55 0 $self->{InvalidTime} = '-----'; # The string used for invalid times
56  
57 #---------------------- Global Variables --------------------
58 0 $self->{calcMethod} = 5; # Calculation method
59 0 $self->{asrJuristic} = 0; # Juristic method for Asr
60 0 $self->{dhuhrMinutes} = 0; # minutes after mid-day for Dhuhr
61 0 $self->{adjustHighLats} = 0; # adjusting method for higher latitudes
62  
63 0 $self->{timeFormat} = 0; # time format
64  
65 0 $self->{lat} = 0; # latitude
66 0 $self->{lng} = 0; # longitude
67 0 $self->{timeZone} = 0; # time-zone
68 0 $self->{JDate} = 0; # Julian date
69
70 #--------------------- Technical Settings --------------------
71 0 $self->{numIterations} = 1; # number of iterations needed to compute times
72 #------------------- Calc Method Parameters --------------------
73 #$self->{methodParams};
74
75 0 $self->{am} = "am";
76 0 $self->{pm} = "pm";
77  
78 0 $methodID += 0;
79 0 $self->PrayTime($methodID);
80  
81 0 return $self;
82 }
83 #=========================================================#
84 0 ▶sub PrayTime {
Subroutine PrayTime: not called CC=1 SCAR=6.9
Pod undocumented
85 0 my ($self, $methodID) = @_;
86
87 # $self->{methodParams}->{methodNum} = array(fa, ms, mv, is, iv);
88 # fa : fajr angle
89 # ms : maghrib selector (0 = angle; 1 = minutes after sunset)
90 # mv : maghrib parameter value (in angle or minutes)
91 # is : isha selector (0 = angle; 1 = minutes after maghrib)
92 # iv : isha parameter value (in angle or minutes)
93  
94 0 $methodID += 0;
95 0 $self->{methodParams}{$self->{Jafari}} = [16, 0, 4, 0, 14];
96 0 $self->{methodParams}{$self->{Karachi}} = [18, 1, 0, 0, 18];
97 0 $self->{methodParams}{$self->{ISNA}} = [15, 1, 0, 0, 15];
98 0 $self->{methodParams}{$self->{MWL}} = [18, 1, 0, 0, 17];
99 0 $self->{methodParams}{$self->{Makkah}} = [18.5, 1, 0, 1, 90];
100 0 $self->{methodParams}{$self->{Egypt}} = [19.5, 1, 0, 0, 17.5];
101 0 $self->{methodParams}{$self->{Tehran}} = [17.7, 0, 4.5, 0, 14];
102 0 $self->{methodParams}{$self->{Custom}} = [18, 1, 0, 0, 17];
103 0 $self->setCalcMethod($methodID);
104 }
105 #=========================================================#
106 # -------------------- Interface Functions --------------------
107 # return prayer times for a given date
108 0 ▶sub getDatePrayerTimes {
Subroutine getDatePrayerTimes: not called CC=1 SCAR=6.9
Pod undocumented
109 0 my ($self, $year, $month, $day, $latitude, $longitude, $timeZone) = @_;
110 0 $self->{lat} = $latitude;
111 0 $self->{lng} = $longitude;
112 0 $self->{timeZone} = $timeZone;
113 0 $self->{JDate} = $self->julianDate($year, $month, $day) - ($longitude/(15* 24));
114 0 return $self->computeDayTimes();
115 }
116  
117 # return prayer times for a given timestamp
118 0 ▶sub getPrayerTimes {
Subroutine getPrayerTimes: not called CC=1 SCAR=6.9
Pod undocumented
119 0 my ($self, $timestamp, $latitude, $longitude, $timeZone) = @_;
120 0 my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime($timestamp);
121 0 $mon++;
122 0 $year += 1900;
123 0 return $self->getDatePrayerTimes($year, $mon, $mday, $latitude, $longitude, $timeZone);
124 }
125  
126 # return prayer times for a given date in a hash
127 0 ▶sub getDatePrayerTimesHash {
Subroutine getDatePrayerTimesHash: not called CC=1 SCAR=6.9
Pod undocumented
128 0 my ($self, $year, $month, $day, $latitude, $longitude, $timeZone) = @_;
129 0 my %times;
130 0 @times{@{$self->{timeNames}}} = $self->getDatePrayerTimes($year, $month, $day, $latitude, $longitude, $timeZone);
131 0 return %times;
132 }
133  
134 # return prayer times for a given timestamp in a hash
135 0 ▶sub getPrayerTimesHash {
Subroutine getPrayerTimesHash: not called CC=1 SCAR=6.9
Pod undocumented
136 0 my ($self, $timestamp, $latitude, $longitude, $timeZone) = @_;
137 0 my %times;
138 0 @times{@{$self->{timeNames}}} = $self->getPrayerTimes($timestamp, $latitude, $longitude, $timeZone);
139 0 return %times;
140 }
141  
142 # set the calculation method
143 0 ▶sub setCalcMethod {
Subroutine setCalcMethod: not called CC=1 SCAR=6.9
Pod undocumented
144 0 my ($self, $methodID) = @_;
145 0 $self->{calcMethod} = $methodID;
146 }
147  
148 # set the juristic method for Asr
149 0 ▶sub setAsrMethod {
Subroutine setAsrMethod: not called CC=3 SCAR=24.8
Pod undocumented
150 0 my ($self, $methodID) = @_;
151 0 ▶ if ($methodID < 0 || $methodID > 1) {return};
Branch: 1 branch
BranchTrueFalseTotal
if ($methodID < 0 or $methodID > 1) 0 0 0
Condition0%0/3
$methodID < 0 or $methodID > 1
l!l&&r!l&&!r
000
MC/DC0%0/2
$methodID < 0 or $methodID > 1
$methodID < 0 $methodID > 1
Truth table0%0/3
A or B
A= $methodID < 0B= $methodID > 1
ABresult
1X1
011
000
152 0 $self->{asrJuristic} = $methodID;
153 }
154  
155 # set the angle for calculating Fajr
156 0 ▶sub setFajrAngle {
Subroutine setFajrAngle: not called CC=1 SCAR=6.9
Pod undocumented
157 0 my ($self, $angle) = @_;
158 0 $self->setCustomParams($angle, undef, undef, undef, undef);
159 }
160  
161 #set the angle for calculating Maghrib
162 0 ▶sub setMaghribAngle {
Subroutine setMaghribAngle: not called CC=1 SCAR=6.9
Pod undocumented
163 0 my ($self, $angle) = @_;
164 0 $self->setCustomParams(undef, 0, $angle, undef, undef);
165 }
166  
167 # set the angle for calculating Isha
168 0 ▶sub setIshaAngle {
Subroutine setIshaAngle: not called CC=1 SCAR=6.9
Pod undocumented
169 0 my ($self, $angle) = @_;
170 0 $self->setCustomParams(undef, undef, undef, 0, $angle);
171 }
172  
173 # set the minutes after mid-day for calculating Dhuhr
174 0 ▶sub setDhuhrMinutes {
Subroutine setDhuhrMinutes: not called CC=1 SCAR=6.9
Pod undocumented
175 0 my ($self, $minutes) = @_;
176 0 $self->{dhuhrMinutes} = $minutes;
177 }
178  
179 #set the minutes after Sunset for calculating Maghrib
180 0 ▶sub setMaghribMinutes {
Subroutine setMaghribMinutes: not called CC=1 SCAR=6.9
Pod undocumented
181 0 my ($self, $minutes) = @_;
182 0 $self->setCustomParams(undef, 1, $minutes, undef, undef);
183 }
184  
185 #set the minutes after Maghrib for calculating Isha
186 0 ▶sub setIshaMinutes {
Subroutine setIshaMinutes: not called CC=1 SCAR=6.9
Pod undocumented
187 0 my ($self, $minutes) = @_;
188 0 $self->setCustomParams(undef, undef, undef, 1, $minutes);
189 }
190  
191 # set custom values for calculation parameters
192 0 ▶sub setCustomParams {
Subroutine setCustomParams: not called CC=3 SCAR=24.8
Pod undocumented
193 0 my ($self, @params) = @_;
194 0 ▶ for (my $i=0; $i<5; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 5) 0 0 0
195 0 ▶ if (!defined($params[$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $params[$i]) { } 0 0 0
196 0 $self->{methodParams}->{$self->{Custom}}[$i] = $self->{methodParams}->{$self->{calcMethod}}[$i];
197 }
198 else {
199 0 $self->{methodParams}->{$self->{Custom}}[$i] = $params[$i];
200 }
201 }
202 0 $self->{calcMethod} = $self->{Custom};
203 }
204  
205 # set adjusting method for higher latitudes
206 0 ▶sub setHighLatsMethod {
Subroutine setHighLatsMethod: not called CC=1 SCAR=6.9
Pod undocumented
207 0 my ($self, $methodID) = @_;
208 0 $self->{adjustHighLats} = $methodID;
209 }
210  
211 # set the time format
212 0 ▶sub setTimeFormat {
Subroutine setTimeFormat: not called CC=1 SCAR=6.9
Pod undocumented
213 0 my ($self, $timeFormat) = @_;
214 0 $self->{timeFormat} = $timeFormat;
215 }
216  
217 0 ▶sub am_pm {
Subroutine am_pm: not called CC=1 SCAR=6.9
Pod undocumented
218 0 my ($self, $am, $pm) = @_;
219 0 $self->{am} = $am;
220 0 $self->{pm} = $pm;
221 0 return ($self->{am}, $self->{pm});
222 }
223  
224 # convert float hours to 24h format
225 0 ▶sub floatToTime24 {
Subroutine floatToTime24: not called CC=2 SCAR=17.9
Pod undocumented
226 0 my ($self, $time) = @_;
227 0 ▶ if (!$time) {return $self->{InvalidTime}};
Branch: 1 branch
BranchTrueFalseTotal
unless ($time) 0 0 0
228 0 $time = $self->fixhour($time+ 0.5/ 60); #add 0.5 minutes to round
229 0 my $hours = floor($time);
230 0 my $minutes = floor(($time- $hours)* 60);
231 0 return $self->twoDigitsFormat($hours). ':'. $self->twoDigitsFormat($minutes);
232 }
233  
234 # convert float hours to 12h format
235 0 ▶sub floatToTime12 {
Subroutine floatToTime12: not called CC=5 SCAR=34.0
Pod undocumented
236 0 my ($self, $time, $noSuffix) = @_;
237 0 ▶ $noSuffix ||= "";
Condition0%0/2
$noSuffix ||= ""
l!l
00
MC/DC0%0/1
$noSuffix ||= ""
$noSuffix
Truth table0%0/2
A
A= $noSuffix
Aresult
11
00
238 0 ▶ if (!$time) {return $self->{InvalidTime}};
Branch: 1 branch
BranchTrueFalseTotal
unless ($time) 0 0 0
239 0 $time = $self->fixhour($time+ 0.5/ 60); # add 0.5 minutes to round
240 0 my $hours = floor($time);
241 0 my $minutes = floor(($time- $hours)* 60);
242 0 ▶ my $suffix = $hours >= 12 ? $self->{pm} : $self->{am};
Branch: 1 branch
BranchTrueFalseTotal
$hours >= 12 ? : 0 0 0
243 0 $hours = ($hours+ 12- 1)% 12+ 1;
244 0 ▶ return $hours. ':'. $self->twoDigitsFormat($minutes). ($noSuffix ? '' : $suffix);
Branch: 1 branch
BranchTrueFalseTotal
$noSuffix ? : 0 0 0
245 }
246  
247 # convert float hours to 12h format with no suffix
248 0 ▶sub floatToTime12NS {
Subroutine floatToTime12NS: not called CC=1 SCAR=6.9
Pod undocumented
249 0 my ($self, $time) = @_;
250 0 return $self->floatToTime12($time, 1);
251 }
252  
253 #---------------------- Calculation Functions -----------------------
254 # References:
255 # http://www.ummah.net/astronomy/saltime
256 # http://aa.usno.navy.mil/faq/docs/SunApprox.html
257  
258 # compute declination angle of sun and equation of time
259 0 ▶sub sunPosition {
Subroutine sunPosition: not called CC=1 SCAR=6.9
Pod undocumented
260 0 my ($self, $jd) = @_;
261  
262 0 my $D = $jd - 2451545.0;
263  
264 0 my $g = $self->fixangle(357.529 + 0.98560028* $D);
265 0 my $q = $self->fixangle(280.459 + 0.98564736* $D);
266 0 my $L = $self->fixangle($q + 1.915* $self->dsin($g) + 0.020* $self->dsin(2*$g));
267 0 my $R = 1.00014 - 0.01671* $self->dcos($g) - 0.00014* $self->dcos(2*$g);
268 0 my $e = 23.439 - 0.00000036* $D;
269  
270 0 my $d = $self->darcsin($self->dsin($e)* $self->dsin($L));
271 0 my $RA = $self->darctan2($self->dcos($e)* $self->dsin($L), $self->dcos($L))/ 15;
272
273 0 my $RA = $self->fixhour($RA);
274 0 my $EqT = $q/15 - $RA;
275
276 0 return ($d, $EqT);
277 }
278  
279 # compute equation of time
280 0 ▶sub equationOfTime {
Subroutine equationOfTime: not called CC=1 SCAR=6.9
Pod undocumented
281 0 my ($self, $jd) = @_;
282 0 my @sp = $self->sunPosition($jd);
283 0 return $sp[1];
284 }
285  
286 # compute declination angle of sun
287 0 ▶sub sunDeclination {
Subroutine sunDeclination: not called CC=1 SCAR=6.9
Pod undocumented
288 0 my ($self, $jd) = @_;
289 0 my @sp = $self->sunPosition($jd);
290 0 return $sp[0];
291 }
292  
293 # compute mid-day (Dhuhr, Zawal) time
294 0 ▶sub computeMidDay {
Subroutine computeMidDay: not called CC=1 SCAR=6.9
Pod undocumented
295 0 my ($self, $t) = @_;
296 0 my $T = $self->equationOfTime($self->{JDate}+ $t);
297 0 my $Z = $self->fixhour(12- $T);
298 0 return $Z;
299 }
300  
301 # compute time for a given angle G
302 0 ▶sub computeTime {
Subroutine computeTime: not called CC=2 SCAR=17.9
Pod undocumented
303 0 my ($self, $G, $t) = @_;
304 0 my $D = $self->sunDeclination($self->{JDate}+ $t);
305 0 my $Z = $self->computeMidDay($t);
306 0 my $V = 1/15* $self->darccos((-$self->dsin($G)- $self->dsin($D)* $self->dsin($self->{lat}))/($self->dcos($D)* $self->dcos($self->{lat})));
307 0 ▶ return ($Z+ ($G>90 ? -$V : $V));
Branch: 1 branch
BranchTrueFalseTotal
$G > 90 ? : 0 0 0
308 }
309  
310 # compute the time of Asr
311 # Shafii: step=1, Hanafi: step=2
312 0 ▶sub computeAsr {
Subroutine computeAsr: not called CC=1 SCAR=6.9
Pod undocumented
313 0 my ($self, $step, $t) = @_;
314 0 my $D = $self->sunDeclination($self->{JDate}+ $t);
315 0 my $G = -$self->darccot($step+ $self->dtan(abs($self->{lat}- $D)));
316 0 return $self->computeTime($G, $t);
317 }
318  
319 #---------------------- Compute Prayer Times -----------------------
320 # compute prayer times at given julian date
321 0 ▶sub computeTimes {
Subroutine computeTimes: not called CC=1 SCAR=6.9
Pod undocumented
322 0 my ($self, @times) = @_;
323  
324 0 my @t = $self->dayPortion(@times);
325  
326 0 my $Fajr = $self->computeTime(180- $self->{methodParams}->{$self->{calcMethod}}[0], $t[0]);
327 0 my $Sunrise = $self->computeTime(180- 0.833, $t[1]);
328 0 my $Dhuhr = $self->computeMidDay($t[2]);
329 0 my $Asr = $self->computeAsr(1+ $self->{asrJuristic}, $t[3]);
330 0 my $Sunset = $self->computeTime(0.833, $t[4]);
331 0 my $Maghrib = $self->computeTime($self->{methodParams}->{$self->{calcMethod}}[2], $t[5]);
332 0 my $Isha = $self->computeTime($self->{methodParams}->{$self->{calcMethod}}[4], $t[6]);
333  
334 0 return ($Fajr, $Sunrise, $Dhuhr, $Asr, $Sunset, $Maghrib, $Isha);
335 }
336  
337 # compute prayer times at given julian date
338 0 ▶sub computeDayTimes {
Subroutine computeDayTimes: not called CC=2 SCAR=17.9
Pod undocumented
339 0 my ($self) = @_;
340 0 my @times = (5, 6, 12, 13, 18, 18, 18); #default times
341  
342 0 ▶ for (my $i=1; $i<=$self->{numIterations}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $self->{"numIterations"}) 0 0 0
343 0 @times = $self->computeTimes(@times);
344 }
345 0 @times = $self->adjustTimes(@times);
346 0 return $self->adjustTimesFormat(@times);
347 }
348  
349 # adjust times in a prayer time array
350 0 ▶sub adjustTimes {
Subroutine adjustTimes: not called CC=5 SCAR=34.0
Pod undocumented
351 0 my ($self, @times) = @_;
352  
353 0 ▶ for (my $i=0; $i<7; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 7) 0 0 0
354 0 $times[$i] += $self->{timeZone} - $self->{lng}/15;
355 }
356  
357 0 $times[2] += $self->{dhuhrMinutes}/60; #Dhuhr
358
359 # Maghrib
360 0 ▶ if ($self->{methodParams}->{$self->{calcMethod}}[1] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"methodParams"}{$self->{"calcMethod"}}[1] == 1) 0 0 0
361 0 $times[5] = $times[4] + $self->{methodParams}->{$self->{calcMethod}}[2]/60;
362 }
363
364 # Isha
365 0 ▶ if ($self->{methodParams}->{$self->{calcMethod}}[3] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"methodParams"}{$self->{"calcMethod"}}[3] == 1) 0 0 0
366 0 $times[6] = $times[5]+ $self->{methodParams}->{$self->{calcMethod}}[4]/60;
367 }
368  
369 0 ▶ if ($self->{adjustHighLats} != $self->{None}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"adjustHighLats"} != $self->{"None"}) 0 0 0
370 0 @times = $self->adjustHighLatTimes(@times);
371 }
372 0 return @times;
373 }
374  
375 # convert times array to given time format
376 0 ▶sub adjustTimesFormat {
Subroutine adjustTimesFormat: not called CC=5 SCAR=34.0
Pod undocumented
377 0 my ($self, @times) = @_;
378  
379 0 ▶ if ($self->{timeFormat} == $self->{Float}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"timeFormat"} == $self->{"Float"}) 0 0 0
380 0 map {$_ = sprintf("%0.$self->{decimal_size}f", $_)} @times;
381 0 return @times;
382 };
383  
384 0 ▶ for (my $i=0; $i<7; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 7) 0 0 0
385 0 ▶ if ($self->{timeFormat} == $self->{Time12}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'timeFormat'} == $self->{'Time12'}) { } 0 0 0
elsif ($self->{'timeFormat'} == $self->{'Time12NS'}) { } 0 0 0
386 0 $times[$i] = $self->floatToTime12($times[$i]);
387 }
388 elsif ($self->{timeFormat} == $self->{Time12NS}) {
389 0 $times[$i] = $self->floatToTime12($times[$i], 1);
390 }
391 else {
392 0 $times[$i] = $self->floatToTime24($times[$i]);
393 }
394 }
395 0 return @times;
396 }
397 0 ▶sub decimal_size {
Subroutine decimal_size: not called CC=1 SCAR=6.9
Pod undocumented
398 0 my ($self, $size) = @_;
399 0 $self->{decimal_size} = $size;
400 }
401  
402 0 ▶sub numeric {
Subroutine numeric: not called CC=5 SCAR=34.0
Pod undocumented
403 0 my ($self, $n) = @_;
404 0 ▶ if (($n=~/^\d+$/) || ($n=~ /^\d+\.$/) || ($n=~ /^\d+\.\d+$/) || ($n=~ /^\.\d+$/)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n =~ /^\d+$/ or $n =~ /^\d+\.$/ or $n =~ /^\d+\.\d+$/ or $n =~ /^\.\d+$/) 0 0 0
Condition0%0/9
$n =~ /^\d+$/ or $n =~ /^\d+\.$/ or $n =~ /^\d+\.\d+$/ or $n =~ /^\.\d+$/
l!l&&r!l&&!r
000
$n =~ /^\d+$/ or $n =~ /^\d+\.$/ or $n =~ /^\d+\.\d+$/
l!l&&r!l&&!r
000
$n =~ /^\d+$/ or $n =~ /^\d+\.$/
l!l&&r!l&&!r
000
MC/DC0%0/4
$n =~ /^\d+$/ or $n =~ /^\d+\.$/ or $n =~ /^\d+\.\d+$/ or $n =~ /^\.\d+$/
$n =~ /^\d+$/ $n =~ /^\d+\.$/ $n =~ /^\d+\.\d+$/ $n =~ /^\.\d+$/
Truth table0%0/5
A or B or C or D
A= $n =~ /^\d+$/B= $n =~ /^\d+\.$/C= $n =~ /^\d+\.\d+$/D= $n =~ /^\.\d+$/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
405 0 return 1;
406 }
407 0 return 0;
408 }
409  
410 # adjust Fajr, Isha and Maghrib for locations in higher latitudes
411 0 ▶sub adjustHighLatTimes {
Subroutine adjustHighLatTimes: not called CC=9 SCAR=45.0
Pod undocumented
412 0 my ($self, @times) = @_;
413  
414 0 my $nightTime = $self->timeDiff($times[4], $times[1]); # sunset to sunrise
415  
416 # Adjust Fajr
417 0 my $FajrDiff = $self->nightPortion($self->{methodParams}->{$self->{calcMethod}}[0])* $nightTime;
418  
419 0 ▶ if (!numeric($times[0]) || $self->timeDiff($times[0], $times[1]) > $FajrDiff) {
Branch: 1 branch
BranchTrueFalseTotal
if (not numeric($times[0]) or $self->timeDiff($times[0], $times[1]) > $FajrDiff) 0 0 0
Condition0%0/3
not numeric($times[0]) or $self->timeDiff($times[0], $times[1]) > $FajrDiff
l!l&&r!l&&!r
000
MC/DC0%0/2
not numeric($times[0]) or $self->timeDiff($times[0], $times[1]) > $FajrDiff
not numeric($times[0]) $self->timeDiff($times[0], $times[1]) > $FajrDiff
Truth table0%0/3
not(A) or B
A= not numeric($times[0])B= $self->timeDiff($times[0], $times[1]) > $FajrDiff
ABresult
1X1
011
000
420 0 $times[0] = $times[1]- $FajrDiff;
421 }
422  
423 # Adjust Isha
424 0 ▶ my $IshaAngle = ($self->{methodParams}->{$self->{calcMethod}}[3] == 0) ? $self->{methodParams}->{$self->{calcMethod}}[4] : 18;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'methodParams'}{$self->{'calcMethod'}}[3] == 0 ? : 0 0 0
425  
426 0 my $IshaDiff = $self->nightPortion($IshaAngle)* $nightTime;
427  
428 0 ▶ if (!numeric($times[6]) || $self->timeDiff($times[4], $times[6]) > $IshaDiff) {
Branch: 1 branch
BranchTrueFalseTotal
if (not numeric($times[6]) or $self->timeDiff($times[4], $times[6]) > $IshaDiff) 0 0 0
Condition0%0/3
not numeric($times[6]) or $self->timeDiff($times[4], $times[6]) > $IshaDiff
l!l&&r!l&&!r
000
MC/DC0%0/2
not numeric($times[6]) or $self->timeDiff($times[4], $times[6]) > $IshaDiff
not numeric($times[6]) $self->timeDiff($times[4], $times[6]) > $IshaDiff
Truth table0%0/3
not(A) or B
A= not numeric($times[6])B= $self->timeDiff($times[4], $times[6]) > $IshaDiff
ABresult
1X1
011
000
429 0 $times[6] = $times[4]+ $IshaDiff;
430 }
431  
432 # Adjust Maghrib
433 0 ▶ my $MaghribAngle = ($self->{methodParams}->{$self->{calcMethod}}[1] == 0) ? $self->{methodParams}->{$self->{calcMethod}}[2] : 4;
Branch: 1 branch
BranchTrueFalseTotal
$self->{'methodParams'}{$self->{'calcMethod'}}[1] == 0 ? : 0 0 0
434  
435 0 my $MaghribDiff = $self->nightPortion($MaghribAngle)* $nightTime;
436  
437 0 ▶ if (!numeric($times[5]) || $self->timeDiff($times[4], $times[5]) > $MaghribDiff) {
Branch: 1 branch
BranchTrueFalseTotal
if (not numeric($times[5]) or $self->timeDiff($times[4], $times[5]) > $MaghribDiff) 0 0 0
Condition0%0/3
not numeric($times[5]) or $self->timeDiff($times[4], $times[5]) > $MaghribDiff
l!l&&r!l&&!r
000
MC/DC0%0/2
not numeric($times[5]) or $self->timeDiff($times[4], $times[5]) > $MaghribDiff
not numeric($times[5]) $self->timeDiff($times[4], $times[5]) > $MaghribDiff
Truth table0%0/3
not(A) or B
A= not numeric($times[5])B= $self->timeDiff($times[4], $times[5]) > $MaghribDiff
ABresult
1X1
011
000
438 0 $times[5] = $times[4]+ $MaghribDiff;
439 }
440  
441 0 return @times;
442 }
443  
444 # the night portion used for adjusting times in higher latitudes
445 0 ▶sub nightPortion {
Subroutine nightPortion: not called CC=4 SCAR=30.0
Pod undocumented
446 0 my ($self, $angle) = @_;
447 0 ▶ if ($self->{adjustHighLats} == $self->{AngleBased}) {return 1/60* $angle;}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"adjustHighLats"} == $self->{"AngleBased"}) 0 0 0
448 0 ▶ if ($self->{adjustHighLats} == $self->{MidNight}) {return 1/2;}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"adjustHighLats"} == $self->{"MidNight"}) 0 0 0
449 0 ▶ if ($self->{adjustHighLats} == $self->{OneSeventh}) {return 1/7;}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"adjustHighLats"} == $self->{"OneSeventh"}) 0 0 0
450 }
451  
452 # convert hours to day portions
453 0 ▶sub dayPortion {
Subroutine dayPortion: not called CC=2 SCAR=17.9
Pod undocumented
454 0 my ($self, @times) = @_;
455 0 ▶ for (my $i=0; $i<7; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < 7) 0 0 0
456 0 $times[$i] = $times[$i]/24;
457 }
458 0 return @times;
459 }
460  
461 #---------------------- Misc Functions -----------------------
462 # compute the difference between two times
463 0 ▶sub timeDiff {
Subroutine timeDiff: not called CC=1 SCAR=6.9
Pod undocumented
464 0 my ($self, $time1, $time2) = @_;
465 0 return $self->fixhour($time2- $time1);
466 }
467  
468 # add a leading 0 if necessary
469 0 ▶sub twoDigitsFormat {
Subroutine twoDigitsFormat: not called CC=2 SCAR=17.9
Pod undocumented
470 0 my ($self, $num) = @_;
471 0 ▶ return ($num <10) ? '0'. $num : $num;
Branch: 1 branch
BranchTrueFalseTotal
$num < 10 ? : 0 0 0
472 }
473  
474 # ---------------------- Julian Date Functions -----------------------
475 # calculate julian date from a calendar date
476 0 ▶sub julianDate {
Subroutine julianDate: not called CC=2 SCAR=17.9
Pod undocumented
477 0 my ($self, $year, $month, $day) = @_;
478 0 ▶ if ($month <= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($month <= 2) 0 0 0
479 0 $year -= 1;
480 0 $month += 12;
481 }
482 0 my $A = floor($year/ 100);
483 0 my $B = 2-$A+floor($A/ 4);
484 0 my $JD = floor(365.25*($year+4716))+floor(30.6001* ($month+ 1))+$day+$B-1524.5;
485 0 return $JD;
486 }
487  
488 # convert a calendar date to julian date (second method)
489 0 ▶sub calcJD {
Subroutine calcJD: not called CC=1 SCAR=6.9
Pod undocumented
490 0 my ($self, $year, $month, $day) = @_;
491  
492 0 my $J1970 = 2440588.0;
493 0 my $ms = timelocal(0, 0, 0, $day, $month-1, $year-1900);
494 0 my $days = floor($ms/ (1000 * 60 * 60* 24));
495 0 return $J1970+ $days- 0.5;
496 }
497  
498 # ---------------------- Trigonometric Functions -----------------------
499 # degree sin
500 0 ▶sub dsin {
Subroutine dsin: not called CC=1 SCAR=6.9
Pod undocumented
501 0 my ($self, $d) = @_;
502 0 return sin($self->dtr($d));
503 }
504 # degree cos
505 0 ▶sub dcos {
Subroutine dcos: not called CC=1 SCAR=6.9
Pod undocumented
506 0 my ($self, $d) = @_;
507 0 return cos($self->dtr($d));
508 }
509 # degree tan
510 0 ▶sub dtan {
Subroutine dtan: not called CC=1 SCAR=6.9
Pod undocumented
511 0 my ($self, $d) = @_;
512 0 return tan($self->dtr($d));
513 }
514 # degree arcsin
515 0 ▶sub darcsin {
Subroutine darcsin: not called CC=1 SCAR=6.9
Pod undocumented
516 0 my ($self, $x) = @_;
517 0 return $self->rtd(asin($x));
518 }
519 # degree arccos
520 0 ▶sub darccos {
Subroutine darccos: not called CC=1 SCAR=6.9
Pod undocumented
521 0 my ($self, $x) = @_;
522 0 return $self->rtd(acos($x));
523 }
524 # degree arctan
525 0 ▶sub darctan {
Subroutine darctan: not called CC=1 SCAR=6.9
Pod undocumented
526 0 my ($self, $x) = @_;
527 0 return $self->rtd(atan($x));
528 }
529 # degree arctan2
530 0 ▶sub darctan2 {
Subroutine darctan2: not called CC=1 SCAR=6.9
Pod undocumented
531 0 my ($self, $y, $x) = @_;
532 0 return $self->rtd(atan2($y, $x));
533 }
534 # degree arccot
535 0 ▶sub darccot {
Subroutine darccot: not called CC=1 SCAR=6.9
Pod undocumented
536 0 my ($self, $x) = @_;
537 0 return $self->rtd(atan(1/$x));
538 }
539 # degree to radian
540 0 ▶sub dtr {
Subroutine dtr: not called CC=1 SCAR=6.9
Pod undocumented
541 0 my ($self, $d) = @_;
542 0 return ($d * PI) / 180.0;
543 }
544 # radian to degree
545 0 ▶sub rtd {
Subroutine rtd: not called CC=1 SCAR=6.9
Pod undocumented
546 0 my ($self, $r) = @_;
547 0 return ($r * 180.0) / PI;
548 }
549 # range reduce angle in degrees.
550 0 ▶sub fixangle {
Subroutine fixangle: not called CC=2 SCAR=17.9
Pod undocumented
551 0 my ($self, $a) = @_;
552 0 $a = $a - 360.0 * floor($a / 360.0);
553 0 ▶ $a = ($a < 0) ? ($a + 360.0) : $a;
Branch: 1 branch
BranchTrueFalseTotal
$a < 0 ? : 0 0 0
554 0 return $a;
555 }
556 # range reduce hours to 0..23
557 0 ▶sub fixhour {
Subroutine fixhour: not called CC=2 SCAR=17.9
Pod undocumented
558 0 my ($self, $a) = @_;
559 0 $a = $a - 24.0 * floor($a / 24.0);
560 0 ▶ $a = $a < 0 ? $a + 24.0 : $a;
Branch: 1 branch
BranchTrueFalseTotal
$a < 0 ? : 0 0 0
561 0 return $a;
562 }
563  
564 0 ▶sub logs {
Subroutine logs: not called CC=3 SCAR=24.8
Pod undocumented
565 0 my ($self, $logs) = @_;
566 0 ▶ if (!defined ($logs)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $logs) 0 0 0
567 0 return $self->{logs};
568 }
569 0 ▶ if ($logs eq "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($logs eq '') { } 0 0 0
570 0 $self->{logs} = "";
571 }
572 else {
573 0 $self->{logs} .= $logs . "\n";
574 }
575 }
576 #=========================================================#
577 1 1;
578  
579 =encoding utf-8
580  
581 =head1 NAME
582  
583 Religion::Islam::PrayTime - Calculates Muslim Prayers Times, Sunrise, and Sunset
584  
585 =head1 SYNOPSIS
586  
587 use Religion::Islam::PrayTime;
588  
589 $date = time();
590 $latitude = 30.0599; # Cairo, Egypt
591 $longitude = 31.2599; # Cairo, Egypt
592 $timeZone = 2; # Cairo, Egypt
593
594 ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $dst) = localtime(time);
595 $mon++; $year += 1900;
596 #$year = 2014; $month = 12; $day = 5;
597 print "Today: $mon/$mday/$year \n";
598
599 $calcMethod = 4;
600 $prayTime = Religion::Islam::PrayTime->new($calcMethod);
601  
602 # Calculation Method: 0..7
603 # 0 Ithna Ashari
604 # 1 University of Islamic Sciences, Karachi
605 # 2 Islamic Society of North America (ISNA)
606 # 3 Muslim World League (MWL)
607 # 4 Umm al-Qura, Makkah
608 # 5 Egyptian General Authority of Survey
609 # 6 Institute of Geophysics, University of Tehran
610 # 7 Custom Setting
611  
612 $calcMethod = 5;
613 $prayTime->setCalcMethod($calcMethod);
614  
615 # Time Formats: 0..3
616 # 0 24-hour format
617 # 1 12-hour format
618 # 2 12-hour format with no suffix
619 # 3 floating point number
620 $prayTime->setTimeFormat(1);
621
622 # set text for am/pm suffix for other languages, defaults english
623 $prayTime->am_pm("am", "pm");
624  
625 # Juristic method for Asr: 0..1
626 # 0 Shafii (standard)
627 # 1 Hanafi
628 $prayTime->setAsrMethod(0);
629  
630 # Adjusting Methods for Higher Latitudes: 0..3
631 # 0 No adjustment
632 # 1 middle of night
633 # 2 1/7th of night
634 # 3 angle/60th of night
635 $prayTime->setHighLatsMethod(0);
636  
637 # set the angle for calculating Fajr
638 #$prayTime->setFajrAngle($angle);
639  
640 #set the angle for calculating Maghrib
641 #$prayTime->setMaghribAngle($angle);
642  
643 # set the angle for calculating Isha
644 #$prayTime->setIshaAngle($angle);
645  
646 # set the minutes after mid-day for calculating Dhuhr
647 #$prayTime->setDhuhrMinutes($minutes);
648  
649 #set the minutes after Sunset for calculating Maghrib
650 #$prayTime->setMaghribMinutes($minutes);
651  
652 #set the minutes after Maghrib for calculating Isha
653 #$prayTime->setIshaMinutes($minutes);
654  
655 # these functions return array of times
656 #@times = $prayTime->getPrayerTimes($date, $latitude, $longitude, $timeZone);
657 #@times = $prayTime->getDatePrayerTimes($year, $month, $day, $latitude, $longitude, $timeZone);
658 #print "Fajr\tSunrise\tDhuhr\tAsr\tSunset\tMaghrib\tIsha\n";
659 #print join "\t", @times , "\n";
660  
661 # these functions return named hash array of times
662 %times = $prayTime->getDatePrayerTimesHash($year, $month, $day, $latitude, $longitude, $timeZone);
663 #%times = $prayTime->getPrayerTimesHash($date, $latitude, $longitude, $timeZone);
664 while (($k, $v) = each %times) {
665 print "$k: $v\n";
666 }
667  
668 =head1 DESCRIPTION
669  
670 This module calculates Muslim prayers times, sunrise and sunset for any location on the earth.
671  
672 =head1 SEE ALSO
673  
674 L<Date::HijriDate>
675 L<Religion::Islam::Qibla>
676 L<Religion::Islam::Quran>
677 L<Religion::Islam::PrayTime>
678  
679 =head1 AUTHOR
680  
681 Ahmed Amin Elsheshtawy, <support@islamware.com> <support@mewsoft.com>
682 Website: http://www.islamware.com http://www.mewsoft.com
683  
684 =head1 COPYRIGHT AND LICENSE
685  
686 Copyright (C) 2013-2014 by Dr. Ahmed Amin Elsheshtawy webmaster@islamware.com,
687 L<http://www.islamware.com>
688 L<http://www.mewsoft.com>
689  
690 This library is free software; you can redistribute it and/or modify
691 it under the same terms as Perl itself.
692  
693 =cut
↑ Summary