I18N_Arabic
[ class tree: I18N_Arabic ] [ index: I18N_Arabic ] [ all elements ]

Source for file Salat.php

Documentation is available at Salat.php

  1. <?php
  2. /**
  3.  * ----------------------------------------------------------------------
  4.  *  
  5.  * Copyright (c) 2006-2012 Khaled Al-Sham'aa
  6.  *  
  7.  * http://www.ar-php.org
  8.  *  
  9.  * PHP Version 5
  10.  *  
  11.  * ----------------------------------------------------------------------
  12.  *  
  13.  * LICENSE
  14.  *
  15.  * This program is open source product; you can redistribute it and/or
  16.  * modify it under the terms of the GNU Lesser General Public License (LGPL)
  17.  * as published by the Free Software Foundation; either version 3
  18.  * of the License, or (at your option) any later version.
  19.  *  
  20.  * This program is distributed in the hope that it will be useful,
  21.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.  * GNU Lesser General Public License for more details.
  24.  *  
  25.  * You should have received a copy of the GNU Lesser General Public License
  26.  * along with this program.  If not, see <http://www.gnu.org/licenses/lgpl.txt>.
  27.  *  
  28.  * ----------------------------------------------------------------------
  29.  *  
  30.  * Class Name: Muslim Prayer Times
  31.  *  
  32.  * Filename:   Salat.php
  33.  *  
  34.  * Original    Author(s): Khaled Al-Sham'aa <khaled@ar-php.org>
  35.  *  
  36.  * Purpose:    The five Islamic prayers are named Fajr, Zuhr, Asr, Maghrib
  37.  *             and Isha. The timing of these five prayers varies from place
  38.  *             to place and from day to day. It is obligatory for Muslims
  39.  *             to perform these prayers at the correct time.
  40.  *              
  41.  * ----------------------------------------------------------------------
  42.  *  
  43.  * Source: http://qasweb.org/qasforum/index.php?showtopic=177&st=0
  44.  * By: Mohamad Magdy <mohamad_magdy_egy@hotmail.com>
  45.  *  
  46.  * ----------------------------------------------------------------------
  47.  *  
  48.  * Muslim Prayer Times
  49.  *
  50.  * Using this PHP Class you can calculate the time of Muslim prayer
  51.  * according to the geographic location.
  52.  * 
  53.  * The five Islamic prayers are named Fajr, Zuhr, Asr, Maghrib and Isha. The timing
  54.  * of these five prayers varies from place to place and from day to day. It is
  55.  * obligatory for Muslims to perform these prayers at the correct time.
  56.  * 
  57.  * The prayer times for any given location on earth may be determined mathematically
  58.  * if the latitude and longitude of the location are known. However, the theoretical
  59.  * determination of prayer times is a lengthy process. Much of this tedium may be
  60.  * alleviated by using computer programs.
  61.  * 
  62.  * Definition of prayer times
  63.  * 
  64.  * - FAJR starts with the dawn or morning twilight. Fajr ends just before sunrise.
  65.  * - ZUHR begins after midday when the trailing limb of the sun has passed the
  66.  *   meridian. For convenience, many published prayer timetables add five minutes to
  67.  *   mid-day (zawal) to obtain the start of Zuhr. Zuhr ends at the start of Asr time.
  68.  * - The timing of ASR depends on the length of the shadow cast by an object.
  69.  *   According to the Shafi school of jurisprudence, Asr begins when the length of
  70.  *   the shadow of an object exceeds the length of the object. According to the
  71.  *   Hanafi school of jurisprudence, Asr begins when the length of the shadow
  72.  *   exceeds TWICE the length of the object. In both cases, the minimum length of
  73.  *   shadow (which occurs when the sun passes the meridian) is subtracted from the
  74.  *   length of the shadow before comparing it with the length of the object.
  75.  * - MAGHRIB begins at sunset and ends at the start of isha.
  76.  * - ISHA starts after dusk when the evening twilight disappears.
  77.  *
  78.  * Example:
  79.  * <code>
  80.  *     date_default_timezone_set('UTC');
  81.  *     
  82.  *     include('./I18N/Arabic.php');
  83.  *     $obj = new I18N_Arabic('Salat');
  84.  * 
  85.  *     $obj->setLocation(33.513,36.292,2);
  86.  *     $obj->setDate(date('j'), date('n'), date('Y'));
  87.  * 
  88.  *     $times = $obj->getPrayTime();
  89.  * 
  90.  *     echo '<b>Damascus, Syria</b><br />';
  91.  *     echo date('l F j, Y').'<br /><br />';
  92.  *        
  93.  *     echo "<b class=hilight>Imsak:</b> {$times[8]}<br />";
  94.  *     echo "<b class=hilight>Fajr:</b> {$times[0]}<br />";
  95.  *     echo "<b class=hilight>Sunrise:</b> {$times[1]}<br />";
  96.  *     echo "<b class=hilight>Zuhr:</b> {$times[2]}<br />";
  97.  *     echo "<b class=hilight>Asr:</b> {$times[3]}<br />";
  98.  *     echo "<b class=hilight>Sunset:</b> {$times[6]}<br />";
  99.  *     echo "<b class=hilight>Maghrib:</b> {$times[4]}<br />";
  100.  *     echo "<b class=hilight>Isha:</b> {$times[5]}<br />";
  101.  *     echo "<b class=hilight>Midnight:</b> {$times[7]}<br />";
  102.  * </code>
  103.  * 
  104.  * Qibla Determination Methods - Basic Spherical Trigonometric Formula
  105.  * 
  106.  * The problem of qibla determination has a simple formulation in spherical
  107.  * trigonometry. A is a given location, K is the Ka'ba, and N is the North Pole.
  108.  * The great circle arcs AN and KN are along the meridians through A and K,
  109.  * respectively, and both point to the north. The qibla is along the great circle
  110.  * arc AK. The spherical angle q = NAK is the angle at A from the north direction
  111.  * AN to the direction AK towards the Ka'ba, and so q is the qibla bearing to be
  112.  * computed. Let F and L be the latitude and longitude of A, and FK and LK be
  113.  * the latitude and longitude of K (the Ka'ba). If all angles and arc lengths
  114.  * are measured in degrees, then it is seen that the arcs AN and KN are of measure
  115.  * 90 - F and 90 - FK, respectively. Also, the angle ANK between the meridians
  116.  * of K and A equals the difference between the longitudes of A and K, that is,
  117.  * LK - L, no matter what the prime meridian is. Here we are given two sides and
  118.  * the included angle of a spherical triangle, and it is required to determine one
  119.  * other angle. One of the simplest solutions is given by the formula:
  120.  * <pre>
  121.  *                       -1              sin(LK - L)
  122.  *                q = tan   ------------------------------------------
  123.  *                              cos F tan FK - sin F cos(LK - L)
  124.  * </pre>
  125.  * In this Equation, the sign of the input quantities are assumed as follows:
  126.  * latitudes are positive if north, negative if south; longitudes are positive
  127.  * if east, negative if west. The quadrant of q is assumed to be so selected
  128.  * that sin q and cos q have the same sign as the numerator and denominator of
  129.  * this Equation. With these conventions, q will be positive for bearings east
  130.  * of north, negative for bearings west of north.
  131.  * 
  132.  * Reference:
  133.  * The Correct Qibla, S. Kamal Abdali <k.abdali@acm.org>
  134.  * PDF version in http://www.patriot.net/users/abdali/ftp/qibla.pdf
  135.  *
  136.  * Example:
  137.  * <code>
  138.  *     date_default_timezone_set('UTC');
  139.  *     
  140.  *     include('./I18N/Arabic.php');
  141.  *     $obj = new I18N_Arabic('Salat');
  142.  * 
  143.  *     $obj->setLocation(33.513,36.292,2);
  144.  *
  145.  *     $direction = $obj->getQibla();
  146.  *     echo "<b>Qibla Direction (from the north direction):</b> $direction<br />";
  147.  * </code>
  148.  *  
  149.  * @category  I18N
  150.  * @package   I18N_Arabic
  151.  * @author    Khaled Al-Sham'aa <khaled@ar-php.org>
  152.  * @copyright 2006-2012 Khaled Al-Sham'aa
  153.  *    
  154.  * @license   LGPL <http://www.gnu.org/licenses/lgpl.txt>
  155.  * @link      http://www.ar-php.org
  156.  */
  157.  
  158. // New in PHP V5.3: Namespaces
  159. // namespace I18N\Arabic;
  160. // 
  161. // $obj = new I18N\Arabic\Salat();
  162. // 
  163. // use I18N\Arabic;
  164. // $obj = new Arabic\Salat();
  165. //
  166. // use I18N\Arabic\Salat as Salat;
  167. // $obj = new Salat();
  168.  
  169. /**
  170.  * This PHP class calculate the time of Muslim prayer according to the geographic
  171.  * location.
  172.  *  
  173.  * @category  I18N
  174.  * @package   I18N_Arabic
  175.  * @author    Khaled Al-Sham'aa <khaled@ar-php.org>
  176.  * @copyright 2006-2012 Khaled Al-Sham'aa
  177.  *    
  178.  * @license   LGPL <http://www.gnu.org/licenses/lgpl.txt>
  179.  * @link      http://www.ar-php.org
  180.  */ 
  181. {
  182.     /**
  183.      * السنة
  184.      * @ignore
  185.      */
  186.     protected $year 1975;
  187.     
  188.     /**
  189.      * الشهر
  190.      * @ignore
  191.      */
  192.     protected $month 8;
  193.     
  194.     /**
  195.      * اليوم
  196.      * @ignore
  197.      */
  198.     protected $day 2;
  199.     
  200.     /**
  201.      * فرق التوقيت العالمى
  202.      * @ignore
  203.      */
  204.     protected $zone 2;
  205.     
  206.     /**
  207.      * خط الطول الجغرافى للمكان
  208.      * @ignore
  209.      */
  210.     protected $long 37.15861;
  211.     
  212.     /**
  213.      * خط العرض الجغرافى
  214.      * @ignore
  215.      */
  216.     protected $lat 36.20278;
  217.     
  218.     /**
  219.      * الارتفاع عن سطح البحر
  220.      * @ignore
  221.      */
  222.     protected $elevation 0;
  223.     
  224.     /**
  225.      * زاوية الشروق والغروب
  226.      * @ignore
  227.      */
  228.     protected $AB2 = -0.833333;
  229.  
  230.     /**
  231.      * زاوية العشاء
  232.      * @ignore
  233.      */
  234.     protected $AG2 = -18;
  235.     
  236.     /**
  237.      * زاوية الفجر
  238.      * @ignore
  239.      */
  240.     protected $AJ2 = -18;
  241.     
  242.     /**
  243.      * المذهب
  244.      * @ignore
  245.      */
  246.     protected $school 'Shafi';
  247.     
  248.     /**
  249.      * الطائفة
  250.      * @ignore
  251.      */
  252.     protected $view 'Sunni';
  253.  
  254.     /**
  255.      * Loads initialize values
  256.      *
  257.      * @ignore
  258.      */         
  259.     public function __construct()
  260.     {
  261.     }
  262.         
  263.     /**
  264.      * Setting date of day for Salat calculation
  265.      *      
  266.      * @param integer $m Month of date you want to calculate Salat in
  267.      * @param integer $d Day of date you want to calculate Salat in
  268.      * @param integer $y Year (four digits) of date you want to calculate Salat in
  269.      *      
  270.      * @return object $this to build a fluent interface
  271.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  272.      */
  273.     public function setDate($m 8$d 2$y 1975)
  274.     {
  275.         if (is_numeric($y&& $y && $y 3000{
  276.             $this->year floor($y);
  277.         }
  278.         
  279.         if (is_numeric($m&& $m >= && $m <= 12{
  280.             $this->month floor($m);
  281.         }
  282.         
  283.         if (is_numeric($d&& $d >= && $d <= 31{
  284.             $this->day floor($d);
  285.         }
  286.         
  287.         return $this;
  288.     }
  289.     
  290.     /**
  291.      * Setting location information for Salat calculation
  292.      *      
  293.      * @param decimal $l1 Latitude of location you want to calculate Salat time in
  294.      * @param decimal $l2 Longitude of location you want to calculate Salat time in
  295.      * @param integer $z  Time Zone, offset from UTC (see also Greenwich Mean Time)
  296.      * @param integer $e  Elevation, it is the observer's height in meters.
  297.      *      
  298.      * @return object $this to build a fluent interface
  299.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  300.      */
  301.     public function setLocation($l1 36.20278$l2 37.15861$z 2$e 0)
  302.     {
  303.         if (is_numeric($l1&& $l1 >= -180 && $l1 <= 180{
  304.             $this->lat $l1;
  305.         }
  306.         
  307.         if (is_numeric($l2&& $l2 >= -180 && $l2 <= 180{
  308.             $this->long $l2;
  309.         }
  310.         
  311.         if (is_numeric($z&& $z >= -12 && $z <= 12{
  312.             $this->zone floor($z);
  313.         }
  314.         
  315.         if (is_numeric($e)) {
  316.             $this->elevation $e;
  317.         }
  318.         
  319.         return $this;
  320.     }
  321.     
  322.     /**
  323.      * Setting rest of Salat calculation configuration
  324.      * 
  325.      * Convention                                 Fajr Angle  Isha Angle
  326.      * 
  327.      * Muslim World League                              -18       -17
  328.      *      
  329.      * Islamic Society of North America (ISNA)          -15       -15
  330.      *      
  331.      * Egyptian General Authority of Survey               -19.5     -17.5
  332.      *      
  333.      * Umm al-Qura University, Makkah                   -18.5
  334.      * Isha 90  min after Maghrib, 120 min during Ramadan
  335.      *      
  336.      * University of Islamic Sciences, Karachi          -18       -18
  337.      *      
  338.      * Institute of Geophysics, University of Tehran      -17.7     -14(*)
  339.      *      
  340.      * Shia Ithna Ashari, Leva Research Institute, Qum  -16       -14
  341.      * 
  342.      * (*) Isha angle is not explicitly defined in Tehran method
  343.      * Fajr Angle = $fajrArc, Isha Angle = $ishaArc
  344.      *                 
  345.      * - حزب العلماء في لندن لدول
  346.      * أوروبا في خطوط عرض تزيد على 48
  347.      *       
  348.      *      $ishaArc = -17
  349.      *      $fajrArc = -17
  350.      *      
  351.      * @param string  $sch        [Shafi|Hanafi] to define Muslims Salat
  352.      *                             calculation method (affect Asr time)
  353.      * @param decimal $sunriseArc Sun rise arc (default value is -0.833333)
  354.      * @param decimal $ishaArc    Isha arc (default value is -18)
  355.      * @param decimal $fajrArc    Fajr arc (default value is -18)
  356.      * @param string  $view       [Sunni|Shia] to define Muslims Salat calculation
  357.      *                             method (affect Maghrib and Midnight time)
  358.      *      
  359.      * @return object $this to build a fluent interface
  360.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  361.      */
  362.     public function setConf($sch 'Shafi'$sunriseArc = -0.833333
  363.                             $ishaArc = -17.5$fajrArc = -19.5$view 'Sunni')
  364.     {
  365.         $sch ucfirst($sch);
  366.         
  367.         if ($sch == 'Shafi' || $sch == 'Hanafi'{
  368.             $this->school $sch;
  369.         }
  370.         
  371.         if (is_numeric($sunriseArc&& $sunriseArc >= -180 && $sunriseArc <= 180{
  372.             $this->AB2 $sunriseArc;
  373.         }
  374.         
  375.         if (is_numeric($ishaArc&& $ishaArc >= -180 && $ishaArc <= 180{
  376.             $this->AG2 $ishaArc;
  377.         }
  378.         
  379.         if (is_numeric($fajrArc&& $fajrArc >= -180 && $fajrArc <= 180{
  380.             $this->AJ2 $fajrArc;
  381.         }
  382.         
  383.         if ($view == 'Sunni' || $view == 'Shia'{
  384.             $this->view $view;
  385.         }
  386.         
  387.         return $this;
  388.     }
  389.     
  390.     /**
  391.      * Calculate Salat times for the date set in setSalatDate methode, and
  392.      * location set in setSalatLocation.
  393.      *                        
  394.      * @return array of Salat times + sun rise in the following format
  395.      *                hh:mm where hh is the hour in local format and 24 mode
  396.      *                mm is minutes with leading zero to be 2 digits always
  397.      *                array items is [Fajr, Sunrise, Zuhr, Asr, Maghrib, Isha]
  398.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  399.      * @author Mohamad Magdy <mohamad_magdy_egy@hotmail.com>
  400.      * @source http://qasweb.org/qasforum/index.php?showtopic=177&st=0
  401.      */
  402.     public function getPrayTime()
  403.     {
  404.         $prayTime array();
  405.         
  406.         // نحسب اليوم الجوليانى
  407.         $d ((367 $this->year(floor((4($this->year 
  408.              floor(($this->month 912)))) floor(275 ($this->month 9)) 
  409.              $this->day 730531.5);
  410.         
  411.         // نحسب طول الشمس الوسطى
  412.         $L fmod(280.461 0.9856474 $d360);
  413.         
  414.         // ثم نحسب حصة الشمس الوسطى
  415.         $M fmod(357.528 0.9856003 $d360);
  416.         
  417.         // ثم نحسب طول الشمس البروجى
  418.         $lambda $L 1.915 sin($M pi(180
  419.                   0.02 sin($M pi(180);
  420.         
  421.         // ثم نحسب ميل دائرة البروج
  422.         $obl 23.439 0.0000004 $d;
  423.         
  424.         // ثم نحسب المطلع المستقيم
  425.         $alpha atan(cos($obl pi(180tan($lambda pi(180)) 
  426.                  180 pi();
  427.         $alpha $alpha (360 floor($alpha 360));
  428.         
  429.         // ثم نعدل المطلع المستقيم
  430.         $alpha $alpha 90 ((int)($lambda 90- (int)($alpha 90));
  431.         
  432.         // نحسب الزمن النجمى بالدرجات الزاوية
  433.         $ST fmod(100.46 0.985647352 $d360);
  434.         
  435.         // ثم نحسب ميل الشمس الزاوى
  436.         $Dec asin(sin($obl pi(180sin($lambda pi(180)) 180 pi();
  437.         
  438.         // نحسب زوال الشمس الوسطى
  439.         $noon fmod(abs($alpha $ST)360);
  440.         
  441.         // ثم الزوالى العالمى
  442.         $un_noon $noon $this->long;
  443.         
  444.         // ثم الزوال المحلى
  445.         $local_noon fmod(($un_noon/15$this->zone24);
  446.         
  447.         // وقت صلاة الظهر
  448.         $Dhuhr       $local_noon 24;
  449.         $Dhuhr_h     = (int)($Dhuhr 24 60 60);
  450.         $Dhuhr_m     sprintf('%02d'($Dhuhr 24 6060);
  451.         $prayTime[2$Dhuhr_h.':'.$Dhuhr_m;
  452.         
  453.         if ($this->school == 'Shafi'{
  454.             // نحسب إرتفاع الشمس لوقت صلاة العصر
  455.             // حسب المذهب الشافعي
  456.             $T atan(tan(abs($this->lat $Decpi(180)) 180 pi();
  457.             
  458.             // ثم نحسب قوس الدائر أى الوقت المتبقى
  459.             // من وقت الظهر حتى صلاة العصر
  460.             // حسب المذهب الشافعي
  461.             $V acos((sin((90 $Tpi(180sin($Dec pi(180
  462.                  sin($this->lat pi(180)) (cos($Dec pi(180
  463.                  cos($this->lat pi(180))) 180 pi(15;
  464.             
  465.             // وقت صلاة العصر حسب المذهب الشافعي
  466.             $X           $local_noon $V;
  467.             $SAsr        $Dhuhr $V 24;
  468.             $SAsr_h      = (int)($SAsr 24 60 60);
  469.             $SAsr_m      sprintf('%02d'($SAsr 24 6060);
  470.             $prayTime[3$SAsr_h.':'.$SAsr_m;
  471.         else {
  472.             // نحسب إرتفاع الشمس لوقت صلاة العصر
  473.             // حسب المذهب الحنفي
  474.             $U atan(tan(abs($this->lat $Decpi(180)) 180 pi();
  475.             
  476.             // ثم نحسب قوس الدائر أى الوقت المتبقى
  477.             // من وقت الظهر حتى صلاة العصر
  478.             // حسب المذهب الحنفي
  479.             $W acos((sin((90 $Upi(180sin($Dec pi(180
  480.                  sin($this->lat pi(180)) (cos($Dec pi(180
  481.                  cos($this->lat pi(180))) 180 pi(15;
  482.             
  483.             // وقت صلاة العصر حسب المذهب الحنفي
  484.             $Z           $local_noon $W;
  485.             $HAsr        $Z 24;
  486.             $HAsr_h      = (int)($HAsr 24 60 60);
  487.             $HAsr_m      sprintf('%02d'($HAsr 24 6060);
  488.             $prayTime[3$HAsr_h.':'.$HAsr_m;
  489.         }
  490.         
  491.         // نحسب نصف قوس النهار
  492.         $AB acos((SIN($this->AB2 pi(180sin($Dec pi(180
  493.               sin($this->lat pi(180)) (cos($Dec pi(180
  494.               cos($this->lat pi(180))) 180 pi();
  495.         
  496.         // وقت الشروق
  497.         $AC          $local_noon $AB 15;
  498.         $Sunrise     $AC 24;
  499.         $Sunrise_h   = (int)($Sunrise 24 60 60);
  500.         $Sunrise_m   sprintf('%02d'($Sunrise 24 6060);
  501.         $prayTime[1$Sunrise_h.':'.$Sunrise_m;
  502.         
  503.         // وقت الغروب
  504.         $AE          $local_noon $AB 15;
  505.         $Sunset      $AE 24;
  506.         $Sunset_h    = (int)($Sunset 24 60 60);
  507.         $Sunset_m    sprintf('%02d'($Sunset 24 6060);
  508.         $prayTime[4$Sunset_h.':'.$Sunset_m;
  509.         
  510.         // نحسب فضل الدائر وهو الوقت المتبقى
  511.         // من وقت صلاة الظهر إلى وقت العشاء
  512.         $AG acos((sin($this->AG2 pi(180sin($Dec pi(180
  513.               sin($this->lat pi(180)) (cos($Dec pi(180
  514.               cos($this->lat pi(180))) 180 pi();
  515.         
  516.         // وقت صلاة العشاء
  517.         $AH          $local_noon ($AG 15);
  518.         $Isha        $AH 24;
  519.         $Isha_h      = (int)($Isha 24 60 60);
  520.         $Isha_m      sprintf('%02d'($Isha 24 6060);
  521.         $prayTime[5$Isha_h.':'.$Isha_m;
  522.         
  523.         // نحسب فضل دائر الفجر وهو الوقت المتبقى
  524.         // من وقت صلاة الفجر حتى وقت صلاة الظهر
  525.         $AJ acos((sin($this->AJ2 pi(180sin($Dec pi(180
  526.               sin($this->lat pi(180)) (cos($Dec pi(180
  527.               cos($this->lat pi(180))) 180 pi();
  528.         
  529.         // وقت صلاة الفجر
  530.         $AK          $local_noon $AJ 15;
  531.         $Fajr        $AK 24;
  532.         $Fajr_h      = (int)($Fajr 24 60 60);
  533.         $Fajr_m      sprintf('%02d'($Fajr 24 6060);
  534.         $prayTime[0$Fajr_h.':'.$Fajr_m;
  535.         
  536.         return $prayTime;
  537.     }
  538.     
  539.     /**
  540.      * Another algorithm (more accurate) to calculate Salat times for the date
  541.      * set in setSalatDate methode, and location set in setSalatLocation.
  542.      *                        
  543.      * @return array of Salat times + sun rise in the following format
  544.      *                hh:mm where hh is the hour in local format and 24 mode
  545.      *                mm is minutes with leading zero to be 2 digits always
  546.      *                array items is [$Fajr, $Sunrise, $Dhuhr, $Asr, $Maghrib,
  547.      *                $Isha, $Sunset, $Midnight, $Imsak, array $timestamps]
  548.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  549.      * @author Hamid Zarrabi-Zadeh <zarrabi@scs.carleton.ca>
  550.      * @source http://praytimes.org/calculation
  551.      */
  552.     public function getPrayTime2()
  553.     {
  554.         $unixtimestamp mktime(000$this->month$this->day$this->year);
  555.         
  556.         // Calculate Julian date
  557.         if ($this->month <= 2{
  558.             $year  $this->year 1;
  559.             $month $this->month 12;
  560.         else {
  561.             $year  $this->year;
  562.             $month $this->month;
  563.         }
  564.         
  565.         $A floor($year 100);
  566.         $B $A floor($A 4);
  567.  
  568.         $jd floor(365.25 ($year 4716)) floor(30.6001 ($month 1)) $this->day $B 1524.5;
  569.         
  570.         // The following algorithm from U.S. Naval Observatory computes the 
  571.         // Sun's angular coordinates to an accuracy of about 1 arcminute within 
  572.         // two centuries of 2000. 
  573.         $d $jd 2451545.0;  // jd is the given Julian date 
  574.  
  575.         // The following algorithm from U.S. Naval Observatory computes the Sun's 
  576.         // angular coordinates to an accuracy of about 1 arcminute within two 
  577.         // centuries of 2000
  578.         // http://aa.usno.navy.mil/faq/docs/SunApprox.php
  579.         // Note: mod % in PHP ignore decimels!
  580.         $g 357.529 0.98560028 $d;
  581.         $g $g 360 ($g ceil($g1);
  582.         
  583.         $q 280.459 0.98564736 $d;
  584.         $q $q 360 ($q ceil($q1);
  585.         
  586.         $L $q 1.915 sin(deg2rad($g)) 0.020 sin(deg2rad($g));
  587.         $L $L 360 ($L ceil($L1);
  588.  
  589.         $R 1.00014 0.01671 cos(deg2rad($g)) 0.00014 cos(deg2rad($g));
  590.         $e 23.439 0.00000036 $d;
  591.         
  592.         $RA rad2deg(atan2(cos(deg2rad($e))sin(deg2rad($L))cos(deg2rad($L))))15;
  593.         if ($RA 0{
  594.             $RA 24 $RA;
  595.         }
  596.  
  597.         // The declination of the Sun is the angle between the rays of the sun and 
  598.         // the plane of the earth equator. The declination of the Sun changes 
  599.         // continuously throughout the year. This is a consequence of the Earth's 
  600.         // tilt, i.e. the difference in its rotational and revolutionary axes. 
  601.         $D rad2deg(asin(sin(deg2rad($e))sin(deg2rad($L))));  // declination of the Sun
  602.         
  603.         // The equation of time is the difference between time as read from a sundial 
  604.         // and a clock. It results from an apparent irregular movement of the Sun 
  605.         // caused by a combination of the obliquity of the Earth's rotation axis 
  606.         // and the eccentricity of its orbit. The sundial can be ahead (fast) by 
  607.         // as much as 16 min 33 s (around November 3) or fall behind by as much as 
  608.         // 14 min 6 s (around February 12), as shown in the following graph:
  609.         // http://en.wikipedia.org/wiki/File:Equation_of_time.png 
  610.         $EqT ($q/15$RA;  // equation of time
  611.         
  612.         // Dhuhr
  613.         // When the Sun begins to decline after reaching its highest point in the sky
  614.         $Dhuhr 12 $this->zone ($this->long/15$EqT
  615.         
  616.         // Sunrise & Sunset 
  617.         // If the observer's location is higher than the surrounding terrain, we 
  618.         // can consider this elevation into consideration by increasing the above 
  619.         // constant 0.833 by 0.0347 × sqrt(elevation), where elevation is the  
  620.         // observer's height in meters. 
  621.         $alpha 0.833 0.0347 sqrt($this->elevation);
  622.         $n     = -sin(deg2rad($alpha)) sin(deg2rad($this->lat)) sin(deg2rad($D));
  623.         $d     cos(deg2rad($this->lat)) cos(deg2rad($D));
  624.  
  625.         $Sunrise $Dhuhr (1/15rad2deg(acos($n $d));
  626.         $Sunset  $Dhuhr (1/15rad2deg(acos($n $d));
  627.         
  628.         // Fajr & Isha
  629.         // Imsak    The time to stop eating Sahur (for fasting), slightly before Fajr.
  630.         // Fajr     When the sky begins to lighten (dawn).
  631.         // Isha      The time at which darkness falls and there is no scattered light in the sky. 
  632.         $n     = -sin(deg2rad(abs($this->AJ2))) sin(deg2rad($this->lat)) sin(deg2rad($D));
  633.         $Fajr  $Dhuhr (1/15rad2deg(acos($n $d));
  634.         $Imsak $Fajr (10/60);
  635.         
  636.         $n    = -sin(deg2rad(abs($this->AG2))) sin(deg2rad($this->lat)) sin(deg2rad($D));
  637.         $Isha $Dhuhr (1/15rad2deg(acos($n $d));
  638.         
  639.         // Asr
  640.         // The following formula computes the time difference between the mid-day 
  641.         // and the time at which the object's shadow equals t times the length of 
  642.         // the object itself plus the length of that object's shadow at noon
  643.         if ($this->school == 'Shafi'{
  644.             $n sin(atan(1/(tan(deg2rad($this->lat $D))))) sin(deg2rad($this->lat)) sin(deg2rad($D));
  645.         else {
  646.             $n sin(atan(1/(tan(deg2rad($this->lat $D))))) sin(deg2rad($this->lat)) sin(deg2rad($D));
  647.         }
  648.         $Asr $Dhuhr (1/15rad2deg(acos($n $d));
  649.         
  650.         // Maghrib
  651.         // In the Sunni's point of view, the time for Maghrib prayer begins once 
  652.         // the Sun has completely set beneath the horizon, that is, Maghrib = Sunset 
  653.         // (some calculators suggest 1 to 3 minutes after Sunset for precaution)
  654.         $MaghribSunni $Sunset 2/60;
  655.         
  656.         // In the Shia's view, however, the dominant opinion is that as long as 
  657.         // the redness in the eastern sky appearing after sunset has not passed 
  658.         // overhead, Maghrib prayer should not be performed.
  659.         $n           = -sin(deg2rad(4)) sin(deg2rad($this->lat)) sin(deg2rad($D));
  660.         $MaghribShia $Dhuhr (1/15rad2deg(acos($n $d));
  661.         
  662.         if ($this->view == 'Sunni'{
  663.             $Maghrib $MaghribSunni;
  664.         else {
  665.             $Maghrib $MaghribShia;
  666.         }
  667.  
  668.         // Midnight
  669.         // Midnight is generally calculated as the mean time from Sunset to Sunrise
  670.         $MidnightSunni $Sunset 0.5 ($Sunrise $Sunset);
  671.         if ($MidnightSunni 12{
  672.             $MidnightSunni $MidnightSunni 12;
  673.         }
  674.         
  675.         // In Shia point of view, the juridical midnight (the ending time for 
  676.         // performing Isha prayer) is the mean time from Sunset to Fajr
  677.         $MidnightShia 0.5 ($Fajr $Sunset);
  678.         if ($MidnightShia 12{
  679.             $MidnightShia $MidnightShia 12;
  680.         }
  681.         
  682.         if ($this->view == 'Sunni'{
  683.             $Midnight $MidnightSunni;
  684.         else {
  685.             $Midnight $MidnightShia;
  686.         }
  687.  
  688.         $times array($Fajr$Sunrise$Dhuhr$Asr$Maghrib$Isha$Sunset$Midnight$Imsak);
  689.         
  690.         // Convert number after the decimal point into minutes 
  691.         foreach ($times as $index => $time{
  692.             $hours   floor($time);
  693.             $minutes round(($time $hours60);
  694.             
  695.             if ($minutes 10{
  696.                 $minutes "0$minutes";
  697.             }
  698.             
  699.             $times[$index"$hours:$minutes";
  700.             
  701.             $times[9][$index$unixtimestamp 3600 $hours 60 $minutes;
  702.             
  703.             if ($index == && $hours 6{
  704.                 $times[9][$index+= 24 3600;
  705.             }
  706.         }
  707.         
  708.         return $times;
  709.     }
  710.  
  711.     /**
  712.      * Determine Qibla direction using basic spherical trigonometric formula
  713.      *                        
  714.      * @return float Qibla Direction (from the north direction) in degrees
  715.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  716.      * @author S. Kamal Abdali <k.abdali@acm.org>
  717.      * @source http://www.patriot.net/users/abdali/ftp/qibla.pdf
  718.      */
  719.     public function getQibla (
  720.     {
  721.         // The geographical coordinates of the Ka'ba
  722.         $K_latitude  21.423333;
  723.         $K_longitude 39.823333;
  724.         
  725.         $latitude  $this->lat;
  726.         $longitude $this->long;
  727.  
  728.         $numerator   sin(deg2rad($K_longitude $longitude));
  729.         $denominator (cos(deg2rad($latitude)) tan(deg2rad($K_latitude))) -
  730.                        (sin(deg2rad($latitude)) cos(deg2rad($K_longitude $longitude)));
  731.  
  732.         $q atan($numerator $denominator);
  733.         $q rad2deg($q);
  734.         
  735.         if ($this->lat 21.423333{
  736.             $q += 180;
  737.         }
  738.         
  739.         return $q;
  740.     }
  741.     
  742.     /**
  743.      * Convert coordinates presented in degrees, minutes and seconds
  744.      * (i.e. 12°34'56"S formula) into usual float number in degree unit scale
  745.      * (i.e. -12.5822 value)
  746.      *      
  747.      * @param string $value Coordinate presented in degrees, minutes and seconds
  748.      *                       (i.e. 12°34'56"S formula)
  749.      *      
  750.      * @return float Equivalent float number in degree unit scale
  751.      *                (i.e. -12.5822 value)
  752.      * @author Khaled Al-Sham'aa <khaled@ar-php.org>
  753.      */
  754.     public function coordinate2deg ($value
  755.     {
  756.         $pattern "/(\d{1,2})°((\d{1,2})')?((\d{1,2})\")?([NSEW])/i";
  757.         
  758.         preg_match($pattern$value$matches);
  759.         
  760.         $degree $matches[1($matches[360($matches[5/3600);
  761.         
  762.         $direction strtoupper($matches[6]);
  763.         
  764.         if ($direction == 'S' || $direction == 'W'{
  765.             $degree = -$degree;
  766.         }
  767.         
  768.         return $degree;
  769.     }
  770. }

Documentation generated on Wed, 29 Aug 2012 08:33:14 +0200 by phpDocumentor 1.4.0