Click here to Skip to main content
15,886,584 members
Please Sign up or sign in to vote.
2.75/5 (4 votes)
See more:
i want some idea or code for simple project of prayer time by using flash (better),other wise
using c#...
///////////////////
for example in the basic form show me the all prayer times in the day (we have 5 different time in a day):
Fajr : 04:45 am
Dhur : 12:10 pm
Asir : 03:30 pm
Magrib: 06:00 pm
Eisha : 08:15 pm
this task always updating for the next day.
(we have a database or a table for 362 days in the year).
.
.
.
.
Thanks...
Posted
Updated 18-Nov-11 23:52pm
v2
Comments
Smithers-Jones 19-Nov-11 5:10am    
I don't get it... It's your project, so you should have an idea about what you want yourself, and asking others for code doesn't make it your project either. I just don't get it.
What is a project about prayer time anyway? A timer that tells you when you have to pray next? A timer that tells you how long you still have to pray or have already prayed? Please enlighten me as I am an atheist.
thatraja 19-Nov-11 5:15am    
Agree with Smithers. Not clear.

1 solution

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
C#
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:
C#
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);
 
Share this answer
 
v2
Comments
Gene Novacek 4-Apr-16 14:28pm    
I found your solution here - thanks very much for this.
However, when I run it for a specific location (long/latitude), the times are all off by about 30 minutes.
I am using the proper Persian Month/Day.

Also, I believe the proper zenith to use for MorningPrayer is 107 (not 108) and for SunsetPrayer is 108 (not 94.3).

Can you offer any suggestions to help me get the proper times?
Thanks very much!!
Gene Novacek 4-Apr-16 14:30pm    
And by the way - I converted this to C++.
used fmod for %
int for byte

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900