BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 06-13-2011, 07:49 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Mar 2011
Model: 8900
PIN: N/A
Carrier: Torch
Posts: 59
Post Thanks: 3
Thanked 1 Time in 1 Post
Default Hello

Please Login to Remove!

Hello,

I am working in blackberry using eclipse

I calculated prayer times using following code:-

public void setCurrentDateTime() {
currentDate = new Date();
Calendar c = Calendar.getInstance();
c.setTime(currentDate);
tz = TimeZone.getDefault();
c.setTimeZone(tz);

// calculate day of the year (rather tricky!)
c.set(Calendar.MONTH, 0);
c.set(Calendar.DAY_OF_MONTH, 1);
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
Date JanFirst = c.getTime();
long millis = currentDate.getTime()-JanFirst.getTime();

DayOfTheYear = (int) (millis / 1000 / 3600 / 24);
}

public void calculatePrayerTimes() {
// Sh=1 (Shafii) - Sh=2 (Hanafi)

int Sh = settings.juristicMethod+1;

int J = DayOfTheYear;
double D; // Solar Declination angle (degrees)
double T; // Equation of Time (minutes)
double B; // Latitude (degrees)
double L; // Longitude (degrees)
double R; // Reference longitude (degrees)


// method described here:
// http://qvezst.googlepages.com/Prayer...wareDevelo.doc

double TZ = HourMinute.getTimeZoneOffset();

double beta = 2.0* Math.PI * J / 365.0;

L = longitude;
B = latitude;
//////////calculate Solar Declination angle (degrees)////////////////////////
D = 180.0 / Math.PI * (
0.006918
- 0.399912*Math.cos(beta)
+ 0.070257*Math.sin(beta)
- 0.006758*Math.cos(2.0*beta)
+ 0.000907*Math.sin(2.0*beta)
- 0.002697*Math.cos(3.0*beta)
+ 0.001480*Math.sin(3.0*beta));
////////calculate Equation of Time (minutes)/////////////////////////////
T = 229.18 * (
0.000075
+ 0.001868*Math.cos(beta)
- 0.032077*Math.sin(beta)
- 0.014615*Math.cos(2.0*beta)
- 0.040849*Math.sin(2.0*beta));
/////////////calculate Reference longitude (degrees)/////////////////////
R = 15.0 *TZ;
double Gd =18;// getDawnAngle();
double Gn = 18;//getDuskAngle();
double H = altitude;
double Dhuhr = 12+(R-L)/15-T/60;
double U = 180.0 / Math.PI / 15.0 *
mMath.acos(
(Math.sin((-0.8333 - 0.0347*sign(H)*Math.sqrt(Math.abs(H)))*Math.PI/180.0)
- Math.sin(D*Math.PI/180.0)*Math.sin(B*Math.PI/180.0))
/
(Math.cos(D*Math.PI/180.0)*Math.cos(B*Math.PI/180.0))
);

double Vd = 180.0 / 15.0 / Math.PI *
mMath.acos(
(-Math.sin(Gd*Math.PI/180.0)-Math.sin(D*Math.PI/180.0)*Math.sin(B*Math.PI/180.0))
/
(Math.cos(D*Math.PI/180.0)*Math.cos(B*Math.PI/180.0))
);
double Vn = 0;
if (Gn < 25) {
Vn = 180.0 / 15.0 / Math.PI *
mMath.acos(
(-Math.sin(Gn*Math.PI/180.0)-Math.sin(D*Math.PI/180.0)*Math.sin(B*Math.PI/180.0))
/
(Math.cos(D*Math.PI/180.0)*Math.cos(B*Math.PI/180.0))
);
}
else {
Vn = Gn/60;
}
double W = 180.0 / 15.0 / Math.PI *
mMath.acos(
(Math.sin( mMath.acotan( Sh + Math.tan(Math.abs(B-D)*Math.PI/180.0) ) )
- Math.sin(D*Math.PI/180.0)*Math.sin(B*Math.PI/180.0))
/
(Math.cos(D*Math.PI/180.0)*Math.cos(B*Math.PI/180.0))
);


mins[0]=getMinutes(Dhuhr-Vd); //Fajr
mins[1]=getMinutes(Dhuhr-U); //Al Sharuq
mins[2]=getMinutes(Dhuhr); //Dhuhr
mins[3]=getMinutes(Dhuhr+W); //Asr
mins[4]=getMinutes(Dhuhr+U); //Margrib
if (Gn < 25)
mins[5]=getMinutes(Dhuhr+Vn);
else
mins[5]=getMinutes(Dhuhr+U+Vn);


}
public String getPrayerTimes(boolean twentyFourHourClock, double minutes){
String str = "";
int mins = ((int)Math.max(0,minutes));
String minsStr = String.valueOf(mins%60);
if ((mins%60) < 10) minsStr = "0" + minsStr;
int hrs = mins/60;
if (!twentyFourHourClock) {
if (hrs > 12) hrs -= 12;
}
str = String.valueOf(hrs) + ":" + minsStr;
return str;
}
public double getMinutes(double hrs) {
double minutesSinceMidnight;
if (hrs>=24) hrs-=24;
if (hrs<0) hrs+= 24;
return minutesSinceMidnight = (hrs*60.0);
}

for latitude & longitude i use this webservice :
http://local.yahooapis.com/MapsServi...e&city=toronto

i am giving altitude as 0.0 always

I get wrong prayer times...Is some thing wrong with this code or i am missing some thing.. why this code gives me wrong prayer times??
any one have any idea?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.