[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: If someone know about PHP Prayertime for websites
- To: "Azhar Mehmood" <azhar at islamas dot lt>, "Development Discussions" <developer at arabeyes dot org>
- Subject: Re: If someone know about PHP Prayertime for websites
- From: "Hatem Ben Yacoub" <info at dynamix-tn dot com>
- Date: Wed, 8 Sep 2004 11:28:43 +0200
- Cc:
Attached the prayertime php class. use it at your own risk.
Regards,
Hatem
----- Original Message -----
From: "Azhar Mehmood" <azhar at islamas dot lt>
To: <info at dynamix-tn dot com>
Sent: Wednesday, September 08, 2004 11:22 AM
Subject: Re: If someone know about PHP Prayertime for websites
> Salam Hatem
>
> Could you please send me the code. I want it please...
>
> Jazak Allah
>
> Azhar
>
> > From: "Hatem Ben Yacoub" <info at dynamix-tn dot com>
> > Salam,
> >
> > This year I've rewritten in PHP the original CPP code of Um Al Qura
> > algorythm to compute prayer time, and sunrise, but didn't get correct
> > values. And i'm not sure if it was a problem of my testing values or
> of my
> > code ! The original code was written by Fayez Alhargan in 2001, and
> make use
> > of about 12 parameters.
> >
> > If interested, i can send you the code.
> >
> > Hatem
>
>
<?php
define ('pi',M_PI);
define ('DToR',pi/180);
define ('RToH',12/pi);
define ('EarthRadius',6378.14);
/**
* prayertime class : class that computes prayer times and sunrise.
*
* Original CPP code written by : Fayez Alhargan, 2001
* King Abdulaziz City for Science and Technology
* Computer and Electronics Research Institute
* Riyadh, Saudi Arabia
* alhargan at kacst dot edu dot sa
* Tel:4813770 Fax:4813764
*
* @package
* @author Ben Yacoub Hatem <hatem at php dot net>
* @website http://Www.phptunisie.net/
* @copyright Copyright (c) 2004
* @version $Id$ - 28/02/2004 19:41:19 - prayertime.class.php
* @access public
**/
class prayertime{
/**
* Constructor
* @access protected
*/
function prayertime(){
}
/**
* prayertime::GetRatior() Function to obtain the ratio of the start time of Isha and Fajr at
* a referenced latitude (45deg suggested by Rabita) to the night length
*
* @param $yg
* @param $mg
* @param $dg
* @param $param
* @param $IshRt
* @param $FajrRt
* @return
**/
function GetRatior($yg,$mg,$dg,$param,&$IshRt,&$FajrRt){
if($param[2]<0) $MaxLat= -abs($param[9]); else $MaxLat= abs($param[9]);
prayertime::SunParamr($yg,$mg,$dg,-$param[1],$MaxLat,-$param[5],&$Rise,&$Transit,&$Setting,&$RA,&$Decl,&$flagrs);
$SINd=sin($Decl)*sin($MaxLat);
$COSd=cos($Decl)*cos($MaxLat);
$Night=24-($Setting-$Rise); /* Night Length */
/* Fajr */
$angl=-$param[6];
$cH=(sin($angl)-$SINd)/($COSd);
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$FjrRf=$Transit-$H-$param[0]; /* Fajr time */
/* Isha */
if($param[7]!=0) /* if Ish angle not equal zero*/
{
$angl=-$param[7];
$cH=(sin($angl)-$SINd)/($COSd);
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$IshRf=$Transit+$H+$param[0]; /* Isha time, instead of Sunset+1.5h */
}
else
{
$IshRf=$Setting+$param[10]; /* Isha time OmAlqrah standard Sunset+1.5h */
}
$IshRt=($IshRf-$Setting)/$Night; /* Isha time ratio */
$FajrRt=($Rise-$FjrRf)/$Night; /* Fajr time ratio */
return;
}
/**
* prayertime::atanxy()
*
* @param $x
* @param $y
* @return
**/
function atanxy($x,$y){
if($x==0) $argm=0.5*pi; else $argm=atan($y/$x);
if($x>0 && $y<0) $argm=2.0*pi+$argm;
if($x<0) $argm=pi+$argm;
return $argm;
}
/**
* prayertime::EclipToEquator()
*
* @param $lmdr
* @param $betar
* @param $alph
* @param $dltr
* @return
**/
function EclipToEquator($lmdr,$betar,&$alph,&$dltr){
/*
Convert Ecliptic to Equatorial Coordinate
p.40 No.27, Peter Duffett-Smith book
input: lmdr,betar in radians
output: alph,dltr in radians
*/
$eps=23.441884; // (in degrees) this changes with time
$rad=0.017453292; // =pi/180.0
$epsr=$eps*$rad; // convert to radians
$sdlt=sin($betar)*cos($epsr)+cos($betar)*sin($epsr)*sin($lmdr);
$dltr=asin($sdlt);
$y=sin($lmdr)*cos($epsr)-tan($betar)*sin($epsr);
$x=cos($lmdr);
$alph=prayertime::atanxy($x,$y);
}
/**
* prayertime::RoutinR2()
*
* @param $M
* @param $e
* @return
**/
function RoutinR2($M,$e){
/*
Routine R2:
Calculate the value of E
p.91, Peter Duffett-Smith book
*/
$dt=1;
$Ec=$M;
// verify abs of fbas ?!!
while(abs($dt)>1e-9)
{
$dt=$Ec-$e*sin($Ec)-$M;
$dE=$dt/(1-$e*cos($Ec));
$Ec=$Ec-$dE;
}
return $Ec;
}
/**
* prayertime::GCalendarToJD()
*
* @param $yy
* @param $mm
* @param $dd
* @return
**/
function GCalendarToJD($yy,$mm,$dd){
if ($mm > 2) {
$y = $yy;
$m = $mm;
}
else {
$y = $yy - 1;
$m = $mm + 12;
}
$A = $y / 100;
$B = 2 - $A + $A / 4;
$T1= (integer) (365.25 * ($y + 4716));
$T2= (integer) (30.6001 * ($m + 1));
$Tr=$T1+ $T2 + $dd + $B - 1524.5 ;
return $Tr;
}
/**
* prayertime::GDateAjust()
*
* @param $yg
* @param $mg
* @param $dg
* @return
**/
function GDateAjust(&$yg,&$mg,&$dg){
$gmonth= array(31,31,28,31,30,31,30,31,31,30,31,30,31,31);/* makes it circular m[0]=m[12] & m[13]=m[1] */
/* Make sure that dates are within the correct values */
/* Underflow */
if($mg<1) /* months underflow */
{
$mg=12+$mg; /* plus as the underflow months is negative */
$yg=$yg-1;
}
if($dg<1) /* days underflow */
{
$mg= $mg-1; /* month becomes the previous month */
$dg=$gmonth[$mg]+$dg; /* number of days of the month less the underflow days (it is plus as the sign of the day is negative) */
if($mg==2) $dg=$dg+prayertime::GLeapYear($yg);
if($mg<1) /* months underflow */
{
$mg=12+$mg; /* plus as the underflow months is negative */
$yg=$yg-1;
}
}
/* Overflow */
if($mg>12) /* months */
{
$mg=$mg-12;
$yg=$yg+1;
}
if($mg==2)
$dys=$gmonth[$mg]+prayertime::GLeapYear($yg); /* number of days in the current month */
else
$dys=$gmonth[$mg];
if($dg>$dys) /* days overflow */
{
$dg=$dg-$dys;
$mg=$mg+1;
if($mg==2)
{
$dys=$gmonth[$mg]+prayertime::GLeapYear($yg); /* number of days in the current month */
if($dg>$dys)
{
$dg=$dg-$dys;
$mg=$mg+1;
}
}
if($mg>12) /* months */
{
$mg=$mg-12;
$yg=$yg+1;
}
}
}
/**
* prayertime::GLeapYear()
*
* @param $year
* @return
**/
function GLeapYear($year){
$T=0;
if($year%4==0) $T=1; /* leap_year=1; */
if($year%100==0)
{
$T=0; /* years=100,200,300,500,... are not leap years */
if($year%400==0) $T=1; /* years=400,800,1200,1600,2000,2400 are leap years */
}
return $T;
}
/**
* prayertime::SunParamr()
*
* @param $yg
* @param $mg
* @param $dg
* @param $ObsLon
* @param $ObsLat
* @param $TimeZone
* @param $Rise
* @param $Transit
* @param $Setting
* @param $RA
* @param $Decl
* @param $RiseSetFlags
* @return
**/
function SunParamr($yg,$mg,$dg,$ObsLon,$ObsLat,$TimeZone,&$Rise,&$Transit,&$Setting,&$RA,&$Decl,&$RiseSetFlags){
/*
p.99 of the Peter Duffett-Smith book
*/
$RiseSetFlags=0;
$JD=prayertime::GCalendarToJD($yg,$mg,$dg);
$T=($JD+ $TimeZone/24.0 - 2451545.0) / 36525.0;
$L=279.6966778+36000.76892*$T+0.0003025*$T*$T; // in degrees
while($L>360) $L=$L-360;
while($L<0) $L=$L+360;
$L=$L*pi/180.0; // radians
$M=358.47583+35999.04975*$T-0.00015*$T*$T-0.0000033*$T*$T*$T;
while($M>360) $M=$M-360;
while($M<0) $M=$M+360;
$M=$M*pi/180.0;
$e=0.01675104-0.0000418*$T-0.000000126*$T*$T;
$Ec=23.452294-0.0130125*$T-0.00000164*$T*$T+0.000000503*$T*$T*$T;
$Ec=$Ec*pi/180.0;
$y=tan(0.5*$Ec);
$y=$y*$y;
$ET=$y*sin(2*$L)-2*$e*sin($M)+4*$e*$y*sin($M)*cos(2*$L)-0.5*$y*$y*sin(4*$L)-5*0.25*$e*$e*sin(2*$M);
$UT=$ET*180.0/(15.0*pi); // from radians to hours
$Ec=prayertime::RoutinR2($M,$e);
$tnv=sqrt((1+$e)/(1-$e))*tan(0.5*$Ec);
$v=2.0*atan($tnv);
$tht=$L+$v-$M;
prayertime::EclipToEquator($tht,0,$RA,$Decl);
$K=12-$UT-$TimeZone+$ObsLon*12.0/pi; // (Noon)
$Transit=$K;
/* Sunrise and Sunset*/
$angl=(-0.833333)*DToR; // Meeus p.98
$T1=(sin($angl)-sin($Decl)*sin($ObsLat));
$T2=(cos($Decl)*cos($ObsLat)); // p.38 Hour angle for the Sun
$cH=$T1/$T2;
if($cH>1) {$RiseSetFlags=16;$cH=1;} /*At this day and place the sun does not rise or set */
$H=acos($cH);
$H=$H*12.0/pi;
$Rise=$K-$H; // Sunrise
$Setting=$K+$H; // SunSet
return $JD;
}
/*
For international prayer times see Islamic Fiqah Council of the Muslim
World League: Saturday 12 Rajeb 1406H, concerning prayer times and fasting
times for countries of high latitudes.
This program is based on the above.
*/
/*****************************************************************************/
/* Name: OmAlQrah */
/* Type: Procedure */
/* Purpose: Compute prayer times and sunrise */
/* Arguments: */
/* yg,mg,dg : Date in Greg */
/* param[0]: Safety time in hours should be 0.016383h */
/* longtud,latud: param[1],[2] : The place longtude and latitude in radians*/
/* HeightdifW : param[3]: The place western herizon height difference in meters */
/* HeightdifE : param[4]: The place eastern herizon height difference in meters */
/* Zonh :param[5]: The place zone time dif. from GMT West neg and East pos*/
/* in decimal hours */
/* fjrangl: param[6]: The angle (radian) used to compute */
/* Fajer prayer time (OmAlqrah -19 deg.) */
/* ashangl: param[7]: The angle (radian) used to compute Isha prayer time */
/* ashangl=0 then use (OmAlqrah: ash=SunSet+1.5h) */
/* asr : param[8]: The Henfy (asr=2) Shafi (asr=1, Omalqrah asr=1) */
/* param[9]: latude (radian) that should be used for places above -+65.5 */
/* should be 45deg as suggested by Rabita */
/* param[10]: The Isha fixed time from Sunset */
/* Output: */
/* lst[]: lst[n], 1:Fajer 2:Sunrise 3:Zohar 4:Aser 5:Magreb 6:Ishe */
/* 7:Fajer using exact Rabita method for places >48 */
/* 8:Ash using exact Rabita method for places >48 */
/* 9: Eid Prayer Time */
/* for places above 48 lst[1] and lst[6] use a modified version of */
/* Rabita method that tries to eliminate the discontinuity */
/* all in 24 decimal hours */
/* returns flag:0 if there are problems, flag:1 no problems */
/*****************************************************************************/
/**
*
* @access public
* @return void
**/
function OmAlQrah($yg,$mg,$dg,$param,&$lst){
$flag=1;$problm=0;
$HightCorWest=0;$HightCorEast=0;
/*
Main Local variables:
RA= Sun's right ascension
Decl= Sun's declination
H= Hour Angle for the Sun
K= Noon time
angl= The Sun altitude for the required time
flagrs: sunrise sunset flags
0:no problem
16: Sun always above horizon (at the ploes for some days in the year)
32: Sun always below horizon
*/
/* Compute the Sun various Parameters */
prayertime::SunParamr($yg,$mg,$dg,-$param[1],$param[2],-$param[5],&$Rise,&$Transit,&$Setting,&$RA,&$Decl,&$flagrs);
/* Compute General Values */
$SINd=sin($Decl)*sin($param[2]);
$COSd=cos($Decl)*cos($param[2]);
/* Noon */
$K=$Transit;
/* Compute the height correction */
$HightCorWest=0;$HightCorEast=0;
if($flagrs==0 && abs($param[2])<0.79 && ($param[4]!=0 || $param[3]!=0))
{ /* height correction not used for problematic places above 45deg*/
$H0=$H=0;
$angl=-0.83333*DToR; /* standard value angl=50min=0.8333deg
for sunset and sunrise */
$cH=(sin($angl)-$SINd)/($COSd);
$H0=acos($cH);
$X=EarthRadius*1000.0; /* meters */
$angl=-0.83333*DToR+(0.5*pi-asin($X/($X+$param[3]))); /* */
$cH=(sin($angl)-$SINd)/($COSd);
$HightCorWest=acos($cH);
$HightCorWest=($H0-$HightCorWest)*(RToH);
$angl=-0.83333*DToR+(0.5*pi-asin($X/($X+$param[4])));
$cH=(sin($angl)-$SINd)/($COSd);
$HightCorEast=acos($cH);
$HightCorEast=($H0-$HightCorEast)*(RToH);
}
/* Modify Sunrise,Sunset and Transit for problematic places*/
if(!($flagrs==0 && abs($Setting-$Rise)>1 && abs($Setting-$Rise)<23))
{ /* There are problems in computing sun(rise,set) */
/* This is because of places above -+65.5 at some days of the year */
/* Note param[9] should be 45deg as suggested by Rabita */
$problm=1;
if($param[2]<0) $MaxLat= -abs($param[9]); else $MaxLat= abs($param[9]);
/* Recompute the Sun various Parameters using the reference param[9] */
prayertime::SunParamr($yg,$mg,$dg,-$param[1],$MaxLat,-$param[5],&$Rise,&$Transit,&$Setting,&$RA,&$Decl,&$flagrs);
$K=$Transit; /* exact noon time */
/* ReCompute General Values for the new reference param[9]*/
$SINd=sin($Decl)*sin($MaxLat);
$COSd=cos($Decl)*cos($MaxLat);
}
/*-------------------------------------------------------------*/
if($K<0) $K=$K+24;
$lst[2]=$Rise-$HightCorEast; /* Sunrise - Height correction */
$lst[3]=$K+$param[0]; /* Zohar time+extra time to make sure that the sun has moved from zaowal */
$lst[5]=$Setting+$HightCorWest+$param[0]; /* Magrib= SunSet + Height correction + Safety Time */
/*-------------------------------------------------------------*/
/* Asr time: Henfy param[8]=2, Shafi param[8]=1, OmAlqrah asr=1 */
if($problm) /* For places above 65deg */
$act=$param[8]+tan(abs($Decl-$MaxLat));
else /* no problem */
$act=$param[8]+tan(abs($Decl-$param[2])); /*In the standard
equations abs() is not used,
but it is required for -ve latitude */
$angl=atan(1.0/$act);
$cH=(sin($angl)-$SINd)/($COSd);
if(abs($cH)>1.0)
{
$H=3.5;
$flag=0; /* problem in compuing Asr */
}
else
{
$H=acos($cH);
$H=$H*RToH;
}
$lst[4]=$K+$H+$param[0]; /* Asr Time */
/*-------------------------------------------------------------*/
/* Fajr Time */
$angl=-$param[6]; /* The value -19deg is used by OmAlqrah for Fajr,
but it is not correct,
Astronomical twilight and Rabita use -18deg */
$cH=(sin($angl)-$SINd)/($COSd);
if(abs($param[2])<0.83776) /*If latitude<48deg */
{ /* no problem */
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$lst[1]=$K-($H+$HightCorEast)+$param[0]; /* Fajr time */
$lst[7]=$lst[1];
}
else
{ /* Get fixed ratio, data depends on latitutde sign*/
if($param[2]<0)
prayertime::GetRatior($yg,12,21,$param,&$IshFix,&$FajrFix);
else
prayertime::GetRatior($yg,6,21,$param,&$IshFix,&$FajrFix);
if(abs($cH)>(0.45+1.3369*$param[6])) /* A linear equation I have interoduced */
{ /* The problem occurs for places above -+48 in the summer */
$Night=24-($Setting-$Rise); /* Night Length */
$lst[1]=$Rise-$Night*$FajrFix; /* According to the general ratio rule*/
}
else
{ /* no problem */
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$lst[1]=$K-($H+$HightCorEast)+$param[0]; /* Fajr time */
}
$lst[7]=$lst[1];
if(abs($cH)>1)
{ /* The problem occurs for places above -+48 in the summer */
prayertime::GetRatior($yg,$mg,$dg,$param,&$IshRt,&$FajrRt);
$Night=24-($Setting-$Rise); /* Night Length */
$lst[7]=$Rise-$Night*$FajrRt; /* Accoording to Rabita Method*/
}
else
{ /* no problem */
$H=acos($cH);
$H=H*RToH; /* convert radians to hours */
$lst[7]=$K-($H+$HightCorEast)+$param[0]; /* Fajr time */
}
}
/*-------------------------------------------------------------*/
/* Isha prayer time */
if($param[7]!=0) /* if Ish angle not equal zero*/
{
$angl=-$param[7];
$cH=(sin($angl)-$SINd)/($COSd);
if(abs($param[2])<0.83776) /*If latitude<48deg */
{ /* no problem */
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$lst[6]=$K+($H+$HightCorWest+$param[0]); /* Isha time, instead of Sunset+1.5h */
$lst[8]=$lst[6];
}
else
{
if(abs($cH)>(0.45+1.3369*$param[6])) /* A linear equation I have interoduced */
{ /* The problem occurs for places above -+48 in the summer */
$Night=24-($Setting-$Rise); /* Night Length */
$lst[6]=$Setting+$Night*$IshFix; /* Accoording to Rabita Method*/
}
else
{ /* no problem */
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$lst[6]=$K+($H+$HightCorWest+$param[0]); /* Isha time, instead of Sunset+1.5h */
}
if(abs($cH)>1.0)
{ /* The problem occurs for places above -+48 in the summer */
prayertime::GetRatior($yg,$mg,$dg,$param,&$IshRt,&$FajrRt);
$Night=24-($Setting-$Rise); /* Night Length */
$lst[8]=$Setting+$Night*$IshRt; /* According to the general ratio rule*/
}
else
{
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$lst[8]=$K+($H+$HightCorWest+$param[0]); /* Isha time, instead of Sunset+1.5h */
}
}
}
else
{
$lst[6]=$lst[5]+$param[10]; /* Isha time OmAlqrah standard Sunset+fixed time (1.5h or 2h in Romadan) */
$lst[8]=$lst[6];
}
/*-------------------------------------------------------------*/
/* Eid prayer time */
$angl=$param[11]; /* Eid Prayer time Angle is 4.2 */
$cH=(sin($angl)-$SINd)/($COSd);
if((abs($param[2])<1.134 || $flagrs==0) && abs($cH)<=1.0) /*If latitude<65deg */
{ /* no problem */
$H=acos($cH);
$H=$H*RToH; /* convert radians to hours */
$lst[9]=$K-($H+$HightCorEast)+$param[0]; /* Eid time */
}
else
{
$lst[9]=$lst[2]+0.25; /* If no Sunrise add 15 minutes */
}
return $flag;
}
}
/*
For international prayer times see Islamic Fiqah Council of the Muslim
World League: Saturday 12 Rajeb 1406H, concerning prayer times and fasting
times for countries of high latitudes.
This program is based on the above.
*/
/*****************************************************************************/
/* Name: OmAlQrah */
/* Type: Procedure */
/* Purpose: Compute prayer times and sunrise */
/* Arguments: */
/* yg,mg,dg : Date in Greg */
/* param[0]: Safety time in hours should be 0.016383h */
/* longtud,latud: param[1],[2] : The place longtude and latitude in radians*/
/* HeightdifW : param[3]: The place western herizon height difference in meters */
/* HeightdifE : param[4]: The place eastern herizon height difference in meters */
/* Zonh :param[5]: The place zone time dif. from GMT West neg and East pos*/
/* in decimal hours */
/* fjrangl: param[6]: The angle (radian) used to compute */
/* Fajer prayer time (OmAlqrah -19 deg.) */
/* ashangl: param[7]: The angle (radian) used to compute Isha prayer time */
/* ashangl=0 then use (OmAlqrah: ash=SunSet+1.5h) */
/* asr : param[8]: The Henfy (asr=2) Shafi (asr=1, Omalqrah asr=1) */
/* param[9]: latude (radian) that should be used for places above -+65.5 */
/* should be 45deg as suggested by Rabita */
/* param[10]: The Isha fixed time from Sunset */
/* Output: */
/* lst[]: lst[n], 1:Fajer 2:Sunrise 3:Zohar 4:Aser 5:Magreb 6:Ishe */
/* 7:Fajer using exact Rabita method for places >48 */
/* 8:Ash using exact Rabita method for places >48 */
/* 9: Eid Prayer Time */
/* for places above 48 lst[1] and lst[6] use a modified version of */
/* Rabita method that tries to eliminate the discontinuity */
/* all in 24 decimal hours */
/* returns flag:0 if there are problems, flag:1 no problems */
/*****************************************************************************/
$longtud=10;$latud=33;
$Zonh=1;
$param = array( 0=>0.016388,/* 59seconds, safety time */
1=>$longtud, // 1 et 2 : The place longtude and latitude in radians
2=>$latud,
3=>300, // The place western herizon height difference in meters
4=>300, // The place eastern herizon height difference in meters
5=>$Zonh, // The place zone time dif. from GMT West neg and East pos in decimal hours
6=>19*DToR, // The angle (radian) used to compute, Fajer prayer time (OmAlqrah -19 deg.)
7=>0, // The angle (radian) used to compute Isha prayer time
8=>1, // The Henfy (asr=2) Shafi (asr=1, Omalqrah asr=1)
9=>45*DToR, // latude (radian) that should be used for places above -+65.5 should be 45deg as suggested by Rabita
10=>1.5, // The Isha fixed time from Sunset
11=>4.2*DToR); /* Eid Prayer Time */
$yg = "2004";$mg = "4";$dg = "18";
prayertime::GDateAjust($yg,$mg,$dg);
$r = prayertime::OmAlQrah($yg,$mg,$dg,$param ,$lst );
if ($r == 1) {
foreach($lst as $k=>$v){
echo "$k - ".(abs($v))."<br>";
}
}else {
echo "there are problems computing prayer times and sunrise with these informations :<br><pre>";
print_r($param);
}
?>