You should have been a latitude and longitude of your location and also a function that compute prayer times!
try the following good code for compute prayer times:)
MorningPrayer->Fajr
Sunrise->
MiddayPrayer->Dhur,Asir
Sunset->
SunsetPrayer->Magrib,Eisha
struct Values
{
public double Val0, Val1;
}
TimeSpan MorningPrayer(byte Month, byte Day, double Longitude, double Latitude)
{
Values ep = sun(Month, Day, 4, Longitude);
double zr = ep.Val0,
delta = ep.Val1,
ha = loc2hor(108.0, delta, Latitude),
t = Round(zr - ha, 24);
ep = sun(Month, Day, t, Longitude);
zr = ep.Val0;
delta = ep.Val1;
ha = loc2hor(108.0, delta, Latitude);
t = Round(zr - ha, 24);
return TimeSpan.Parse(hms(t));
}
TimeSpan Sunrise(byte Month, byte Day, double Longitude, double Latitude)
{
Values ep = sun(Month, Day, 6, Longitude);
double zr = ep.Val0,
delta = ep.Val1,
ha = loc2hor(90.833, delta, Latitude),
t = Round(zr - ha, 24);
ep = sun(Month, Day, t, Longitude);
zr = ep.Val0;
delta = ep.Val1;
ha = loc2hor(90.833, delta, Latitude);
t = Round(zr - ha, 24);
return TimeSpan.Parse(hms(t));
}
TimeSpan MiddayPrayer(byte Month, byte Day, double Longitude)
{
Values ep = sun(Month, Day, 12, Longitude);
ep = sun(Month, Day, ep.Val0, Longitude);
double zr = ep.Val0;
return TimeSpan.Parse(hms(zr));
}
TimeSpan Sunset(byte Month, byte Day, double Longitude, double Latitude)
{
Values ep = sun(Month, Day, 18, Longitude);
double zr = ep.Val0,
delta = ep.Val1,
ha = loc2hor(90.833, delta, Latitude),
t = Round(zr + ha, 24);
ep = sun(Month, Day, t, Longitude);
zr = ep.Val0;
delta = ep.Val1;
ha = loc2hor(90.833, delta, Latitude);
t = Round(zr + ha, 24);
return TimeSpan.Parse(hms(t));
}
TimeSpan SunsetPrayer(byte Month, byte Day, double Longitude, double Latitude)
{
Values ep = sun(Month, Day, 18.5, Longitude);
double zr = ep.Val0,
delta = ep.Val1,
ha = loc2hor(94.3, delta, Latitude),
t = Round(zr + ha, 24);
ep = sun(Month, Day, t, Longitude);
zr = ep.Val0;
delta = ep.Val1;
ha = loc2hor(94.3, delta, Latitude);
t = Round(zr + ha, 24);
return TimeSpan.Parse(hms(t));
}
Values sun(byte m, double d, double h, double lg)
{
if (m < 7)
d = 31 * (m - 1) + d + h / 24;
else
d = 6 + 30 * (m - 1) + d + h / 24;
double M = 74.2023 + 0.98560026 * d,
L = -2.75043 + 0.98564735 * d,
lst = 8.3162159 + 0.065709824 * Math.Floor(d) + 1.00273791 * 24 * (d % 1) + lg / 15,
e = 0.0167065,
omega = 4.85131 - 0.052954 * d,
ep = 23.4384717 + 0.00256 * cosd(omega),
ed = 180.0 / Math.PI * e, u = M;
for (byte i = 1; i < 5; i++)
u = u - (u - ed * sind(u) - M) / (1 - e * cosd(u));
double v = 2 * atand(tand(u / 2) * Math.Sqrt((1 + e) / (1 - e))),
theta = L + v - M - 0.00569 - 0.00479 * sind(omega),
delta = asind(sind(ep) * sind(theta)),
alpha = 180.0 / Math.PI * Math.Atan2(cosd(ep) * sind(theta), cosd(theta));
if (alpha >= 360)
alpha -= 360;
double ha = lst - alpha / 15;
double zr = Round(h - ha, 24);
Values vlu;
vlu.Val1 = delta;
vlu.Val0 = zr;
return vlu;
}
double sind(double x) { return Math.Sin(Math.PI / 180.0 * x); }
double cosd(double x) { return Math.Cos(Math.PI / 180.0 * x); }
double tand(double x) { return Math.Tan(Math.PI / 180.0 * x); }
double atand(double x) { return Math.Atan(x) * 180.0 / Math.PI; }
double asind(double x) { return Math.Asin(x) * 180.0 / Math.PI; }
double acosd(double x) { return Math.Acos(x) * 180.0 / Math.PI; }
double loc2hor(double z, double d, double p) { return acosd((cosd(z) - sind(d) * sind(p)) / cosd(d) / cosd(p)) / 15; }
double Round(double x, byte a)
{
double tmp = x % a;
if (tmp < 0)
tmp += a;
return tmp;
}
string hms(double x)
{
x = Math.Floor(3600 * x);
double
h = Math.Floor(x / 3600),
mp = x - 3600 * h,
m = Math.Floor(mp / 60),
s = Math.Floor(mp - 60 * m);
return h.ToString() + ":" + m.ToString() + ":" + s.ToString();
}
Note: Month and Day paramiters are PersianCalendar, for converting to it:
DateTime gregorian = new DateTime(Year, Month, Day);
System.Globalization.PersianCalendar pc = new System.Globalization.PersianCalendar();
Month = (byte)pc.GetMonth(gregorian);
Day = (byte)pc.GetDayOfMonth(gregorian);