File Coverage

blib/lib/Religion/Islam/PrayTime.pm
Criterion Covered Total %
statement 15 287 5.2
branch 0 56 0.0
condition 0 23 0.0
subroutine 5 58 8.6
pod 0 53 0.0
total 20 477 4.1


line stmt bran cond sub pod time code
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     1   24104 use strict;
  1         2  
  1         40  
12 1     1   5 use Carp;
  1         2  
  1         95  
13 1     1   912 use POSIX;
  1         7953  
  1         7  
14 1     1   5804 use Time::Local;
  1         2049  
  1         104  
15 1     1   8 use constant PI => 4 * atan2(1, 1); #3.1415926535897932
  1         3  
  1         4500  
16              
17             our $VERSION = '1.06';
18             #=========================================================#
19             sub new {
20 0     0 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             sub PrayTime {
85 0     0 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             sub getDatePrayerTimes {
109 0     0 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             sub getPrayerTimes {
119 0     0 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             sub getDatePrayerTimesHash {
128 0     0 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);
  0            
131 0           return %times;
132             }
133              
134             # return prayer times for a given timestamp in a hash
135             sub getPrayerTimesHash {
136 0     0 0   my ($self, $timestamp, $latitude, $longitude, $timeZone) = @_;
137 0           my %times;
138 0           @times{@{$self->{timeNames}}} = $self->getPrayerTimes($timestamp, $latitude, $longitude, $timeZone);
  0            
139 0           return %times;
140             }
141              
142             # set the calculation method
143             sub setCalcMethod {
144 0     0 0   my ($self, $methodID) = @_;
145 0           $self->{calcMethod} = $methodID;
146             }
147              
148             # set the juristic method for Asr
149             sub setAsrMethod {
150 0     0 0   my ($self, $methodID) = @_;
151 0 0 0       if ($methodID < 0 || $methodID > 1) {return};
  0            
152 0           $self->{asrJuristic} = $methodID;
153             }
154              
155             # set the angle for calculating Fajr
156             sub setFajrAngle {
157 0     0 0   my ($self, $angle) = @_;
158 0           $self->setCustomParams($angle, undef, undef, undef, undef);
159             }
160              
161             #set the angle for calculating Maghrib
162             sub setMaghribAngle {
163 0     0 0   my ($self, $angle) = @_;
164 0           $self->setCustomParams(undef, 0, $angle, undef, undef);
165             }
166              
167             # set the angle for calculating Isha
168             sub setIshaAngle {
169 0     0 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             sub setDhuhrMinutes {
175 0     0 0   my ($self, $minutes) = @_;
176 0           $self->{dhuhrMinutes} = $minutes;
177             }
178              
179             #set the minutes after Sunset for calculating Maghrib
180             sub setMaghribMinutes {
181 0     0 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             sub setIshaMinutes {
187 0     0 0   my ($self, $minutes) = @_;
188 0           $self->setCustomParams(undef, undef, undef, 1, $minutes);
189             }
190              
191             # set custom values for calculation parameters
192             sub setCustomParams {
193 0     0 0   my ($self, @params) = @_;
194 0           for (my $i=0; $i<5; $i++) {
195 0 0         if (!defined($params[$i])) {
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             sub setHighLatsMethod {
207 0     0 0   my ($self, $methodID) = @_;
208 0           $self->{adjustHighLats} = $methodID;
209             }
210              
211             # set the time format
212             sub setTimeFormat {
213 0     0 0   my ($self, $timeFormat) = @_;
214 0           $self->{timeFormat} = $timeFormat;
215             }
216              
217             sub am_pm {
218 0     0 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             sub floatToTime24 {
226 0     0 0   my ($self, $time) = @_;
227 0 0         if (!$time) {return $self->{InvalidTime}};
  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             sub floatToTime12 {
236 0     0 0   my ($self, $time, $noSuffix) = @_;
237 0   0       $noSuffix ||= "";
238 0 0         if (!$time) {return $self->{InvalidTime}};
  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 0         my $suffix = $hours >= 12 ? $self->{pm} : $self->{am};
243 0           $hours = ($hours+ 12- 1)% 12+ 1;
244 0 0         return $hours. ':'. $self->twoDigitsFormat($minutes). ($noSuffix ? '' : $suffix);
245             }
246              
247             # convert float hours to 12h format with no suffix
248             sub floatToTime12NS {
249 0     0 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             sub sunPosition {
260 0     0 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             sub equationOfTime {
281 0     0 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             sub sunDeclination {
288 0     0 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             sub computeMidDay {
295 0     0 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             sub computeTime {
303 0     0 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 0         return ($Z+ ($G>90 ? -$V : $V));
308             }
309              
310             # compute the time of Asr
311             # Shafii: step=1, Hanafi: step=2
312             sub computeAsr {
313 0     0 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             sub computeTimes {
322 0     0 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             sub computeDayTimes {
339 0     0 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++) {
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             sub adjustTimes {
351 0     0 0   my ($self, @times) = @_;
352              
353 0           for (my $i=0; $i<7; $i++) {
354 0           $times[$i] += $self->{timeZone} - $self->{lng}/15;
355             }
356              
357 0           $times[2] += $self->{dhuhrMinutes}/60; #Dhuhr
358            
359             # Maghrib
360 0 0         if ($self->{methodParams}->{$self->{calcMethod}}[1] == 1) {
361 0           $times[5] = $times[4] + $self->{methodParams}->{$self->{calcMethod}}[2]/60;
362             }
363            
364             # Isha
365 0 0         if ($self->{methodParams}->{$self->{calcMethod}}[3] == 1) {
366 0           $times[6] = $times[5]+ $self->{methodParams}->{$self->{calcMethod}}[4]/60;
367             }
368              
369 0 0         if ($self->{adjustHighLats} != $self->{None}) {
370 0           @times = $self->adjustHighLatTimes(@times);
371             }
372 0           return @times;
373             }
374              
375             # convert times array to given time format
376             sub adjustTimesFormat {
377 0     0 0   my ($self, @times) = @_;
378              
379 0 0         if ($self->{timeFormat} == $self->{Float}) {
380 0           map {$_ = sprintf("%0.$self->{decimal_size}f", $_)} @times;
  0            
381 0           return @times;
382             };
383              
384 0           for (my $i=0; $i<7; $i++) {
385 0 0         if ($self->{timeFormat} == $self->{Time12}) {
    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             sub decimal_size {
398 0     0 0   my ($self, $size) = @_;
399 0           $self->{decimal_size} = $size;
400             }
401              
402             sub numeric {
403 0     0 0   my ($self, $n) = @_;
404 0 0 0       if (($n=~/^\d+$/) || ($n=~ /^\d+\.$/) || ($n=~ /^\d+\.\d+$/) || ($n=~ /^\.\d+$/)) {
      0        
      0        
405 0           return 1;
406             }
407 0           return 0;
408             }
409              
410             # adjust Fajr, Isha and Maghrib for locations in higher latitudes
411             sub adjustHighLatTimes {
412 0     0 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 0 0       if (!numeric($times[0]) || $self->timeDiff($times[0], $times[1]) > $FajrDiff) {
420 0           $times[0] = $times[1]- $FajrDiff;
421             }
422              
423             # Adjust Isha
424 0 0         my $IshaAngle = ($self->{methodParams}->{$self->{calcMethod}}[3] == 0) ? $self->{methodParams}->{$self->{calcMethod}}[4] : 18;
425              
426 0           my $IshaDiff = $self->nightPortion($IshaAngle)* $nightTime;
427              
428 0 0 0       if (!numeric($times[6]) || $self->timeDiff($times[4], $times[6]) > $IshaDiff) {
429 0           $times[6] = $times[4]+ $IshaDiff;
430             }
431              
432             # Adjust Maghrib
433 0 0         my $MaghribAngle = ($self->{methodParams}->{$self->{calcMethod}}[1] == 0) ? $self->{methodParams}->{$self->{calcMethod}}[2] : 4;
434              
435 0           my $MaghribDiff = $self->nightPortion($MaghribAngle)* $nightTime;
436              
437 0 0 0       if (!numeric($times[5]) || $self->timeDiff($times[4], $times[5]) > $MaghribDiff) {
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             sub nightPortion {
446 0     0 0   my ($self, $angle) = @_;
447 0 0         if ($self->{adjustHighLats} == $self->{AngleBased}) {return 1/60* $angle;}
  0            
448 0 0         if ($self->{adjustHighLats} == $self->{MidNight}) {return 1/2;}
  0            
449 0 0         if ($self->{adjustHighLats} == $self->{OneSeventh}) {return 1/7;}
  0            
450             }
451              
452             # convert hours to day portions
453             sub dayPortion {
454 0     0 0   my ($self, @times) = @_;
455 0           for (my $i=0; $i<7; $i++) {
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             sub timeDiff {
464 0     0 0   my ($self, $time1, $time2) = @_;
465 0           return $self->fixhour($time2- $time1);
466             }
467              
468             # add a leading 0 if necessary
469             sub twoDigitsFormat {
470 0     0 0   my ($self, $num) = @_;
471 0 0         return ($num <10) ? '0'. $num : $num;
472             }
473              
474             # ---------------------- Julian Date Functions -----------------------
475             # calculate julian date from a calendar date
476             sub julianDate {
477 0     0 0   my ($self, $year, $month, $day) = @_;
478 0 0         if ($month <= 2) {
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             sub calcJD {
490 0     0 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             sub dsin {
501 0     0 0   my ($self, $d) = @_;
502 0           return sin($self->dtr($d));
503             }
504             # degree cos
505             sub dcos {
506 0     0 0   my ($self, $d) = @_;
507 0           return cos($self->dtr($d));
508             }
509             # degree tan
510             sub dtan {
511 0     0 0   my ($self, $d) = @_;
512 0           return tan($self->dtr($d));
513             }
514             # degree arcsin
515             sub darcsin {
516 0     0 0   my ($self, $x) = @_;
517 0           return $self->rtd(asin($x));
518             }
519             # degree arccos
520             sub darccos {
521 0     0 0   my ($self, $x) = @_;
522 0           return $self->rtd(acos($x));
523             }
524             # degree arctan
525             sub darctan {
526 0     0 0   my ($self, $x) = @_;
527 0           return $self->rtd(atan($x));
528             }
529             # degree arctan2
530             sub darctan2 {
531 0     0 0   my ($self, $y, $x) = @_;
532 0           return $self->rtd(atan2($y, $x));
533             }
534             # degree arccot
535             sub darccot {
536 0     0 0   my ($self, $x) = @_;
537 0           return $self->rtd(atan(1/$x));
538             }
539             # degree to radian
540             sub dtr {
541 0     0 0   my ($self, $d) = @_;
542 0           return ($d * PI) / 180.0;
543             }
544             # radian to degree
545             sub rtd {
546 0     0 0   my ($self, $r) = @_;
547 0           return ($r * 180.0) / PI;
548             }
549             # range reduce angle in degrees.
550             sub fixangle {
551 0     0 0   my ($self, $a) = @_;
552 0           $a = $a - 360.0 * floor($a / 360.0);
553 0 0         $a = ($a < 0) ? ($a + 360.0) : $a;
554 0           return $a;
555             }
556             # range reduce hours to 0..23
557             sub fixhour {
558 0     0 0   my ($self, $a) = @_;
559 0           $a = $a - 24.0 * floor($a / 24.0);
560 0 0         $a = $a < 0 ? $a + 24.0 : $a;
561 0           return $a;
562             }
563              
564             sub logs {
565 0     0 0   my ($self, $logs) = @_;
566 0 0         if (!defined ($logs)) {
567 0           return $self->{logs};
568             }
569 0 0         if ($logs eq "") {
570 0           $self->{logs} = "";
571             }
572             else {
573 0           $self->{logs} .= $logs . "\n";
574             }
575             }
576             #=========================================================#
577             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
675             L
676             L
677             L
678              
679             =head1 AUTHOR
680              
681             Ahmed Amin Elsheshtawy,
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
688             L
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