22-03-2015, 04:24 PM
تصحيح جديد
PHP كود :
unit MuslimPrayerTimes;
{
Author: onexite
Date: 22/03/2015
Description: Prayer Times Calculator (ver 3.3)
Filename: MuslimPrayerTimes.pas
Purpose: The five Islamic prayers are named Fajr, Zuhr, Asr, Maghrib and Isha. The timing of these five prayers varies from place to place and from day to day. It is obligatory for Muslims to perform these prayers at the correct time.
}
interface
uses
SysUtils,System.Math,System.DateUtils;
type
stTimes=Array[0..4] of TDateTime;
//********************
PTime = record
Time:TDateTime;
SstringTime: string;
Position: Byte ;
name:string;
Alert:Boolean;
end;
//********************
PrayTime = record
Fajr, Sunrise, Dhuhr, Asr, Maghrib, Isha, Sunset,Midnight, Imsak,ThlthAkhir,Doha :TDateTime;
end;
const Version : string ='3.3.0.0';
//********************// Functions //********************
function getQibla (latitude,longitude:Extended):Extended;
function CalcPray(Lon, Lat, Zone,_Elevation,DefaultElev:Real; PrayDate:TDateTime; CalcWay:Byte;MaghribAdd:SmallInt;school:string;view:Byte;_StatusElevation:Boolean=False;_Summer:Boolean=False;isRamadan:Boolean=False): PrayTime;
implementation
procedure modulo(var deg: Extended;const base:integer );
begin
if deg > 0 then deg:= deg - base * trunc(deg / base) else deg:= deg - base*(trunc(deg/base)-1);
end;
//==========================================================================
function getQibla (latitude,longitude:Extended):Extended;
const K_latitude = 21.423333; K_longitude = 39.823333;
begin
Result := RadToDeg( ArcTan(sin(DegToRad(K_longitude - longitude)) /((cos(DegToRad(latitude)) * tan(DegToRad(K_latitude))) -(sin(DegToRad(latitude))* cos(DegToRad(K_longitude - longitude))))) );
if (latitude > 21.423333) then
Result :=Result+ 180;
end;
//==========================================================================
function CalcPray(Lon, Lat, Zone,_Elevation,DefaultElev:Real; PrayDate:TDateTime; CalcWay:Byte;MaghribAdd:SmallInt;school:string;view:Byte;_StatusElevation:Boolean=False;_Summer:Boolean=False;isRamadan:Boolean=False): PrayTime;
var Smr :0..1;
d,tmp,g,q,l,r,ra,e,eqt,alpha,n,_d,MaghribSunni,MaghribShia,MidnightSunni,MidnightShia:Extended;
CalcWayFajr, CalcWayIsha: Real;
function TimeZone_Longitude(long:Real):SmallInt;
begin
if (Frac(long/15)=0) or (long<0) then //
Result:=Trunc(long/15) else Result:=Trunc(long/15) +1
// if long>0 then
// else
// Result:=Trunc(long/15) -1
end;
Begin
{
* Setting rest of Salat calculation configuration
*
* Convention Fajr Angle Isha Angle
*
* Muslim World League -18 -17
*
* Islamic Society of North America (ISNA) -15 -15
*
* Egyptian General Authority of Survey -19.5 -17.5
*
* Umm al-Qura University, Makkah -18.5
* Isha 90 min after Maghrib, 120 min during Ramadan
*
* University of Islamic Sciences, Karachi -18 -18
*
* Institute of Geophysics, University of Tehran -17.7 -14(*)
*
* Shia Ithna Ashari, Leva Research Institute, Qum -16 -14
*
* (*) Isha angle is not explicitly defined in Tehran method
* Fajr Angle = fajrArc, Isha Angle = ishaArc
*
* - حزب العلماء في لندن لدول
* أوروبا في خطوط عرض تزيد على 48
*
* ishaArc = -17
* fajrArc = -17
*
* @param string school [Shafi|Hanafi] to define Muslims Salat
* calculation method (affect Asr time)
* @param decimal sunriseArc Sun rise arc (default value is -0.833333)
* @param decimal ishaArc Isha arc (default value is -17.5)
* @param decimal fajrArc Fajr arc (default value is -19.5)
* @param string view [Sunni|Shia] to define Muslims Salat calculation
* method (affect Maghrib and Midnight time)
}
Smr:=0; if _Summer then Smr:=1;
CalcWayFajr:=-19.5;
CalcWayIsha:=-17.5;
Case CalcWay Of
0: Begin CalcWayFajr:=-18; CalcWayIsha:=-18 End;
1: Begin CalcWayFajr:=-15; CalcWayIsha:=-15 End;
2: Begin CalcWayFajr:=-18; CalcWayIsha:=-17 End;
3: Begin CalcWayFajr:=-18.5;CalcWayIsha:=0 End;
4: Begin CalcWayFajr:=-19.5;CalcWayIsha:=-17.5 End;
5: Begin CalcWayFajr:=-17.7; CalcWayIsha:=-14 End;
6: Begin CalcWayFajr:=-16; CalcWayIsha:=-14 End;
End;
d := DateTimeToJulianDate(PrayDate) ; // jd is the given Julian date
// d := d - Lon / 360; // 15* 24
d := d - 2451545.0;
g := 357.529 + 0.98560028 * d;
modulo(g,360);
q := 280.459 + 0.98564736 * d;
modulo(q,360);
L := q + 1.915 * sin(DegToRad(g)) + 0.020 * sin(DegToRad(2 * g));
modulo(l,360);
R := 1.00014 - 0.01671 * cos(DegToRad(g)) - 0.00014 * cos(DegToRad(2 * g));
e := 23.439 - 0.00000036 * d;
RA := RadToDeg(ArcTan2(cos(DegToRad(e))* sin(DegToRad(L)), cos(DegToRad(L))))/ 15;
// if (RA < 0) then RA := 24 + RA;
modulo(RA,24);
// The declination of the Sun is the angle between the rays of the sun and
// the plane of the earth equator. The declination of the Sun changes
// continuously throughout the year. This is a consequence of the Earth's
// tilt, i.e. the difference in its rotational and revolutionary axes.
// declination of the Sun
_d := RadToDeg(ArcSin(sin(DegToRad(e))* sin(DegToRad(L))));
EqT := (q/15) - RA; // equation of time
tmp := 12 + zone - (lon/15) - EqT;
// if (Result.Dhuhr < 0) then Result.Dhuhr:= 24 + Result.Dhuhr;
modulo(tmp,24);
Result.Dhuhr:=tmp;
// Sunrise & Sunset
// If the observer's location is higher than the surrounding terrain, we
// can consider this elevation into consideration by increasing the above
// constant 0.833 by 0.0347 × sqrt(elevation), where elevation is the
// observer's height in meters
if _StatusElevation then
alpha := 0.833 + 0.0347 * sqrt(_Elevation) else
alpha := 0.833 + 0.0347 * sqrt(DefaultElev) ;//1.32373210614; // 0.8680333 ;
try
n := -1 * sin(DegToRad(alpha)) - sin(DegToRad(lat)) * sin(DegToRad(_d));
d := cos(DegToRad(lat)) * cos(DegToRad(_d));
except
n:=0;d:=0 ;
end;
Result.Sunrise := Result.Dhuhr - (1/15) * RadToDeg(ArcCos(n / d));
Result.Sunset := Result.Dhuhr + (1/15) * RadToDeg(ArcCos(n / d));
n := -1 * sin(DegToRad(abs(CalcWayfajr))) - sin(DegToRad(lat)) * sin(DegToRad(_d));
Result.Fajr := Result.Dhuhr - (1/15) * RadToDeg(ArcCos(n / d));
Result.Imsak := Result.Fajr - (10/60);
n := -1 * sin(DegToRad(abs(CalcWayIsha))) - sin(DegToRad(lat))* sin(DegToRad(_d));
Result.Isha := Result.Dhuhr + (1/15) * RadToDeg(ArcCos(n / d));
if (school = 'Shafi') then
n := sin(ArcTan(1/(1 + tan(DegToRad(lat - _d))))) - sin(DegToRad(lat)) * sin(DegToRad(_d))
else
n := sin(ArcTan(1/(2 + tan(DegToRad(lat - _d)))))- sin(DegToRad(lat)) * sin(DegToRad(_d));
Result.Asr := Result.Dhuhr + (1/15) * RadToDeg(ArcCos(n / d));
// Maghrib
// In the Sunni's point of view, the time for Maghrib prayer begins once
// the Sun has completely set beneath the horizon, that is, Maghrib = Sunset
// (some calculators suggest 1 to 3 minutes after Sunset for precaution)
MaghribSunni := Result.Sunset + MaghribAdd/60;
n := -1 * sin(DegToRad(4)) - sin(DegToRad(lat)) * sin(DegToRad(_d));
MaghribShia := Result.Dhuhr + (1/15) * RadToDeg(ArcCos(n / d));
{
Tehran: {
name: 'Institute of Geophysics, University of Tehran',
params: { fajr: 17.7, isha: 14, maghrib: 4.5, midnight: 'Jafari' // isha is not explicitly specified in this method
Jafari:
name: 'Shia Ithna-Ashari, Leva Institute, Qum',
params: { fajr: 16, isha: 14, maghrib: 4, midnight: 'Jafari'
if CalcWay=5 then
MaghribShia := MaghribShia+(4.5/60);
if CalcWay=6 then
MaghribShia := MaghribShia+(4/60);
if CalcWay=6 then
MaghribShia := MaghribShia+(4/60);
}
if (view = 0) then //'Sunni'
Result.Maghrib := MaghribSunni
else
Result.Maghrib := MaghribShia;
if CalcWay=3 then
if isRamadan then
Result.Isha := Result.Maghrib+2 else //120/60 =2
Result.Isha := Result.Maghrib+1.5; //90/60=1.5
//نصف الليل = مجموع الوقت من غروب الشمس إلى طلوع الفجر ÷ 2+وقت غروب الشمس والناتج هو منتصف الليل
MidnightSunni := Result.Sunset +(24- Result.Sunset+Result.Sunrise)/2;
MidnightShia := ( 24- Result.Sunset+ Result.Fajr)/2;
if (view = 0) then // 'Sunni'
Result.Midnight := MidnightSunni
else
Result.Midnight := MidnightShia;
Result.ThlthAkhir:= Result.Fajr-(24-Result.Maghrib + Result.Fajr)/3;
Result.Doha := Result.Sunrise+(15/60);
//********************************************
Result.Fajr:=(Frac((Result.Fajr+Smr)/24));
Result.Sunrise:=(Frac((Result.Sunrise+Smr)/24));
Result.Dhuhr:=(Frac((Result.Dhuhr+Smr)/24));
Result.Asr:=(Frac((Result.Asr+Smr)/24)) ;
Result.Maghrib:=(Frac((Result.Maghrib+Smr)/24));
Result.Isha:=(Frac((Result.Isha+Smr)/24)) ;
Result.Sunset:=(Frac((Result.Sunset+Smr)/24)) ;
Result.Midnight:=(Frac((Result.Midnight+Smr)/24));
Result.Imsak:=(Frac((Result.Imsak+Smr)/24));
Result.ThlthAkhir:=(Frac((Result.ThlthAkhir+Smr)/24));
Result.Doha:=(Frac((Result.Doha+Smr)/24));
//********************************************
End;
End.

