From 11799ac697108cdf60063aea307cc67eeafc7eb0 Mon Sep 17 00:00:00 2001 From: fikr4n Date: Mon, 13 Feb 2017 06:43:21 +0700 Subject: [PATCH] Convert tab to 4-space --- README.md | 132 +- src/example/Example.java | 180 +-- src/org/arabeyes/itl/hijri/HijriCalc.java | 118 +- .../arabeyes/itl/hijri/HijriCalculator.java | 468 +++--- src/org/arabeyes/itl/hijri/HijriNames.java | 88 +- .../arabeyes/itl/hijri/SimpleHijriDate.java | 228 +-- .../itl/hijri/UmmAlquraCalculator.java | 1278 +++++++-------- src/org/arabeyes/itl/hijri/event.properties | 2 +- src/org/arabeyes/itl/hijri/name.properties | 2 +- src/org/arabeyes/itl/prayer/CustomMethod.java | 294 ++-- src/org/arabeyes/itl/prayer/Method.java | 768 ++++----- src/org/arabeyes/itl/prayer/PrayerTime.java | 130 +- .../arabeyes/itl/prayer/PrayerTimeCalc.java | 1380 ++++++++--------- src/org/arabeyes/itl/prayer/PrayerTimes.java | 98 +- src/org/arabeyes/itl/prayer/TimeNames.java | 66 +- src/org/arabeyes/itl/prayer/astro/Astro.java | 136 +- .../arabeyes/itl/prayer/astro/AstroDay.java | 100 +- .../arabeyes/itl/prayer/astro/AstroLib.java | 960 ++++++------ .../arabeyes/itl/prayer/astro/Direction.java | 4 +- src/org/arabeyes/itl/prayer/astro/Dms.java | 158 +- .../arabeyes/itl/prayer/astro/Location.java | 284 ++-- .../itl/prayer/astro/SimpleGregorianDate.java | 78 +- src/org/arabeyes/itl/prayer/astro/Utils.java | 70 +- 23 files changed, 3511 insertions(+), 3511 deletions(-) diff --git a/README.md b/README.md index 729e585..979cefb 100644 --- a/README.md +++ b/README.md @@ -17,51 +17,51 @@ display it directly to the user. **Basic usage** ``` java - /* As an example, we use Depok (West Java, Indonesia) as the location - * and Egyptian General Authority of Survey as the method. */ - - // new Location(latitude, longitude, GMT diff, daylight saving time) - Location location = new Location(-6.37812775, 106.8342445, +7, 0); - PrayerTimeCalc calculator = new PrayerTimeCalc(location, Method.EGYPT_SURVEY); - - /* Calculate prayer times for today. */ - - PrayerTimes prayerTimes = calculator.getPrayerTimes(new Date()); - - /* Print Fajr and sunrise time. */ - - PrayerTime fajr = prayerTimes.get(PrayerTimes.FAJR); - System.out.printl(fajr.getHour() + ":" + fajr.getMinute()); + /* As an example, we use Depok (West Java, Indonesia) as the location + * and Egyptian General Authority of Survey as the method. */ + + // new Location(latitude, longitude, GMT diff, daylight saving time) + Location location = new Location(-6.37812775, 106.8342445, +7, 0); + PrayerTimeCalc calculator = new PrayerTimeCalc(location, Method.EGYPT_SURVEY); + + /* Calculate prayer times for today. */ + + PrayerTimes prayerTimes = calculator.getPrayerTimes(new Date()); + + /* Print Fajr and sunrise time. */ + + PrayerTime fajr = prayerTimes.get(PrayerTimes.FAJR); + System.out.printl(fajr.getHour() + ":" + fajr.getMinute()); ``` **Getting qibla direction** ``` java - PrayerTimeCalc calculator = . . . - System.out.println(calculator.getNorthQibla()); - - // Or simply - - Location location = . . . - System.out.println(PrayerTimeCalc.getNorthQibla(location)); + PrayerTimeCalc calculator = . . . + System.out.println(calculator.getNorthQibla()); + + // Or simply + + Location location = . . . + System.out.println(PrayerTimeCalc.getNorthQibla(location)); ``` **Displaying along with built-in prayer names** ``` java - PrayerTimes prayerTimes = . . . - - /* Print all prayers (Fajr .. Isha) and sunrise using default locale. */ - - TimeNames names = TimeNames.getInstance(Locale.getDefault()); - for (int i = 0; i < 6; ++i) { - - /* PrayerTimes.FAJR, PrayerTimes.ZUHR, etc are integer constants from 0 to 5. */ - System.out.printf("%s\t%s:%s\n", - names.get(i), - prayerTimes.get(i).getHour(), - prayerTimes.get(i).getMinute()); - } + PrayerTimes prayerTimes = . . . + + /* Print all prayers (Fajr .. Isha) and sunrise using default locale. */ + + TimeNames names = TimeNames.getInstance(Locale.getDefault()); + for (int i = 0; i < 6; ++i) { + + /* PrayerTimes.FAJR, PrayerTimes.ZUHR, etc are integer constants from 0 to 5. */ + System.out.printf("%s\t%s:%s\n", + names.get(i), + prayerTimes.get(i).getHour(), + prayerTimes.get(i).getMinute()); + } ``` **Using imsak** @@ -70,11 +70,11 @@ Imsak (minutes before saum/fasting) is calculated separately, i.e. not using `PrayerTimeCalc.getPrayerTimes()`. ``` java - /* Print imsak for today. */ - - PrayerTimeCalc calculator = . . . - PrayerTime imsakTime = calculator.getImsak(new Date()); - System.out.println(imsakTime.getHour() + ":" + imsakTime.getMinute()); + /* Print imsak for today. */ + + PrayerTimeCalc calculator = . . . + PrayerTime imsakTime = calculator.getImsak(new Date()); + System.out.println(imsakTime.getHour() + ":" + imsakTime.getMinute()); ``` ### Hijri (and Umm Al-Qura) date ### @@ -86,43 +86,43 @@ also be +2 or -2 :). **Basic usage** ``` java - /* Convert current date to Hijri calendar. */ - - SimpleHijriDate hdate = HijriCalc.toHijri(new Date()); - - /* Like in standard Java, month starts from 0. */ - - System.out.println(hdate.getYear() + "-" + - (hdate.getMonth() + 1) + "-" + - hdate.getDayOfMonth()); + /* Convert current date to Hijri calendar. */ + + SimpleHijriDate hdate = HijriCalc.toHijri(new Date()); + + /* Like in standard Java, month starts from 0. */ + + System.out.println(hdate.getYear() + "-" + + (hdate.getMonth() + 1) + "-" + + hdate.getDayOfMonth()); ``` **Displaying along with built-in month names** ``` java - SimpleHijriDate hdate = . . . - - System.out.printf("%s, %s %s %s %s\n", - hdate.getDayOfWeekName(locale), - hdate.getDayOfMonth(), - hdate.getMonthName(locale), - hdate.getYear(), - hdate.getEraName(locale)); - System.out.printf("%s %s-%s-%s\n", - hdate.getDayOfWeekShortName(locale), - hdate.getDayOfMonth(), - hdate.getMonthShortName(locale), - hdate.getYear()); + SimpleHijriDate hdate = . . . + + System.out.printf("%s, %s %s %s %s\n", + hdate.getDayOfWeekName(locale), + hdate.getDayOfMonth(), + hdate.getMonthName(locale), + hdate.getYear(), + hdate.getEraName(locale)); + System.out.printf("%s %s-%s-%s\n", + hdate.getDayOfWeekShortName(locale), + hdate.getDayOfMonth(), + hdate.getMonthShortName(locale), + hdate.getYear()); ``` - + `get*Name()` above are the shortcuts for `HijriNames.getInstance(locale).get*Name()`. **Using Umm Al-Qura** ``` java - /* Convert current date to Umm Al-Qura calendar. */ - - SimpleHijriDate hdate = HijriCalc.toUmmAlqura(new Date()); + /* Convert current date to Umm Al-Qura calendar. */ + + SimpleHijriDate hdate = HijriCalc.toUmmAlqura(new Date()); ``` ## Prayer times calculation methods ## diff --git a/src/example/Example.java b/src/example/Example.java index 8545f57..318bb46 100644 --- a/src/example/Example.java +++ b/src/example/Example.java @@ -14,94 +14,94 @@ public class Example { - public static void main(String[] args) { - showPrayerTime(); - showHijri(); - showUmmAlqura(); - } - - public static void showHijri() { - System.out.println("=== HIJRI ==="); - - /* We use the default locale to print the name of days and months. */ - Locale locale = Locale.getDefault(); - - /* Convert current date to Hijri calendar. */ - SimpleHijriDate hdate = HijriCalc.toHijri(new Date()); - - /* Print it. */ - System.out.printf("%s, %s %s %s %s\n", - hdate.getDayOfWeekName(locale), - hdate.getDayOfMonth(), - hdate.getMonthName(locale), - hdate.getYear(), - hdate.getEraName(locale)); - System.out.printf("%s %s-%s-%s\n", - hdate.getDayOfWeekShortName(locale), - hdate.getDayOfMonth(), - hdate.getMonthShortName(locale), - hdate.getYear()); - System.out.printf("%s-%s-%s\n", - hdate.getDayOfMonth(), - hdate.getMonth() + 1, // Month (and also day of week) is started from 0 - hdate.getYear()); - } - - public static void showUmmAlqura() { - System.out.println("=== UMM AL-QURA ==="); - - /* We use the default locale to print the name of days and months. */ - Locale locale = Locale.getDefault(); - - /* Convert current date to Umm Al-Qura calendar. */ - SimpleHijriDate hdate = HijriCalc.toUmmAlqura(new Date()); - - /* Print it. */ - System.out.printf("%s, %s %s %s %s\n", - hdate.getDayOfWeekName(locale), - hdate.getDayOfMonth(), - hdate.getMonthName(locale), - hdate.getYear(), - hdate.getEraName(locale)); - System.out.printf("%s %s-%s-%s\n", - hdate.getDayOfWeekShortName(locale), - hdate.getDayOfMonth(), - hdate.getMonthShortName(locale), - hdate.getYear()); - System.out.printf("%s-%s-%s\n", - hdate.getDayOfMonth(), - hdate.getMonth() + 1, // Month (as well as day of week) is started from 0 - hdate.getYear()); - } - - public static void showPrayerTime() { - System.out.println("=== PRAYER TIME ==="); - - /* As an example, we use the location of Depok (West Java, Indonesia) and - * Egyptian General Authority of Survey method. */ - Location location = new Location(-6.37812775, 106.8342445, +7, 0); - Method method = Method.EGYPT_SURVEY; - - /* Instantiate the calculator. */ - PrayerTimeCalc calculator = new PrayerTimeCalc(location, method); - - /* Calculate prayer times for today. */ - Date date = new Date(); - PrayerTimes prayerTimes = calculator.getPrayerTimes(date); - PrayerTime imsakTime = calculator.getImsak(date); - - /* Print it (using default locale). */ - TimeNames names = TimeNames.getInstance(Locale.getDefault()); - System.out.printf("%s\t%s:%s\n", - names.getImsak(), - imsakTime.getHour(), - imsakTime.getMinute()); - for (int i = 0; i < 6; ++i) { - System.out.printf("%s\t%s:%s\n", - names.get(i), - prayerTimes.get(i).getHour(), - prayerTimes.get(i).getMinute()); - } - System.out.println("Qibla direction: " + calculator.getNorthQibla()); - } + public static void main(String[] args) { + showPrayerTime(); + showHijri(); + showUmmAlqura(); + } + + public static void showHijri() { + System.out.println("=== HIJRI ==="); + + /* We use the default locale to print the name of days and months. */ + Locale locale = Locale.getDefault(); + + /* Convert current date to Hijri calendar. */ + SimpleHijriDate hdate = HijriCalc.toHijri(new Date()); + + /* Print it. */ + System.out.printf("%s, %s %s %s %s\n", + hdate.getDayOfWeekName(locale), + hdate.getDayOfMonth(), + hdate.getMonthName(locale), + hdate.getYear(), + hdate.getEraName(locale)); + System.out.printf("%s %s-%s-%s\n", + hdate.getDayOfWeekShortName(locale), + hdate.getDayOfMonth(), + hdate.getMonthShortName(locale), + hdate.getYear()); + System.out.printf("%s-%s-%s\n", + hdate.getDayOfMonth(), + hdate.getMonth() + 1, // Month (and also day of week) is started from 0 + hdate.getYear()); + } + + public static void showUmmAlqura() { + System.out.println("=== UMM AL-QURA ==="); + + /* We use the default locale to print the name of days and months. */ + Locale locale = Locale.getDefault(); + + /* Convert current date to Umm Al-Qura calendar. */ + SimpleHijriDate hdate = HijriCalc.toUmmAlqura(new Date()); + + /* Print it. */ + System.out.printf("%s, %s %s %s %s\n", + hdate.getDayOfWeekName(locale), + hdate.getDayOfMonth(), + hdate.getMonthName(locale), + hdate.getYear(), + hdate.getEraName(locale)); + System.out.printf("%s %s-%s-%s\n", + hdate.getDayOfWeekShortName(locale), + hdate.getDayOfMonth(), + hdate.getMonthShortName(locale), + hdate.getYear()); + System.out.printf("%s-%s-%s\n", + hdate.getDayOfMonth(), + hdate.getMonth() + 1, // Month (as well as day of week) is started from 0 + hdate.getYear()); + } + + public static void showPrayerTime() { + System.out.println("=== PRAYER TIME ==="); + + /* As an example, we use the location of Depok (West Java, Indonesia) and + * Egyptian General Authority of Survey method. */ + Location location = new Location(-6.37812775, 106.8342445, +7, 0); + Method method = Method.EGYPT_SURVEY; + + /* Instantiate the calculator. */ + PrayerTimeCalc calculator = new PrayerTimeCalc(location, method); + + /* Calculate prayer times for today. */ + Date date = new Date(); + PrayerTimes prayerTimes = calculator.getPrayerTimes(date); + PrayerTime imsakTime = calculator.getImsak(date); + + /* Print it (using default locale). */ + TimeNames names = TimeNames.getInstance(Locale.getDefault()); + System.out.printf("%s\t%s:%s\n", + names.getImsak(), + imsakTime.getHour(), + imsakTime.getMinute()); + for (int i = 0; i < 6; ++i) { + System.out.printf("%s\t%s:%s\n", + names.get(i), + prayerTimes.get(i).getHour(), + prayerTimes.get(i).getMinute()); + } + System.out.println("Qibla direction: " + calculator.getNorthQibla()); + } } diff --git a/src/org/arabeyes/itl/hijri/HijriCalc.java b/src/org/arabeyes/itl/hijri/HijriCalc.java index c9e38bd..0fa5a90 100644 --- a/src/org/arabeyes/itl/hijri/HijriCalc.java +++ b/src/org/arabeyes/itl/hijri/HijriCalc.java @@ -29,66 +29,66 @@ * */ public class HijriCalc { - - private static void error(String msg) { - System.err.println("HijriCalc: " + msg); - } + + private static void error(String msg) { + System.err.println("HijriCalc: " + msg); + } - public static SimpleHijriDate toHijri(Date date) { - GregorianCalendar gcal = new GregorianCalendar(); - gcal.setTime(date); - - if (gcal.get(Calendar.ERA) != GregorianCalendar.AD) - error("Function h_date doesn't provide era input, it should be AD"); - - HijriCalculator.sDate mydate = new HijriCalculator.sDate(); - HijriCalculator.h_date(mydate, gcal.get(Calendar.DAY_OF_MONTH), - gcal.get(Calendar.MONTH) + 1, gcal.get(Calendar.YEAR)); - return new SimpleHijriDate(mydate); - } - - public static Date fromHijri(int year, int month, int day) { - HijriCalculator.sDate mydate = new HijriCalculator.sDate(); - HijriCalculator.g_date(mydate, day, month + 1, year); - GregorianCalendar result = new GregorianCalendar(mydate.year, mydate.month - 1, mydate.day); - if (HijriCalculator.GREGORIAN_BC.equals(mydate.units)) - result.set(Calendar.ERA, GregorianCalendar.BC); - return result.getTime(); - } + public static SimpleHijriDate toHijri(Date date) { + GregorianCalendar gcal = new GregorianCalendar(); + gcal.setTime(date); + + if (gcal.get(Calendar.ERA) != GregorianCalendar.AD) + error("Function h_date doesn't provide era input, it should be AD"); + + HijriCalculator.sDate mydate = new HijriCalculator.sDate(); + HijriCalculator.h_date(mydate, gcal.get(Calendar.DAY_OF_MONTH), + gcal.get(Calendar.MONTH) + 1, gcal.get(Calendar.YEAR)); + return new SimpleHijriDate(mydate); + } + + public static Date fromHijri(int year, int month, int day) { + HijriCalculator.sDate mydate = new HijriCalculator.sDate(); + HijriCalculator.g_date(mydate, day, month + 1, year); + GregorianCalendar result = new GregorianCalendar(mydate.year, mydate.month - 1, mydate.day); + if (HijriCalculator.GREGORIAN_BC.equals(mydate.units)) + result.set(Calendar.ERA, GregorianCalendar.BC); + return result.getTime(); + } - /** - * Only valid for 1420 H to 1450 H. - * @param gcal - * @return - */ - public static SimpleHijriDate toUmmAlqura(Date date) { - GregorianCalendar gcal = new GregorianCalendar(); - gcal.setTime(date); - - if (gcal.get(Calendar.ERA) != GregorianCalendar.AD) - error("Function G2H doesn't provide era input, it should be AD"); - - HijriCalculator.sDate mydate = new HijriCalculator.sDate(); - UmmAlquraCalculator.G2H(mydate, gcal.get(Calendar.DAY_OF_MONTH), - gcal.get(Calendar.MONTH) + 1, gcal.get(Calendar.YEAR)); - if (mydate.year < 1420 || mydate.year > 1450) - error("Invalid year for Umm Al-Qura returned by function G2H: " + mydate.year); - return new SimpleHijriDate(mydate); - } - - /** - * - * @param year between 1420 and 1450 - * @param month start from 0 (Muharram) - * @param day start from 1 - * @return - */ - public static Date fromUmmAlqura(int year, int month, int day) { - if (year < 1420 || year > 1450) - error("Invalid year for Umm Al-Qura: " + year); - HijriCalculator.sDate mydate = new HijriCalculator.sDate(); - UmmAlquraCalculator.H2G(mydate, day, month + 1, year); - return new GregorianCalendar(mydate.year, mydate.month - 1, mydate.day).getTime(); - } + /** + * Only valid for 1420 H to 1450 H. + * @param gcal + * @return + */ + public static SimpleHijriDate toUmmAlqura(Date date) { + GregorianCalendar gcal = new GregorianCalendar(); + gcal.setTime(date); + + if (gcal.get(Calendar.ERA) != GregorianCalendar.AD) + error("Function G2H doesn't provide era input, it should be AD"); + + HijriCalculator.sDate mydate = new HijriCalculator.sDate(); + UmmAlquraCalculator.G2H(mydate, gcal.get(Calendar.DAY_OF_MONTH), + gcal.get(Calendar.MONTH) + 1, gcal.get(Calendar.YEAR)); + if (mydate.year < 1420 || mydate.year > 1450) + error("Invalid year for Umm Al-Qura returned by function G2H: " + mydate.year); + return new SimpleHijriDate(mydate); + } + + /** + * + * @param year between 1420 and 1450 + * @param month start from 0 (Muharram) + * @param day start from 1 + * @return + */ + public static Date fromUmmAlqura(int year, int month, int day) { + if (year < 1420 || year > 1450) + error("Invalid year for Umm Al-Qura: " + year); + HijriCalculator.sDate mydate = new HijriCalculator.sDate(); + UmmAlquraCalculator.H2G(mydate, day, month + 1, year); + return new GregorianCalendar(mydate.year, mydate.month - 1, mydate.day).getTime(); + } } diff --git a/src/org/arabeyes/itl/hijri/HijriCalculator.java b/src/org/arabeyes/itl/hijri/HijriCalculator.java index 97be92b..6e92684 100644 --- a/src/org/arabeyes/itl/hijri/HijriCalculator.java +++ b/src/org/arabeyes/itl/hijri/HijriCalculator.java @@ -36,241 +36,241 @@ */ class HijriCalculator { - public static final String GREGORIAN_AD = "A.D"; - public static final String GREGORIAN_BC = "B.C"; - public static final String HIJRI_AH = "A.H"; - public static final String HIJRI_BH = "B.H"; + public static final String GREGORIAN_AD = "A.D"; + public static final String GREGORIAN_BC = "B.C"; + public static final String HIJRI_AH = "A.H"; + public static final String HIJRI_BH = "B.H"; - /* User-viewable Date structure */ - static final class sDate - { - int day; /* Day */ - int month; /* Month */ - int year; /* Year */ - int weekday; /* Day of the week (0:Sunday, 1:Monday...) */ - int frm_numdays; /* Number of days in specified input month */ - int to_numdays; /* Number of days in resulting output month */ - int to_numdays2; /* Number of days in resulting output month+1 */ - String units; /* Units used to denote before/after epoch */ -// String frm_dname; /* Converting from - Name of day */ -// String frm_mname; /* Converting from - Name of month */ -// String frm_dname_sh; /* Converting from - Name of day in short format */ -// String frm_mname_sh; /* Converting from - Name of month in short format */ -// String to_dname; /* Converting to - Name of day */ -// String to_mname; /* Converting to - Name of month */ -// String to_mname2; /* Converting to - Name of month+1 */ -// String to_dname_sh; /* Converting to - Name of day in short format */ -// String to_mname_sh; /* Converting to - Name of month in short format */ -// String[] event; /* Important event pertaining to date at hand */ - } + /* User-viewable Date structure */ + static final class sDate + { + int day; /* Day */ + int month; /* Month */ + int year; /* Year */ + int weekday; /* Day of the week (0:Sunday, 1:Monday...) */ + int frm_numdays; /* Number of days in specified input month */ + int to_numdays; /* Number of days in resulting output month */ + int to_numdays2; /* Number of days in resulting output month+1 */ + String units; /* Units used to denote before/after epoch */ +// String frm_dname; /* Converting from - Name of day */ +// String frm_mname; /* Converting from - Name of month */ +// String frm_dname_sh; /* Converting from - Name of day in short format */ +// String frm_mname_sh; /* Converting from - Name of month in short format */ +// String to_dname; /* Converting to - Name of day */ +// String to_mname; /* Converting to - Name of month */ +// String to_mname2; /* Converting to - Name of month+1 */ +// String to_dname_sh; /* Converting to - Name of day in short format */ +// String to_mname_sh; /* Converting to - Name of month in short format */ +// String[] event; /* Important event pertaining to date at hand */ + } - /* Absolute date of start of Islamic calendar (July 19, 622 Gregorian)*/ - private static final int HijriEpoch = 227015; -// private static final int GregorianEpoch = 1; - - // END OF COMMON + /* Absolute date of start of Islamic calendar (July 19, 622 Gregorian)*/ + private static final int HijriEpoch = 227015; +// private static final int GregorianEpoch = 1; + + // END OF COMMON - /* Wrapper function to do a division and a floor call */ - private static float - divf(float x, - float y) - { - return (float) ( Math.floor(x / y) ); - } - - /* Determine if Hijri passed-in year is a leap year */ - private static int - h_leapyear(int year) - { - /* True if year is an Islamic leap year */ - - if ( Math.abs(((11 * year) + 14) % 30) < 11 ) - return(1); - else - return(0); - } - - - /* Determine the number of days in passed-in hijri month/year */ - private static int - h_numdays(int month, - int year) - { - /* Last day in month during year on the Islamic calendar. */ - - if (((month % 2) == 1) || ((month == 12) && h_leapyear(year) != 0)) - return(30); - else - return(29); - } - - - /* Determine Hijri absolute date from passed-in day/month/year */ - private static int - h_absolute(int day, - int month, - int year) - { - /* Computes the Islamic date from the absolute date. */ - return (int) (day // days so far this month - + (29 * (month - 1)) // days so far... - + divf(month, 2) // ...this year - + (354 * (year - 1)) // non-leap days in prior years - + divf((3 + (11 * year)), 30) // leap days in prior years - + HijriEpoch - 1); // days before start of calendar - } - - - /* Determine Hijri/Islamic date from passed-in Gregorian day/month/year - ie. Gregorian -> Hijri - */ - static void - h_date(sDate cdate, - int day, - int month, - int year) - { - int abs_date; - int pre_epoch = 0; - - /* Account for Pre-Epoch date correction, year 0 entry */ - if (year < 0) - year++; - - abs_date = g_absolute(day, month, year); - - /* Search forward/backward year by year from approximate year */ - if (abs_date < HijriEpoch) - { - cdate.year = 0; - - while (abs_date <= h_absolute(1, 1, cdate.year)) - cdate.year--; - } - else - { - cdate.year = (int) divf((abs_date - HijriEpoch - 1), 355); - - while (abs_date >= h_absolute(1, 1, cdate.year+1)) - cdate.year++; - } - - /* Search forward month by month from Muharram */ - cdate.month = 1; - while (abs_date > h_absolute(h_numdays(cdate.month, cdate.year), - cdate.month, - cdate.year)) - cdate.month++; - - cdate.day = abs_date - h_absolute(1, cdate.month, cdate.year) + 1; - - /* Account for Pre-Hijrah date correction, year 0 entry */ - if (cdate.year <= 0) - { - pre_epoch = 1; - cdate.year = ((cdate.year - 1) * -1); - } - - /* Set resulting values */ - cdate.units = ( pre_epoch != 0 ? HIJRI_BH : HIJRI_AH ); - cdate.weekday = (Math.abs(abs_date % 7)); - cdate.frm_numdays = g_numdays(month, year); - cdate.to_numdays = h_numdays(cdate.month, cdate.year); - cdate.to_numdays2 = h_numdays((cdate.month + 1), cdate.year); - }; - - - /* Determine the number of days in passed-in gregorian month/year */ - private static int - g_numdays(int month, - int year) - { - int y; - - y = Math.abs(year); - - /* Compute the last date of the month for the Gregorian calendar. */ - switch (month) - { - case 2: - if ( (((y % 4) == 0) && ((y % 100) != 0)) || ((y % 400) == 0) ) - return(29); - else - return(28); - case 4: - case 6: - case 9: - case 11: return(30); - default: return(31); - } - } - - - /* Determine Gregorian absolute date from passed-in day/month/year */ - private static int - g_absolute(int day, - int month, - int year) - { - int N = day; /* days this month */ - int m; - - for (m = month - 1; m > 0; m--) /* days in prior months this year */ - N += g_numdays(m, year); - - return (int) (N // days this year - + 365 * (year - 1) // previous years days ignoring leap - + divf((year - 1), 4) // Julian leap days before this year.. - - divf((year - 1), 100) // ..minus prior century years... - + divf((year - 1), 400)); // ..plus prior years divisible by 400 - } - - - /* Determine Gregorian date from passed-in Hijri/Islamic day/month/year - ie. Hijri -> Gregorian - */ - static void - g_date(sDate cdate, - int day, - int month, - int year) - { - int abs_date; - int pre_epoch = 0; - - /* Account for Pre-Epoch date correction, year 0 entry */ - if (year < 0) - year++; - - abs_date = h_absolute(day, month, year); - - /* Search forward year by year from approximate year */ - cdate.year = (int) divf(abs_date, 366); - - while (abs_date >= g_absolute(1, 1, cdate.year+1)) - cdate.year++; - - /* Search forward month by month from January */ - cdate.month = 1; - while (abs_date > g_absolute(g_numdays(cdate.month, cdate.year), - cdate.month, - cdate.year)) - cdate.month++; - - cdate.day = abs_date - g_absolute(1, cdate.month, cdate.year) + 1; - - /* Account for Pre-Hijrah date correction, year 0 entry */ - if (cdate.year <= 0) - { - pre_epoch = 1; - cdate.year = ((cdate.year - 1) * -1); - } - - /* Set resulting values */ - cdate.units = ( pre_epoch != 0 ? GREGORIAN_BC : GREGORIAN_AD ); - cdate.weekday = (Math.abs(abs_date % 7)); - cdate.frm_numdays = h_numdays(month, year); - cdate.to_numdays = g_numdays(cdate.month, cdate.year); - cdate.to_numdays2 = g_numdays((cdate.month + 1), cdate.year); - }; + /* Wrapper function to do a division and a floor call */ + private static float + divf(float x, + float y) + { + return (float) ( Math.floor(x / y) ); + } + + /* Determine if Hijri passed-in year is a leap year */ + private static int + h_leapyear(int year) + { + /* True if year is an Islamic leap year */ + + if ( Math.abs(((11 * year) + 14) % 30) < 11 ) + return(1); + else + return(0); + } + + + /* Determine the number of days in passed-in hijri month/year */ + private static int + h_numdays(int month, + int year) + { + /* Last day in month during year on the Islamic calendar. */ + + if (((month % 2) == 1) || ((month == 12) && h_leapyear(year) != 0)) + return(30); + else + return(29); + } + + + /* Determine Hijri absolute date from passed-in day/month/year */ + private static int + h_absolute(int day, + int month, + int year) + { + /* Computes the Islamic date from the absolute date. */ + return (int) (day // days so far this month + + (29 * (month - 1)) // days so far... + + divf(month, 2) // ...this year + + (354 * (year - 1)) // non-leap days in prior years + + divf((3 + (11 * year)), 30) // leap days in prior years + + HijriEpoch - 1); // days before start of calendar + } + + + /* Determine Hijri/Islamic date from passed-in Gregorian day/month/year + ie. Gregorian -> Hijri + */ + static void + h_date(sDate cdate, + int day, + int month, + int year) + { + int abs_date; + int pre_epoch = 0; + + /* Account for Pre-Epoch date correction, year 0 entry */ + if (year < 0) + year++; + + abs_date = g_absolute(day, month, year); + + /* Search forward/backward year by year from approximate year */ + if (abs_date < HijriEpoch) + { + cdate.year = 0; + + while (abs_date <= h_absolute(1, 1, cdate.year)) + cdate.year--; + } + else + { + cdate.year = (int) divf((abs_date - HijriEpoch - 1), 355); + + while (abs_date >= h_absolute(1, 1, cdate.year+1)) + cdate.year++; + } + + /* Search forward month by month from Muharram */ + cdate.month = 1; + while (abs_date > h_absolute(h_numdays(cdate.month, cdate.year), + cdate.month, + cdate.year)) + cdate.month++; + + cdate.day = abs_date - h_absolute(1, cdate.month, cdate.year) + 1; + + /* Account for Pre-Hijrah date correction, year 0 entry */ + if (cdate.year <= 0) + { + pre_epoch = 1; + cdate.year = ((cdate.year - 1) * -1); + } + + /* Set resulting values */ + cdate.units = ( pre_epoch != 0 ? HIJRI_BH : HIJRI_AH ); + cdate.weekday = (Math.abs(abs_date % 7)); + cdate.frm_numdays = g_numdays(month, year); + cdate.to_numdays = h_numdays(cdate.month, cdate.year); + cdate.to_numdays2 = h_numdays((cdate.month + 1), cdate.year); + }; + + + /* Determine the number of days in passed-in gregorian month/year */ + private static int + g_numdays(int month, + int year) + { + int y; + + y = Math.abs(year); + + /* Compute the last date of the month for the Gregorian calendar. */ + switch (month) + { + case 2: + if ( (((y % 4) == 0) && ((y % 100) != 0)) || ((y % 400) == 0) ) + return(29); + else + return(28); + case 4: + case 6: + case 9: + case 11: return(30); + default: return(31); + } + } + + + /* Determine Gregorian absolute date from passed-in day/month/year */ + private static int + g_absolute(int day, + int month, + int year) + { + int N = day; /* days this month */ + int m; + + for (m = month - 1; m > 0; m--) /* days in prior months this year */ + N += g_numdays(m, year); + + return (int) (N // days this year + + 365 * (year - 1) // previous years days ignoring leap + + divf((year - 1), 4) // Julian leap days before this year.. + - divf((year - 1), 100) // ..minus prior century years... + + divf((year - 1), 400)); // ..plus prior years divisible by 400 + } + + + /* Determine Gregorian date from passed-in Hijri/Islamic day/month/year + ie. Hijri -> Gregorian + */ + static void + g_date(sDate cdate, + int day, + int month, + int year) + { + int abs_date; + int pre_epoch = 0; + + /* Account for Pre-Epoch date correction, year 0 entry */ + if (year < 0) + year++; + + abs_date = h_absolute(day, month, year); + + /* Search forward year by year from approximate year */ + cdate.year = (int) divf(abs_date, 366); + + while (abs_date >= g_absolute(1, 1, cdate.year+1)) + cdate.year++; + + /* Search forward month by month from January */ + cdate.month = 1; + while (abs_date > g_absolute(g_numdays(cdate.month, cdate.year), + cdate.month, + cdate.year)) + cdate.month++; + + cdate.day = abs_date - g_absolute(1, cdate.month, cdate.year) + 1; + + /* Account for Pre-Hijrah date correction, year 0 entry */ + if (cdate.year <= 0) + { + pre_epoch = 1; + cdate.year = ((cdate.year - 1) * -1); + } + + /* Set resulting values */ + cdate.units = ( pre_epoch != 0 ? GREGORIAN_BC : GREGORIAN_AD ); + cdate.weekday = (Math.abs(abs_date % 7)); + cdate.frm_numdays = h_numdays(month, year); + cdate.to_numdays = g_numdays(cdate.month, cdate.year); + cdate.to_numdays2 = g_numdays((cdate.month + 1), cdate.year); + }; } diff --git a/src/org/arabeyes/itl/hijri/HijriNames.java b/src/org/arabeyes/itl/hijri/HijriNames.java index bbb020b..8fe4bbe 100644 --- a/src/org/arabeyes/itl/hijri/HijriNames.java +++ b/src/org/arabeyes/itl/hijri/HijriNames.java @@ -4,49 +4,49 @@ import java.util.ResourceBundle; public class HijriNames { - - private static HijriNames instance; - - private ResourceBundle res; - private Locale locale; - - public HijriNames(Locale locale) { - this.res = ResourceBundle.getBundle("org.arabeyes.itl.hijri.name", locale); - this.locale = locale; - } - - public Locale getLocale() { - return locale; - } + + private static HijriNames instance; + + private ResourceBundle res; + private Locale locale; + + public HijriNames(Locale locale) { + this.res = ResourceBundle.getBundle("org.arabeyes.itl.hijri.name", locale); + this.locale = locale; + } + + public Locale getLocale() { + return locale; + } - public String getDayName(int dayOfWeek) { - return res.getString("day.long." + dayOfWeek); - } - - public String getDayShortName(int dayOfWeek) { - return res.getString("day.short." + dayOfWeek); - } - - public String getMonthName(int month) { - return res.getString("month.long." + month); - } - - public String getMonthShortName(int month) { - return res.getString("month.short." + month); - } - - public String getEraName(int era) { - if (era == SimpleHijriDate.ERA_BH) - return res.getString("era.bh"); - else if (era == SimpleHijriDate.ERA_AH) - return res.getString("era.ah"); - else - throw new IllegalArgumentException("Invalid Hijri era: " + era); - } - - public static HijriNames getInstance(Locale locale) { - if (instance == null || !instance.locale.equals(locale)) - instance = new HijriNames(locale); - return instance; - } + public String getDayName(int dayOfWeek) { + return res.getString("day.long." + dayOfWeek); + } + + public String getDayShortName(int dayOfWeek) { + return res.getString("day.short." + dayOfWeek); + } + + public String getMonthName(int month) { + return res.getString("month.long." + month); + } + + public String getMonthShortName(int month) { + return res.getString("month.short." + month); + } + + public String getEraName(int era) { + if (era == SimpleHijriDate.ERA_BH) + return res.getString("era.bh"); + else if (era == SimpleHijriDate.ERA_AH) + return res.getString("era.ah"); + else + throw new IllegalArgumentException("Invalid Hijri era: " + era); + } + + public static HijriNames getInstance(Locale locale) { + if (instance == null || !instance.locale.equals(locale)) + instance = new HijriNames(locale); + return instance; + } } diff --git a/src/org/arabeyes/itl/hijri/SimpleHijriDate.java b/src/org/arabeyes/itl/hijri/SimpleHijriDate.java index 0591005..f84cf73 100644 --- a/src/org/arabeyes/itl/hijri/SimpleHijriDate.java +++ b/src/org/arabeyes/itl/hijri/SimpleHijriDate.java @@ -27,125 +27,125 @@ * */ public class SimpleHijriDate { - /* This class uses Java convention so that month number is starting from 0 instead of 1. - * But the original calculator uses 1-based month number. - */ + /* This class uses Java convention so that month number is starting from 0 instead of 1. + * But the original calculator uses 1-based month number. + */ - /** Before Hijri. */ - public static final int ERA_BH = -1; - /** After Hijri (anno-hegirae). */ - public static final int ERA_AH = 0; - - private int year; - private int month; - private int dayOfMonth; - private int dayOfWeek; - private int monthLength; - private int era; - - SimpleHijriDate(HijriCalculator.sDate d) { - this.year = d.year; - this.month = d.month - 1; - this.dayOfMonth = d.day; - this.dayOfWeek = d.weekday; - this.monthLength = d.to_numdays; - if (HijriCalculator.HIJRI_BH.equals(d.units)) - era = ERA_BH; - else - era = ERA_AH; - } + /** Before Hijri. */ + public static final int ERA_BH = -1; + /** After Hijri (anno-hegirae). */ + public static final int ERA_AH = 0; + + private int year; + private int month; + private int dayOfMonth; + private int dayOfWeek; + private int monthLength; + private int era; + + SimpleHijriDate(HijriCalculator.sDate d) { + this.year = d.year; + this.month = d.month - 1; + this.dayOfMonth = d.day; + this.dayOfWeek = d.weekday; + this.monthLength = d.to_numdays; + if (HijriCalculator.HIJRI_BH.equals(d.units)) + era = ERA_BH; + else + era = ERA_AH; + } - /** - * Start from 1. - * @return - */ - public int getDayOfMonth() { - return dayOfMonth; - } + /** + * Start from 1. + * @return + */ + public int getDayOfMonth() { + return dayOfMonth; + } - /** - * Start from 0 for Ahad (Sunday). - * @return - */ - public int getDayOfWeek() { - return dayOfWeek; - } + /** + * Start from 0 for Ahad (Sunday). + * @return + */ + public int getDayOfWeek() { + return dayOfWeek; + } - /** - * Start from 0 for Muharram. - * @return - */ - public int getMonth() { - return month; - } + /** + * Start from 0 for Muharram. + * @return + */ + public int getMonth() { + return month; + } - /** - * The year. - * @return - */ - public int getYear() { - return year; - } + /** + * The year. + * @return + */ + public int getYear() { + return year; + } - /** - * Number of days in this month. - * @return - */ - public int getMonthLength() { - return monthLength; - } - - /** - * Could be {@link #ERA_AH} or {@link #ERA_BH}. - * @return - */ - public int getEra() { - return era; - } - - /** - * Short cut for {@link HijriNames}. - * @param locale - * @return - */ - public String getDayOfWeekName(Locale locale) { - return HijriNames.getInstance(locale).getDayName(dayOfWeek); - } - - /** - * Short cut for {@link HijriNames}. - * @param locale - * @return - */ - public String getDayOfWeekShortName(Locale locale) { - return HijriNames.getInstance(locale).getDayShortName(dayOfWeek); - } - - /** - * Short cut for {@link HijriNames}. - * @param locale - * @return - */ - public String getMonthName(Locale locale) { - return HijriNames.getInstance(locale).getMonthName(month); - } - - /** - * Short cut for {@link HijriNames}. - * @param locale - * @return - */ - public String getMonthShortName(Locale locale) { - return HijriNames.getInstance(locale).getMonthShortName(month); - } - - /** - * Short cut for {@link HijriNames}. - * @param locale - * @return - */ - public String getEraName(Locale locale) { - return HijriNames.getInstance(locale).getEraName(era); - } + /** + * Number of days in this month. + * @return + */ + public int getMonthLength() { + return monthLength; + } + + /** + * Could be {@link #ERA_AH} or {@link #ERA_BH}. + * @return + */ + public int getEra() { + return era; + } + + /** + * Short cut for {@link HijriNames}. + * @param locale + * @return + */ + public String getDayOfWeekName(Locale locale) { + return HijriNames.getInstance(locale).getDayName(dayOfWeek); + } + + /** + * Short cut for {@link HijriNames}. + * @param locale + * @return + */ + public String getDayOfWeekShortName(Locale locale) { + return HijriNames.getInstance(locale).getDayShortName(dayOfWeek); + } + + /** + * Short cut for {@link HijriNames}. + * @param locale + * @return + */ + public String getMonthName(Locale locale) { + return HijriNames.getInstance(locale).getMonthName(month); + } + + /** + * Short cut for {@link HijriNames}. + * @param locale + * @return + */ + public String getMonthShortName(Locale locale) { + return HijriNames.getInstance(locale).getMonthShortName(month); + } + + /** + * Short cut for {@link HijriNames}. + * @param locale + * @return + */ + public String getEraName(Locale locale) { + return HijriNames.getInstance(locale).getEraName(era); + } } diff --git a/src/org/arabeyes/itl/hijri/UmmAlquraCalculator.java b/src/org/arabeyes/itl/hijri/UmmAlquraCalculator.java index 2f05ea5..2bc0cd3 100644 --- a/src/org/arabeyes/itl/hijri/UmmAlquraCalculator.java +++ b/src/org/arabeyes/itl/hijri/UmmAlquraCalculator.java @@ -41,654 +41,654 @@ */ class UmmAlquraCalculator { - private static final int HStartYear = 1420; - private static final int HEndYear = 1450; - - private static final int MonthMap[]={19410, - 19396,19337,19093,13613,13741,15210,18132,19913,19858,19110, - 18774,12974,13677,13162,15189,19114,14669,13469,14685,12986, - 13749,17834,15701,19098,14638,12910,13661,15066,18132,18085 - }; - - /* makes it circular m[0]=m[12] & m[13]=m[1] */ - private static final short[] gmonth={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] */ -// private static final short[] smonth={31,30,30,30,30,30,29,31,31,31,31,31,31,30}; - - /****************************************************************************/ - /* Name: Hsub2G */ - /* Type: Procedure */ - /* Purpose: Finds Gdate(year,month,day) for Hdate(year,month,day) */ - /* Arguments: */ - /* Input: Hijri date: year:yh, month:mh */ - /* Output: Gregorian date: year:yg, month:mg, day:dg , day of week:dayweek */ - /* and returns flag found:1 not found:0 */ - /****************************************************************************/ - private static int Hsub2G(HijriCalculator.sDate mydate, int mh, int yh) - { - int flag; - int JD; - double GJD; - - /* Make sure that the date is within the range of the tables */ - if(mh < 1) {mh = 12;} - if(mh > 12) {mh = 1;} - if(yh < HStartYear) {yh = HStartYear;} - if(yh > HEndYear) {yh = HEndYear;} - - GJD = HCalendarToJDA(yh, mh, 1); - JDToGCalendar(GJD, mydate); - JD = (int) GJD; - mydate.weekday = (JD + 1) % 7; - /* NOTE: so when is flag = 0 ? */ - flag = 1; /* date has been found */ - - return(flag); - } - - /****************************************************************************/ - /* Name: HCalendarToJDA */ - /* Type: Function */ - /* Purpose: convert Hdate(year,month,day) to Exact Julian Day */ - /* Arguments: */ - /* Input : Hijrah date: year:yh, month:mh, day:dh */ - /* Output: The Exact Julian Day: JD */ - /****************************************************************************/ - private static double HCalendarToJDA(int yh, int mh, int dh) - { - int flag, Dy, m, b; - int JD; - double GJD; - - /* estimate JD of the beginning of year */ - JD = (int) HCalendarToJD(yh, 1, 1); - Dy = MonthMap[yh-HStartYear]/4096; /* Mask 1111000000000000 */ - GJD = JD - 3 + Dy; /* correct the JD value from stored tables */ - b = MonthMap[yh - HStartYear]; - b = b - Dy * 4096; - for(m=1; m < mh; m++) - { - flag = b % 2; /* Mask for the current month */ - if(flag != 0) - Dy = 30; - else - Dy = 29; - GJD = GJD + Dy; /* Add the months lengths before mh */ - b = (b - flag) / 2; - } - GJD = GJD + dh - 1; - - return(GJD); - } - - /****************************************************************************/ - /* Name: HMonthLength */ - /* Type: Function */ - /* Purpose: Obtains the month length */ - /* Arguments: */ - /* Input : Hijrah date: year:yh, month:mh */ - /* Output: Month Length */ - /****************************************************************************/ - private static int HMonthLength(int yh, int mh) - { - int flag, Dy, m, b; - - if(yhHEndYear) - { - flag = 0; - Dy = 0; - } - else - { - Dy = MonthMap[yh - HStartYear]/4096; /* Mask 1111000000000000 */ - b = MonthMap[yh - HStartYear]; - b = b - Dy * 4096; - for(m=1; m <= mh; m++) - { - flag = b % 2; /* Mask for the current month */ - if(flag != 0) - Dy = 30; - else - Dy = 29; - b = (b - flag) / 2; - } - } - return(Dy); - } - -// /****************************************************************************/ -// /* Name: DayInYear */ -// /* Type: Function */ -// /* Purpose: Obtains the day number in the yea */ -// /* Arguments: */ -// /* Input : Hijrah date: year:yh, month:mh day:dh */ -// /* Output: Day number in the Year */ -// /****************************************************************************/ -// private static int DayinYear(int yh, int mh, int dh) -// { -// int flag, Dy, m, b, DL; + private static final int HStartYear = 1420; + private static final int HEndYear = 1450; + + private static final int MonthMap[]={19410, + 19396,19337,19093,13613,13741,15210,18132,19913,19858,19110, + 18774,12974,13677,13162,15189,19114,14669,13469,14685,12986, + 13749,17834,15701,19098,14638,12910,13661,15066,18132,18085 + }; + + /* makes it circular m[0]=m[12] & m[13]=m[1] */ + private static final short[] gmonth={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] */ +// private static final short[] smonth={31,30,30,30,30,30,29,31,31,31,31,31,31,30}; + + /****************************************************************************/ + /* Name: Hsub2G */ + /* Type: Procedure */ + /* Purpose: Finds Gdate(year,month,day) for Hdate(year,month,day) */ + /* Arguments: */ + /* Input: Hijri date: year:yh, month:mh */ + /* Output: Gregorian date: year:yg, month:mg, day:dg , day of week:dayweek */ + /* and returns flag found:1 not found:0 */ + /****************************************************************************/ + private static int Hsub2G(HijriCalculator.sDate mydate, int mh, int yh) + { + int flag; + int JD; + double GJD; + + /* Make sure that the date is within the range of the tables */ + if(mh < 1) {mh = 12;} + if(mh > 12) {mh = 1;} + if(yh < HStartYear) {yh = HStartYear;} + if(yh > HEndYear) {yh = HEndYear;} + + GJD = HCalendarToJDA(yh, mh, 1); + JDToGCalendar(GJD, mydate); + JD = (int) GJD; + mydate.weekday = (JD + 1) % 7; + /* NOTE: so when is flag = 0 ? */ + flag = 1; /* date has been found */ + + return(flag); + } + + /****************************************************************************/ + /* Name: HCalendarToJDA */ + /* Type: Function */ + /* Purpose: convert Hdate(year,month,day) to Exact Julian Day */ + /* Arguments: */ + /* Input : Hijrah date: year:yh, month:mh, day:dh */ + /* Output: The Exact Julian Day: JD */ + /****************************************************************************/ + private static double HCalendarToJDA(int yh, int mh, int dh) + { + int flag, Dy, m, b; + int JD; + double GJD; + + /* estimate JD of the beginning of year */ + JD = (int) HCalendarToJD(yh, 1, 1); + Dy = MonthMap[yh-HStartYear]/4096; /* Mask 1111000000000000 */ + GJD = JD - 3 + Dy; /* correct the JD value from stored tables */ + b = MonthMap[yh - HStartYear]; + b = b - Dy * 4096; + for(m=1; m < mh; m++) + { + flag = b % 2; /* Mask for the current month */ + if(flag != 0) + Dy = 30; + else + Dy = 29; + GJD = GJD + Dy; /* Add the months lengths before mh */ + b = (b - flag) / 2; + } + GJD = GJD + dh - 1; + + return(GJD); + } + + /****************************************************************************/ + /* Name: HMonthLength */ + /* Type: Function */ + /* Purpose: Obtains the month length */ + /* Arguments: */ + /* Input : Hijrah date: year:yh, month:mh */ + /* Output: Month Length */ + /****************************************************************************/ + private static int HMonthLength(int yh, int mh) + { + int flag, Dy, m, b; + + if(yhHEndYear) + { + flag = 0; + Dy = 0; + } + else + { + Dy = MonthMap[yh - HStartYear]/4096; /* Mask 1111000000000000 */ + b = MonthMap[yh - HStartYear]; + b = b - Dy * 4096; + for(m=1; m <= mh; m++) + { + flag = b % 2; /* Mask for the current month */ + if(flag != 0) + Dy = 30; + else + Dy = 29; + b = (b - flag) / 2; + } + } + return(Dy); + } + +// /****************************************************************************/ +// /* Name: DayInYear */ +// /* Type: Function */ +// /* Purpose: Obtains the day number in the yea */ +// /* Arguments: */ +// /* Input : Hijrah date: year:yh, month:mh day:dh */ +// /* Output: Day number in the Year */ +// /****************************************************************************/ +// private static int DayinYear(int yh, int mh, int dh) +// { +// int flag, Dy, m, b, DL; // -// if(yhHEndYear) -// { -// flag = 0; -// DL = 0; -// } -// else -// { -// Dy = MonthMap[yh - HStartYear]/4096; /* Mask 1111000000000000 */ -// b = MonthMap[yh - HStartYear]; -// b = b - Dy * 4096; -// DL = 0; -// for(m = 1; m <= mh; m++) -// { -// flag = b % 2; /* Mask for the current month */ -// if(flag != 0) -// Dy = 30; -// else -// Dy = 29; -// b = (b - flag) / 2; -// DL = DL + Dy; -// } -// DL = DL + dh; -// } -// return(DL); -// } - -// /****************************************************************************/ -// /* Name: HYearLength */ -// /* Type: Function */ -// /* Purpose: Obtains the year length */ -// /* Arguments: */ -// /* Input : Hijrah date: year:yh */ -// /* Output: Year Length */ -// /****************************************************************************/ -// private static int HYearLength(int yh) -// { -// int flag, Dy, m, b, YL; +// if(yhHEndYear) +// { +// flag = 0; +// DL = 0; +// } +// else +// { +// Dy = MonthMap[yh - HStartYear]/4096; /* Mask 1111000000000000 */ +// b = MonthMap[yh - HStartYear]; +// b = b - Dy * 4096; +// DL = 0; +// for(m = 1; m <= mh; m++) +// { +// flag = b % 2; /* Mask for the current month */ +// if(flag != 0) +// Dy = 30; +// else +// Dy = 29; +// b = (b - flag) / 2; +// DL = DL + Dy; +// } +// DL = DL + dh; +// } +// return(DL); +// } + +// /****************************************************************************/ +// /* Name: HYearLength */ +// /* Type: Function */ +// /* Purpose: Obtains the year length */ +// /* Arguments: */ +// /* Input : Hijrah date: year:yh */ +// /* Output: Year Length */ +// /****************************************************************************/ +// private static int HYearLength(int yh) +// { +// int flag, Dy, m, b, YL; // -// if(yhHEndYear) -// { -// flag = 0; -// YL = 0; -// } -// else -// { -// Dy = MonthMap[yh - HStartYear]/4096; /* Mask 1111000000000000 */ -// b = MonthMap[yh - HStartYear]; -// b = b - Dy * 4096; -// flag = b % 2; /* Mask for the current month */ -// if(flag != 0) -// YL = 30; -// else -// YL = 29; +// if(yhHEndYear) +// { +// flag = 0; +// YL = 0; +// } +// else +// { +// Dy = MonthMap[yh - HStartYear]/4096; /* Mask 1111000000000000 */ +// b = MonthMap[yh - HStartYear]; +// b = b - Dy * 4096; +// flag = b % 2; /* Mask for the current month */ +// if(flag != 0) +// YL = 30; +// else +// YL = 29; // -// for(m = 2; m <= 12; m++) -// { -// flag = b % 2; /* Mask for the current month */ -// if(flag != 0) -// Dy = 30; -// else -// Dy = 29; -// b = (b - flag) / 2; -// YL = YL + Dy; -// } -// } -// return(YL); -// } - - /****************************************************************************/ - /* Name: G2H */ - /* Type: Procedure */ - /* Purpose: convert Gdate(year,month,day) to Hdate(year,month,day) */ - /* Arguments: */ - /* Input: Gregorian date: year:yg, month:mg, day:dg */ - /* Output: Hijrah date: year:yh, month:mh, day:dh, day of week:dayweek */ - /* and returns flag found:1 not found:0 */ - /****************************************************************************/ - static int G2H(HijriCalculator.sDate mydate, int dg, int mg, int yg) - { - int yh2, mh2; - int df; - int flag = 1; - int J; - double GJD, HJD; - HijriCalculator.sDate tmpdate = new HijriCalculator.sDate(); - HijriCalculator.sDate tmpdate2 = new HijriCalculator.sDate(); - - GJD = GCalendarToJD(yg, mg, dg + 0.5); /* find JD of Gdate */ - - /* estimate the Hdate that correspond to the Gdate */ - JDToHCalendar(GJD, tmpdate); - - /* get the exact Julian Day */ - HJD = HCalendarToJDA(tmpdate.year, tmpdate.month, tmpdate.day); - df = (int) (GJD - HJD); - tmpdate.day += df; - while(tmpdate.day > 30) - { - tmpdate.day -= HMonthLength(tmpdate.year, tmpdate.month); - tmpdate.month++; - if(tmpdate.month > 12) - { - tmpdate.year++; - tmpdate.month = 1; - } - } - if(tmpdate.day == 30) - { - yh2 = tmpdate.year; - mh2 = tmpdate.month + 1; - if(mh2 > 12) - { - yh2++; - mh2 = 1; - } - Hsub2G(tmpdate2, mh2, yh2); - - /* Make sure that the month is 30days if not make adjustment */ - if(dg == tmpdate2.day) - { - tmpdate.year = yh2; - tmpdate.month = mh2; - tmpdate.day = 1; - } - } - - J = (int) (GCalendarToJD(yg, mg, dg)+2); - mydate.weekday = J % 7; - mydate.to_numdays = 1; /* this needs to be fixed !! */ - mydate.year = tmpdate.year; - mydate.month = tmpdate.month; - mydate.day = tmpdate.day; - - return(flag); - } - - /****************************************************************************/ - /* Name: H2G */ - /* Type: Procedure */ - /* Purpose: convert Hdate(year,month,day) to Gdate(year,month,day) */ - /* Arguments: */ - /* Input/Ouput: Hijrah date: year:yh, month:mh, day:dh */ - /* Output: Gregorian date: year:yg, month:mg, day:dg , day of week:dayweek */ - /* and returns flag found:1 not found:0 */ - /* Note: The function will correct Hdate if day=30 and the month is 29 only */ - /****************************************************************************/ - static int H2G(HijriCalculator.sDate mydate, int dh, int mh, int yh) - { - int found, yh1, mh1; - HijriCalculator.sDate tmpdate = new HijriCalculator.sDate(); - - /* make sure values are within the allowed values */ - if(dh > 30) { dh = 1; mh++; } - if(dh < 1) { dh = 1; mh--; } - if(mh > 12) { mh = 1; yh++; } - if(mh < 1) { mh = 12; yh--; } - - /* find the date of the begining of the month */ - found = Hsub2G(mydate, mh, yh); - mydate.day += dh - 1; - - /* Make sure that dates are within the correct values */ - GDateAjust(mydate); - mydate.weekday += dh - 1; - mydate.weekday = mydate.weekday % 7; - - /*find the date of the begining of the next month*/ - if(dh == 30) - { - mh1 = mh + 1; - yh1 = yh; - if(mh1 > 12) {mh1 -= 12; yh1++;} - found = Hsub2G(tmpdate, mh1, yh1); - /* Make sure that the month is 30days if not make adjustment */ - if(mydate.day == tmpdate.day) - { - mydate.year = tmpdate.year; - mydate.month = tmpdate.month; - mydate.day = 1; - } - } - - return(found); - } - - /****************************************************************************/ - /* Name: JDToGCalendar */ - /* Type: Procedure */ - /* Purpose: convert Julian Day to Gdate(year,month,day) */ - /* Arguments: */ - /* Input: The Julian Day: JD */ - /* Output: Gregorian date: year:yy, month:mm, day:dd */ - /****************************************************************************/ - private static double JDToGCalendar(double JD, HijriCalculator.sDate mydate) - { - double A, B, F; - int alpha, C, E; - int D, Z; - - Z = (int)Math.floor (JD + 0.5); - F = (JD + 0.5) - Z; - alpha = (int)((Z - 1867216.25) / 36524.25); - A = Z + 1 + alpha - alpha / 4; - B = A + 1524; - C = (int) ((B - 122.1) / 365.25); - D = (int) (365.25 * C); - E = (int)(((B - D) / 30.6001)); - mydate.day =(int) (B - D - Math.floor (30.6001 * E) + F); - if (E < 14) - mydate.month = E - 1; - else - mydate.month = E - 13; - if (mydate.month > 2) - mydate.year = C - 4716; - else - mydate.year = C - 4715; - - F = F * 24.0; - - return(F); - } - - /****************************************************************************/ - /* Name: GCalendarToJD */ - /* Type: Function */ - /* Purpose: convert Gdate(year,month,day) to Julian Day */ - /* Arguments: */ - /* Input : Gregorian date: year:yy, month:mm, day:dd */ - /* Output: The Julian Day: JD */ - /****************************************************************************/ - private static double GCalendarToJD(int yy, int mm, double dd) - { - /* It does not take care of 1582 correction assumes correct - calender from the past - */ - int A, B, m, y; - double T1, T2, Tr; - - if (mm > 2) - { - y = yy; - m = mm; - } - else - { - y = yy - 1; - m = mm + 12; - } - A = y / 100; - B = 2 - A + A / 4; - T1=ip (365.25 * (y + 4716)); - T2=ip (30.6001 * (m + 1)); - Tr=T1+ T2 + dd + B - 1524.5 ; - - return(Tr); - } - - /****************************************************************************/ - /* Name: GLeapYear */ - /* Type: Function */ - /* Purpose: Determines if Gdate(year) is leap or not */ - /* Arguments: */ - /* Input : Gregorian date: year */ - /* Output: 0:year not leap 1:year is leap */ - /****************************************************************************/ - private static int GLeapYear(int year) - { - int T = 0; - - if(year % 4 == 0) - T = 1; /* leap_year = 1; */ - - if(year % 100 == 0) - { - /* years=100,200,300,500,... are not leap years */ - T=0; - - /* years=400,800,1200,1600,2000,2400 are leap years */ - if(year % 400 == 0) T = 1; - } - - return(T); - } - - /****************************************************************************/ - /* Name: GDateAjust */ - /* Type: Procedure */ - /* Purpose: Adjust the G Dates by making sure that the month lengths */ - /* are correct if not so take the extra days to next month or year */ - /* Arguments: */ - /* Input: Gregorian date: year:yg, month:mg, day:dg */ - /* Output: corrected Gregorian date: year:yg, month:mg, day:dg */ - /****************************************************************************/ - private static void GDateAjust(HijriCalculator.sDate mydate) - { - int dys; - - /* Make sure that dates are within the correct values */ - /* Underflow */ - if(mydate.month < 1) /* months underflow */ - { - /* plus as the underflow months is negative */ - mydate.month += 12; - mydate.year--; - } - - if(mydate.day < 1) /* days underflow */ - { - /* month becomes the previous month */ - mydate.month--; - /* number of days of the month less the underflow days - (it is plus as the sign of the day is negative) - */ - mydate.day += gmonth[mydate.month]; - if(mydate.month == 2) - mydate.day += GLeapYear(mydate.year); - if(mydate.month < 1) /* months underflow */ - { - /* plus as the underflow months is negative */ - mydate.month += 12; - mydate.year--; - } - } - - /* Overflow */ - if(mydate.month > 12) /* months */ - { - mydate.month -= 12; - mydate.year++; - } - - if(mydate.month == 2) - /* number of days in the current month */ - dys = gmonth[mydate.month] + GLeapYear(mydate.year); - else - dys = gmonth[mydate.month]; - if(mydate.day > dys) /* days overflow */ - { - mydate.day -= dys; - mydate.month++; - if(mydate.month == 2) - { - /* number of days in the current month */ - dys = gmonth[mydate.month] + GLeapYear(mydate.year); - if(mydate.day > dys) - { - mydate.day -= dys; - mydate.month++; - } - } - if(mydate.month > 12) /* months */ - { - mydate.month -= 12; - mydate.year++; - } - } - mydate.to_numdays = dys; - } - -// /****************************************************************************/ -// /* -// The day of the week is obtained as -// Dy=(Julian+1)%7 -// Dy=0 Sunday -// Dy=1 Monday -// ... -// Dy=6 Saturday -// */ -// /****************************************************************************/ -// private static int DayWeek(int JulianD) -// { -// int Dy; +// for(m = 2; m <= 12; m++) +// { +// flag = b % 2; /* Mask for the current month */ +// if(flag != 0) +// Dy = 30; +// else +// Dy = 29; +// b = (b - flag) / 2; +// YL = YL + Dy; +// } +// } +// return(YL); +// } + + /****************************************************************************/ + /* Name: G2H */ + /* Type: Procedure */ + /* Purpose: convert Gdate(year,month,day) to Hdate(year,month,day) */ + /* Arguments: */ + /* Input: Gregorian date: year:yg, month:mg, day:dg */ + /* Output: Hijrah date: year:yh, month:mh, day:dh, day of week:dayweek */ + /* and returns flag found:1 not found:0 */ + /****************************************************************************/ + static int G2H(HijriCalculator.sDate mydate, int dg, int mg, int yg) + { + int yh2, mh2; + int df; + int flag = 1; + int J; + double GJD, HJD; + HijriCalculator.sDate tmpdate = new HijriCalculator.sDate(); + HijriCalculator.sDate tmpdate2 = new HijriCalculator.sDate(); + + GJD = GCalendarToJD(yg, mg, dg + 0.5); /* find JD of Gdate */ + + /* estimate the Hdate that correspond to the Gdate */ + JDToHCalendar(GJD, tmpdate); + + /* get the exact Julian Day */ + HJD = HCalendarToJDA(tmpdate.year, tmpdate.month, tmpdate.day); + df = (int) (GJD - HJD); + tmpdate.day += df; + while(tmpdate.day > 30) + { + tmpdate.day -= HMonthLength(tmpdate.year, tmpdate.month); + tmpdate.month++; + if(tmpdate.month > 12) + { + tmpdate.year++; + tmpdate.month = 1; + } + } + if(tmpdate.day == 30) + { + yh2 = tmpdate.year; + mh2 = tmpdate.month + 1; + if(mh2 > 12) + { + yh2++; + mh2 = 1; + } + Hsub2G(tmpdate2, mh2, yh2); + + /* Make sure that the month is 30days if not make adjustment */ + if(dg == tmpdate2.day) + { + tmpdate.year = yh2; + tmpdate.month = mh2; + tmpdate.day = 1; + } + } + + J = (int) (GCalendarToJD(yg, mg, dg)+2); + mydate.weekday = J % 7; + mydate.to_numdays = 1; /* this needs to be fixed !! */ + mydate.year = tmpdate.year; + mydate.month = tmpdate.month; + mydate.day = tmpdate.day; + + return(flag); + } + + /****************************************************************************/ + /* Name: H2G */ + /* Type: Procedure */ + /* Purpose: convert Hdate(year,month,day) to Gdate(year,month,day) */ + /* Arguments: */ + /* Input/Ouput: Hijrah date: year:yh, month:mh, day:dh */ + /* Output: Gregorian date: year:yg, month:mg, day:dg , day of week:dayweek */ + /* and returns flag found:1 not found:0 */ + /* Note: The function will correct Hdate if day=30 and the month is 29 only */ + /****************************************************************************/ + static int H2G(HijriCalculator.sDate mydate, int dh, int mh, int yh) + { + int found, yh1, mh1; + HijriCalculator.sDate tmpdate = new HijriCalculator.sDate(); + + /* make sure values are within the allowed values */ + if(dh > 30) { dh = 1; mh++; } + if(dh < 1) { dh = 1; mh--; } + if(mh > 12) { mh = 1; yh++; } + if(mh < 1) { mh = 12; yh--; } + + /* find the date of the begining of the month */ + found = Hsub2G(mydate, mh, yh); + mydate.day += dh - 1; + + /* Make sure that dates are within the correct values */ + GDateAjust(mydate); + mydate.weekday += dh - 1; + mydate.weekday = mydate.weekday % 7; + + /*find the date of the begining of the next month*/ + if(dh == 30) + { + mh1 = mh + 1; + yh1 = yh; + if(mh1 > 12) {mh1 -= 12; yh1++;} + found = Hsub2G(tmpdate, mh1, yh1); + /* Make sure that the month is 30days if not make adjustment */ + if(mydate.day == tmpdate.day) + { + mydate.year = tmpdate.year; + mydate.month = tmpdate.month; + mydate.day = 1; + } + } + + return(found); + } + + /****************************************************************************/ + /* Name: JDToGCalendar */ + /* Type: Procedure */ + /* Purpose: convert Julian Day to Gdate(year,month,day) */ + /* Arguments: */ + /* Input: The Julian Day: JD */ + /* Output: Gregorian date: year:yy, month:mm, day:dd */ + /****************************************************************************/ + private static double JDToGCalendar(double JD, HijriCalculator.sDate mydate) + { + double A, B, F; + int alpha, C, E; + int D, Z; + + Z = (int)Math.floor (JD + 0.5); + F = (JD + 0.5) - Z; + alpha = (int)((Z - 1867216.25) / 36524.25); + A = Z + 1 + alpha - alpha / 4; + B = A + 1524; + C = (int) ((B - 122.1) / 365.25); + D = (int) (365.25 * C); + E = (int)(((B - D) / 30.6001)); + mydate.day =(int) (B - D - Math.floor (30.6001 * E) + F); + if (E < 14) + mydate.month = E - 1; + else + mydate.month = E - 13; + if (mydate.month > 2) + mydate.year = C - 4716; + else + mydate.year = C - 4715; + + F = F * 24.0; + + return(F); + } + + /****************************************************************************/ + /* Name: GCalendarToJD */ + /* Type: Function */ + /* Purpose: convert Gdate(year,month,day) to Julian Day */ + /* Arguments: */ + /* Input : Gregorian date: year:yy, month:mm, day:dd */ + /* Output: The Julian Day: JD */ + /****************************************************************************/ + private static double GCalendarToJD(int yy, int mm, double dd) + { + /* It does not take care of 1582 correction assumes correct + calender from the past + */ + int A, B, m, y; + double T1, T2, Tr; + + if (mm > 2) + { + y = yy; + m = mm; + } + else + { + y = yy - 1; + m = mm + 12; + } + A = y / 100; + B = 2 - A + A / 4; + T1=ip (365.25 * (y + 4716)); + T2=ip (30.6001 * (m + 1)); + Tr=T1+ T2 + dd + B - 1524.5 ; + + return(Tr); + } + + /****************************************************************************/ + /* Name: GLeapYear */ + /* Type: Function */ + /* Purpose: Determines if Gdate(year) is leap or not */ + /* Arguments: */ + /* Input : Gregorian date: year */ + /* Output: 0:year not leap 1:year is leap */ + /****************************************************************************/ + private static int GLeapYear(int year) + { + int T = 0; + + if(year % 4 == 0) + T = 1; /* leap_year = 1; */ + + if(year % 100 == 0) + { + /* years=100,200,300,500,... are not leap years */ + T=0; + + /* years=400,800,1200,1600,2000,2400 are leap years */ + if(year % 400 == 0) T = 1; + } + + return(T); + } + + /****************************************************************************/ + /* Name: GDateAjust */ + /* Type: Procedure */ + /* Purpose: Adjust the G Dates by making sure that the month lengths */ + /* are correct if not so take the extra days to next month or year */ + /* Arguments: */ + /* Input: Gregorian date: year:yg, month:mg, day:dg */ + /* Output: corrected Gregorian date: year:yg, month:mg, day:dg */ + /****************************************************************************/ + private static void GDateAjust(HijriCalculator.sDate mydate) + { + int dys; + + /* Make sure that dates are within the correct values */ + /* Underflow */ + if(mydate.month < 1) /* months underflow */ + { + /* plus as the underflow months is negative */ + mydate.month += 12; + mydate.year--; + } + + if(mydate.day < 1) /* days underflow */ + { + /* month becomes the previous month */ + mydate.month--; + /* number of days of the month less the underflow days + (it is plus as the sign of the day is negative) + */ + mydate.day += gmonth[mydate.month]; + if(mydate.month == 2) + mydate.day += GLeapYear(mydate.year); + if(mydate.month < 1) /* months underflow */ + { + /* plus as the underflow months is negative */ + mydate.month += 12; + mydate.year--; + } + } + + /* Overflow */ + if(mydate.month > 12) /* months */ + { + mydate.month -= 12; + mydate.year++; + } + + if(mydate.month == 2) + /* number of days in the current month */ + dys = gmonth[mydate.month] + GLeapYear(mydate.year); + else + dys = gmonth[mydate.month]; + if(mydate.day > dys) /* days overflow */ + { + mydate.day -= dys; + mydate.month++; + if(mydate.month == 2) + { + /* number of days in the current month */ + dys = gmonth[mydate.month] + GLeapYear(mydate.year); + if(mydate.day > dys) + { + mydate.day -= dys; + mydate.month++; + } + } + if(mydate.month > 12) /* months */ + { + mydate.month -= 12; + mydate.year++; + } + } + mydate.to_numdays = dys; + } + +// /****************************************************************************/ +// /* +// The day of the week is obtained as +// Dy=(Julian+1)%7 +// Dy=0 Sunday +// Dy=1 Monday +// ... +// Dy=6 Saturday +// */ +// /****************************************************************************/ +// private static int DayWeek(int JulianD) +// { +// int Dy; // -// Dy = (JulianD + 1) % 7; +// Dy = (JulianD + 1) % 7; // -// return(Dy); -// } - - /****************************************************************************/ - /* Name: HCalendarToJD */ - /* Type: Function */ - /* Purpose: convert Hdate(year,month,day) to estimated Julian Day */ - /* Arguments: */ - /* Input : Hijrah date: year:yh, month:mh, day:dh */ - /* Output: The Estimated Julian Day: JD */ - /****************************************************************************/ - private static double HCalendarToJD(int yh, int mh, int dh) - { - /* Estimating The JD for hijrah dates - this is an approximate JD for the given hijrah date - */ - double md, yd; - - md = (mh - 1.0) * 29.530589; - yd = (yh - 1.0) * 354.367068 + md + dh - 1.0; - yd = yd + 1948439.0; /* add JD for 18/7/622 first Hijrah date */ - - return(yd); - } - - /****************************************************************************/ - /* Name: JDToHCalendar */ - /* Type: Procedure */ - /* Purpose: convert Julian Day to estimated Hdate(year,month,day) */ - /* Arguments: */ - /* Input: The Julian Day: JD */ - /* Output : Hijrah date: year:yh, month:mh, day:dh */ - /****************************************************************************/ - private static void JDToHCalendar(double JD, HijriCalculator.sDate mydate) - { - /* Estimating the hijrah date from JD */ - double md, yd; - - yd = JD-1948439.0; /* subtract JD for 18/7/622 first Hijrah date*/ - md = mod(yd, 354.367068); - mydate.day = mod(md + 0.5, 29.530589)+1; - mydate.month = (int) ((md/29.530589) + 1); - yd = yd - md; - mydate.year = (int) (yd/354.367068 + 1); - if(mydate.day > 30) {mydate.day -= 30; mydate.month++;} - if(mydate.month > 12) {mydate.month -= 12; mydate.year++;} - } - -// /****************************************************************************/ -// /* Name: JDToHACalendar */ -// /* Type: Procedure */ -// /* Purpose: convert Julian Day to Hdate(year,month,day) */ -// /* Arguments: */ -// /* Input: The Julian Day: JD */ -// /* Output : Hijrah date: year:yh, month:mh, day:dh */ -// /****************************************************************************/ -// private static int[] JDToHACalendar(double JD) -// { -// int yh, mh, dh; -// int df; -// int J; -// double HJD; -// HijriCalculator.sDate tmpdate = new HijriCalculator.sDate(); +// return(Dy); +// } + + /****************************************************************************/ + /* Name: HCalendarToJD */ + /* Type: Function */ + /* Purpose: convert Hdate(year,month,day) to estimated Julian Day */ + /* Arguments: */ + /* Input : Hijrah date: year:yh, month:mh, day:dh */ + /* Output: The Estimated Julian Day: JD */ + /****************************************************************************/ + private static double HCalendarToJD(int yh, int mh, int dh) + { + /* Estimating The JD for hijrah dates + this is an approximate JD for the given hijrah date + */ + double md, yd; + + md = (mh - 1.0) * 29.530589; + yd = (yh - 1.0) * 354.367068 + md + dh - 1.0; + yd = yd + 1948439.0; /* add JD for 18/7/622 first Hijrah date */ + + return(yd); + } + + /****************************************************************************/ + /* Name: JDToHCalendar */ + /* Type: Procedure */ + /* Purpose: convert Julian Day to estimated Hdate(year,month,day) */ + /* Arguments: */ + /* Input: The Julian Day: JD */ + /* Output : Hijrah date: year:yh, month:mh, day:dh */ + /****************************************************************************/ + private static void JDToHCalendar(double JD, HijriCalculator.sDate mydate) + { + /* Estimating the hijrah date from JD */ + double md, yd; + + yd = JD-1948439.0; /* subtract JD for 18/7/622 first Hijrah date*/ + md = mod(yd, 354.367068); + mydate.day = mod(md + 0.5, 29.530589)+1; + mydate.month = (int) ((md/29.530589) + 1); + yd = yd - md; + mydate.year = (int) (yd/354.367068 + 1); + if(mydate.day > 30) {mydate.day -= 30; mydate.month++;} + if(mydate.month > 12) {mydate.month -= 12; mydate.year++;} + } + +// /****************************************************************************/ +// /* Name: JDToHACalendar */ +// /* Type: Procedure */ +// /* Purpose: convert Julian Day to Hdate(year,month,day) */ +// /* Arguments: */ +// /* Input: The Julian Day: JD */ +// /* Output : Hijrah date: year:yh, month:mh, day:dh */ +// /****************************************************************************/ +// private static int[] JDToHACalendar(double JD) +// { +// int yh, mh, dh; +// int df; +// int J; +// double HJD; +// HijriCalculator.sDate tmpdate = new HijriCalculator.sDate(); // -// /* Estimate the Hdate that correspond to the Gdate */ -// JDToHCalendar(JD, tmpdate); -// /* get the exact Julian Day */ -// HJD = HCalendarToJDA(tmpdate.year, tmpdate.month, tmpdate.day); -// df = (int) (JD + 0.5 - HJD); -// tmpdate.day += df; -// while(tmpdate.day > 30) -// { -// tmpdate.day -= HMonthLength(tmpdate.year, tmpdate.month); -// tmpdate.month++; -// if(tmpdate.month > 12) -// { -// tmpdate.year++; -// tmpdate.month = 1; -// } -// } -// if(tmpdate.day == 30 && -// HMonthLength(tmpdate.year, tmpdate.month) < 30) -// { -// tmpdate.day = 1; -// tmpdate.month++; -// } -// if(tmpdate.month > 12) -// { -// tmpdate.month = 1; -// tmpdate.year++; -// } +// /* Estimate the Hdate that correspond to the Gdate */ +// JDToHCalendar(JD, tmpdate); +// /* get the exact Julian Day */ +// HJD = HCalendarToJDA(tmpdate.year, tmpdate.month, tmpdate.day); +// df = (int) (JD + 0.5 - HJD); +// tmpdate.day += df; +// while(tmpdate.day > 30) +// { +// tmpdate.day -= HMonthLength(tmpdate.year, tmpdate.month); +// tmpdate.month++; +// if(tmpdate.month > 12) +// { +// tmpdate.year++; +// tmpdate.month = 1; +// } +// } +// if(tmpdate.day == 30 && +// HMonthLength(tmpdate.year, tmpdate.month) < 30) +// { +// tmpdate.day = 1; +// tmpdate.month++; +// } +// if(tmpdate.month > 12) +// { +// tmpdate.month = 1; +// tmpdate.year++; +// } // -// /* -// J = JD + 2; -// *dayweek = J % 7; -// */ -// yh = tmpdate.year; -// mh = tmpdate.month; -// dh = tmpdate.day; -// return new int[] { yh, mh, dh }; -// } - - /**************************************************************************/ - /* Purpose: return the integral part of a double value. */ - /**************************************************************************/ - private static double ip(double x) - { - return (int) x; - } - - /**************************************************************************/ - /* Name: mod */ - /* Purpose: The mod operation for doubles x mod y */ - /**************************************************************************/ - private static int mod(double x, double y) - { - int r; - double d; - - d = x / y; - r = (int) d; - if(r < 0) - r--; - d = x - y * r; - r = (int) d; - - return(r); - } - -// /**************************************************************************/ -// /* Purpose: returns 0 for incorrect Hijri date and 1 for correct date */ -// /**************************************************************************/ -// private static int IsValid(int yh, int mh, int dh) -// { -// int valid = 1; +// /* +// J = JD + 2; +// *dayweek = J % 7; +// */ +// yh = tmpdate.year; +// mh = tmpdate.month; +// dh = tmpdate.day; +// return new int[] { yh, mh, dh }; +// } + + /**************************************************************************/ + /* Purpose: return the integral part of a double value. */ + /**************************************************************************/ + private static double ip(double x) + { + return (int) x; + } + + /**************************************************************************/ + /* Name: mod */ + /* Purpose: The mod operation for doubles x mod y */ + /**************************************************************************/ + private static int mod(double x, double y) + { + int r; + double d; + + d = x / y; + r = (int) d; + if(r < 0) + r--; + d = x - y * r; + r = (int) d; + + return(r); + } + +// /**************************************************************************/ +// /* Purpose: returns 0 for incorrect Hijri date and 1 for correct date */ +// /**************************************************************************/ +// private static int IsValid(int yh, int mh, int dh) +// { +// int valid = 1; // -// if((yh < HStartYear) || (yh > HEndYear)) -// valid = 0; +// if((yh < HStartYear) || (yh > HEndYear)) +// valid = 0; // -// if( (mh < 1) || (mh > 12)) -// valid = 0; +// if( (mh < 1) || (mh > 12)) +// valid = 0; // -// if( (dh < 1) || (dh > HMonthLength(yh, mh)) ) -// valid = 0; +// if( (dh < 1) || (dh > HMonthLength(yh, mh)) ) +// valid = 0; // -// return(valid); -// } +// return(valid); +// } } diff --git a/src/org/arabeyes/itl/hijri/event.properties b/src/org/arabeyes/itl/hijri/event.properties index 7019a01..87aa779 100644 --- a/src/org/arabeyes/itl/hijri/event.properties +++ b/src/org/arabeyes/itl/hijri/event.properties @@ -32,4 +32,4 @@ 10_12="Hajj to Makkah - day #3" 10_12="Eid Al-Adhaa - day #1" 11_12="Eid Al-Adhaa - day #2" -12_12="Eid Al-Adhaa - day #3" \ No newline at end of file +12_12="Eid Al-Adhaa - day #3" diff --git a/src/org/arabeyes/itl/hijri/name.properties b/src/org/arabeyes/itl/hijri/name.properties index e14ec88..2f7c79d 100644 --- a/src/org/arabeyes/itl/hijri/name.properties +++ b/src/org/arabeyes/itl/hijri/name.properties @@ -41,4 +41,4 @@ month.short.10=Qid month.short.11=Hij era.bh=BH -era.ah=H \ No newline at end of file +era.ah=H diff --git a/src/org/arabeyes/itl/prayer/CustomMethod.java b/src/org/arabeyes/itl/prayer/CustomMethod.java index 9ad3629..288d76f 100644 --- a/src/org/arabeyes/itl/prayer/CustomMethod.java +++ b/src/org/arabeyes/itl/prayer/CustomMethod.java @@ -8,152 +8,152 @@ * A mutable version of {@link Method}. */ public class CustomMethod extends Method { - - public CustomMethod() { - } + + public CustomMethod() { + } - /** - * Copy constructor - * @param orig method to copy from - */ - public CustomMethod(Method orig) { - this.fajrAng = orig.getFajrAng(); - this.ishaaAng = orig.getIshaaAng(); - this.imsaakAng = orig.getImsaakAng(); - this.fajrInv = orig.getFajrInv(); - this.ishaaInv = orig.getIshaaInv(); - this.imsaakInv = orig.getImsaakInv(); - this.round = orig.getRound(); - this.mathhab = orig.getMathhab(); - this.nearestLat = orig.getNearestLat(); - this.extremeLatitude = orig.getExtremeLatitude(); - this.offset = orig.getOffset(); - - this.fajrOffset = orig.getFajrOffset(); - this.shurooqOffset = orig.getShurooqOffset(); - this.thuhrOffset = orig.getThuhrOffset(); - this.assrOffset = orig.getAssrOffset(); - this.maghribOffset = orig.getMaghribOffset(); - this.ishaaOffset = orig.getIshaaOffset(); - } - - public void setAssrOffset(double assrOffset) { - this.assrOffset = assrOffset; - } - - /** - * - * @param extreme Extreme latitude calculation method - * @see ExtremeLatitude - */ - public void setExtremeLatitude(ExtremeLatitude extreme) { - this.extremeLatitude = extreme; - } - - public void setFajrAng(double fajrAng) { - this.fajrAng = fajrAng; - } - - /** - * - * @param fajrInv Fajr Interval is the amount of minutes between Fajr and - * Shurooq (0 if not used) - */ - public void setFajrInv(int fajrInv) { - this.fajrInv = fajrInv; - } - - public void setFajrOffset(double fajrOffset) { - this.fajrOffset = fajrOffset; - } - - /** - * - * @param imsaakAng The angle difference between Imsaak and Fajr (default - * is 1.5) - */ - public void setImsaakAng(double imsaakAng) { - this.imsaakAng = imsaakAng; - } - - /** - * - * @param imsaakInv Imsaak Interval is the amount of minutes between Imsaak - * and Fajr. The default is 10 minutes before Fajr if Fajr Interval is set - */ - public void setImsaakInv(int imsaakInv) { - this.imsaakInv = imsaakInv; - } - - public void setIshaaAng(double ishaaAng) { - this.ishaaAng = ishaaAng; - } - - /** - * - * @param ishaaInv Ishaa Interval is the amount if minutes between Ishaa and - * Maghrib (0 if not used) - */ - public void setIshaaInv(int ishaaInv) { - this.ishaaInv = ishaaInv; - } - - public void setIshaaOffset(double ishaaOffset) { - this.ishaaOffset = ishaaOffset; - } - - public void setMaghribOffset(double maghribOffset) { - this.maghribOffset = maghribOffset; - } - - /** - * - * @param mathhab mathhab for calculating assr prayer shadow ratio - * @see Madhhab - */ - public void setMathhab(Madhhab mathhab) { - this.mathhab = mathhab; - } - - /** - * - * @param nearestLat Latitude Used for the 'Nearest Latitude' extreme - * methods. The default is 48.5 - */ - public void setNearestLat(double nearestLat) { - this.nearestLat = nearestLat; - } - - /** - * - * @param offset Enable Offsets switch (set this to true to activate). This - * option allows you to add or subtract any amount of minutes to the daily - * computed prayer times based on values (in minutes) for each prayer in - * the next xxxOffset parameters - * For Example: If you want to add 30 seconds to Maghrib and subtract 2 - * minutes from Ishaa: - * method.setOffset(true); - * method.setMaghribOffset(0.5); - * method.setIshaaOffset(-2); - */ - public void setOffset(boolean offset) { - this.offset = offset; - } - - /** - * - * @param round Method used for rounding seconds - * @see Rounding - */ - public void setRound(Rounding round) { - this.round = round; - } - - public void setShurooqOffset(double shurooqOffset) { - this.shurooqOffset = shurooqOffset; - } - - public void setThuhrOffset(double thuhrOffset) { - this.thuhrOffset = thuhrOffset; - } + /** + * Copy constructor + * @param orig method to copy from + */ + public CustomMethod(Method orig) { + this.fajrAng = orig.getFajrAng(); + this.ishaaAng = orig.getIshaaAng(); + this.imsaakAng = orig.getImsaakAng(); + this.fajrInv = orig.getFajrInv(); + this.ishaaInv = orig.getIshaaInv(); + this.imsaakInv = orig.getImsaakInv(); + this.round = orig.getRound(); + this.mathhab = orig.getMathhab(); + this.nearestLat = orig.getNearestLat(); + this.extremeLatitude = orig.getExtremeLatitude(); + this.offset = orig.getOffset(); + + this.fajrOffset = orig.getFajrOffset(); + this.shurooqOffset = orig.getShurooqOffset(); + this.thuhrOffset = orig.getThuhrOffset(); + this.assrOffset = orig.getAssrOffset(); + this.maghribOffset = orig.getMaghribOffset(); + this.ishaaOffset = orig.getIshaaOffset(); + } + + public void setAssrOffset(double assrOffset) { + this.assrOffset = assrOffset; + } + + /** + * + * @param extreme Extreme latitude calculation method + * @see ExtremeLatitude + */ + public void setExtremeLatitude(ExtremeLatitude extreme) { + this.extremeLatitude = extreme; + } + + public void setFajrAng(double fajrAng) { + this.fajrAng = fajrAng; + } + + /** + * + * @param fajrInv Fajr Interval is the amount of minutes between Fajr and + * Shurooq (0 if not used) + */ + public void setFajrInv(int fajrInv) { + this.fajrInv = fajrInv; + } + + public void setFajrOffset(double fajrOffset) { + this.fajrOffset = fajrOffset; + } + + /** + * + * @param imsaakAng The angle difference between Imsaak and Fajr (default + * is 1.5) + */ + public void setImsaakAng(double imsaakAng) { + this.imsaakAng = imsaakAng; + } + + /** + * + * @param imsaakInv Imsaak Interval is the amount of minutes between Imsaak + * and Fajr. The default is 10 minutes before Fajr if Fajr Interval is set + */ + public void setImsaakInv(int imsaakInv) { + this.imsaakInv = imsaakInv; + } + + public void setIshaaAng(double ishaaAng) { + this.ishaaAng = ishaaAng; + } + + /** + * + * @param ishaaInv Ishaa Interval is the amount if minutes between Ishaa and + * Maghrib (0 if not used) + */ + public void setIshaaInv(int ishaaInv) { + this.ishaaInv = ishaaInv; + } + + public void setIshaaOffset(double ishaaOffset) { + this.ishaaOffset = ishaaOffset; + } + + public void setMaghribOffset(double maghribOffset) { + this.maghribOffset = maghribOffset; + } + + /** + * + * @param mathhab mathhab for calculating assr prayer shadow ratio + * @see Madhhab + */ + public void setMathhab(Madhhab mathhab) { + this.mathhab = mathhab; + } + + /** + * + * @param nearestLat Latitude Used for the 'Nearest Latitude' extreme + * methods. The default is 48.5 + */ + public void setNearestLat(double nearestLat) { + this.nearestLat = nearestLat; + } + + /** + * + * @param offset Enable Offsets switch (set this to true to activate). This + * option allows you to add or subtract any amount of minutes to the daily + * computed prayer times based on values (in minutes) for each prayer in + * the next xxxOffset parameters + * For Example: If you want to add 30 seconds to Maghrib and subtract 2 + * minutes from Ishaa: + * method.setOffset(true); + * method.setMaghribOffset(0.5); + * method.setIshaaOffset(-2); + */ + public void setOffset(boolean offset) { + this.offset = offset; + } + + /** + * + * @param round Method used for rounding seconds + * @see Rounding + */ + public void setRound(Rounding round) { + this.round = round; + } + + public void setShurooqOffset(double shurooqOffset) { + this.shurooqOffset = shurooqOffset; + } + + public void setThuhrOffset(double thuhrOffset) { + this.thuhrOffset = thuhrOffset; + } } diff --git a/src/org/arabeyes/itl/prayer/Method.java b/src/org/arabeyes/itl/prayer/Method.java index 488305a..7a4d644 100644 --- a/src/org/arabeyes/itl/prayer/Method.java +++ b/src/org/arabeyes/itl/prayer/Method.java @@ -4,206 +4,206 @@ import org.arabeyes.itl.prayer.astro.Utils; public class Method { - - /** - * At certain locations and times of year, some prayer times do not occur - * or otherwise are impossible to precisely calculate using conventional - * means. These methods generally apply to locations with High latitudes - * (near or above 49 degrees) or locations of Extreme proportion (near or - * above 66 degrees). - *

- * Method Category Information:

    - * - *
  • Nearest Latitude (Aqrab Al-Bilaad): Calculate a prayer time - * using a safe latitude value. The recommended latitude by - * many schools of Fiqh is 48.5 degrees, but you can customize - * this by setting the "Method.setNearestLat()" method. - *
  • - *
  • Nearest Good Day (Aqrab Al-Ayyam): The library determines - * the closest previous or next day that the Fajr and Ishaa - * times occur and are both valid. - *
  • - *
  • An [amount] of Night and Day: Unlike the above mentioned - * methods, the multiple methods in this category have no proof - * in traditional Shari'a (Fiqh) resources. These methods were - * introduced by modern day Muslim scholars and scientists for - * practical reasons only. - *
  • - *
  • Minutes from Shurooq/Maghrib: Use an interval time to - * calculate Fajr and Ishaa. This will set the values of Fajr - * and Ishaa to the same as the computed Shurooq and Maghrib - * respectively, then add or subtract the amount of minutes - * found in the "Method.getFajrInv" and "Method.getIshaaInv" - * methods. - *
  • - *
- */ - public static enum ExtremeLatitude { - - /** - * None. If unable to calculate, leave only the invalid prayer - * time as 99:99. - */ - NONE_EX, - - /** - * Nearest Latitude: Apply to all prayer times always. - */ - LAT_ALL, - - /** - * Nearest Latitude: Apply to Fajr and Ishaa times always. - */ - LAT_ALWAYS, - - /** - * Nearest Latitude: Apply to Fajr and Ishaa times but only if - * the library has detected that the current - * Fajr or Ishaa time is invalid. - */ - LAT_INVALID, - - /** - * Nearest Good Day: Apply to all prayer times always. - */ - GOOD_ALL, - - /** - * Nearest Good Day: Apply to Fajr and Ishaa times but only if - * the library has detected that the current - * Fajr or Ishaa time is invalid. This is the - * default method. (Default) - */ - GOOD_INVALID, - - /** - * 1/7th of Night: Apply to Fajr and Ishaa times always. - */ - SEVEN_NIGHT_ALWAYS, + + /** + * At certain locations and times of year, some prayer times do not occur + * or otherwise are impossible to precisely calculate using conventional + * means. These methods generally apply to locations with High latitudes + * (near or above 49 degrees) or locations of Extreme proportion (near or + * above 66 degrees). + *

+ * Method Category Information:

    + * + *
  • Nearest Latitude (Aqrab Al-Bilaad): Calculate a prayer time + * using a safe latitude value. The recommended latitude by + * many schools of Fiqh is 48.5 degrees, but you can customize + * this by setting the "Method.setNearestLat()" method. + *
  • + *
  • Nearest Good Day (Aqrab Al-Ayyam): The library determines + * the closest previous or next day that the Fajr and Ishaa + * times occur and are both valid. + *
  • + *
  • An [amount] of Night and Day: Unlike the above mentioned + * methods, the multiple methods in this category have no proof + * in traditional Shari'a (Fiqh) resources. These methods were + * introduced by modern day Muslim scholars and scientists for + * practical reasons only. + *
  • + *
  • Minutes from Shurooq/Maghrib: Use an interval time to + * calculate Fajr and Ishaa. This will set the values of Fajr + * and Ishaa to the same as the computed Shurooq and Maghrib + * respectively, then add or subtract the amount of minutes + * found in the "Method.getFajrInv" and "Method.getIshaaInv" + * methods. + *
  • + *
+ */ + public static enum ExtremeLatitude { + + /** + * None. If unable to calculate, leave only the invalid prayer + * time as 99:99. + */ + NONE_EX, + + /** + * Nearest Latitude: Apply to all prayer times always. + */ + LAT_ALL, + + /** + * Nearest Latitude: Apply to Fajr and Ishaa times always. + */ + LAT_ALWAYS, + + /** + * Nearest Latitude: Apply to Fajr and Ishaa times but only if + * the library has detected that the current + * Fajr or Ishaa time is invalid. + */ + LAT_INVALID, + + /** + * Nearest Good Day: Apply to all prayer times always. + */ + GOOD_ALL, + + /** + * Nearest Good Day: Apply to Fajr and Ishaa times but only if + * the library has detected that the current + * Fajr or Ishaa time is invalid. This is the + * default method. (Default) + */ + GOOD_INVALID, + + /** + * 1/7th of Night: Apply to Fajr and Ishaa times always. + */ + SEVEN_NIGHT_ALWAYS, - /** - * 1/7th of Night: Apply to Fajr and Ishaa times but only if - * the library has detected that the current - * Fajr or Ishaa time is invalid. - * - */ - SEVEN_NIGHT_INVALID, - - /** - * 1/7th of Day: Apply to Fajr and Ishaa times always. - */ - SEVEN_DAY_ALWAYS, - - /** - * 1/7th of Day: Apply to Fajr and Ishaa times but only if the - * library has detected that the current Fajr - * or Ishaa time is invalid. - */ - SEVEN_DAY_INVALID, - - /** - * Half of the Night: Apply to Fajr and Ishaa times always. - */ - HALF_ALWAYS, - - /** - * Half of the Night: Apply to Fajr and Ishaa times but only - * if the library has detected that the - * current Fajr or Ishaa time is - * invalid. - */ - HALF_INVALID, - - /** - * Minutes from Shorooq/Maghrib: Apply to Fajr and Ishaa times always. - */ - MIN_ALWAYS, + /** + * 1/7th of Night: Apply to Fajr and Ishaa times but only if + * the library has detected that the current + * Fajr or Ishaa time is invalid. + * + */ + SEVEN_NIGHT_INVALID, + + /** + * 1/7th of Day: Apply to Fajr and Ishaa times always. + */ + SEVEN_DAY_ALWAYS, + + /** + * 1/7th of Day: Apply to Fajr and Ishaa times but only if the + * library has detected that the current Fajr + * or Ishaa time is invalid. + */ + SEVEN_DAY_INVALID, + + /** + * Half of the Night: Apply to Fajr and Ishaa times always. + */ + HALF_ALWAYS, + + /** + * Half of the Night: Apply to Fajr and Ishaa times but only + * if the library has detected that the + * current Fajr or Ishaa time is + * invalid. + */ + HALF_INVALID, + + /** + * Minutes from Shorooq/Maghrib: Apply to Fajr and Ishaa times always. + */ + MIN_ALWAYS, - /** - * Minutes from Shorooq/Maghrib: Apply to Fajr and Ishaa times but only if - * the library has detected that the - * current Fajr or Ishaa time is invalid. - * - */ - MIN_INVALID, - - /** - * Nearest Good Day: Different good days for Fajr and Ishaa (Not - * implemented) - */ - GOOD_DIF + /** + * Minutes from Shorooq/Maghrib: Apply to Fajr and Ishaa times but only if + * the library has detected that the + * current Fajr or Ishaa time is invalid. + * + */ + MIN_INVALID, + + /** + * Nearest Good Day: Different good days for Fajr and Ishaa (Not + * implemented) + */ + GOOD_DIF - } - - /** - * Madhhab is used for Asr prayer calculation. - */ - public static enum Madhhab { + } + + /** + * Madhhab is used for Asr prayer calculation. + */ + public static enum Madhhab { - /** - * Assr prayer shadow ratio: use Shaa'fi mathhab (default) - */ - SHAFII, - - /** - * Assr prayer shadow ratio: use Hanafi mathhab - */ - HANAFI + /** + * Assr prayer shadow ratio: use Shaa'fi mathhab (default) + */ + SHAFII, + + /** + * Assr prayer shadow ratio: use Hanafi mathhab + */ + HANAFI - } - - /** - * This class is used to round prayer times (seconds). - */ - public static enum Rounding { - - /** - * No Rounding. second is set to the amount of computed seconds. - */ - NONE, - - /** - * Normal Rounding. If seconds are equal to 30 or above, add 1 minute. Sets "Prayer.seconds" to zero. - */ - NORMAL, - - /** - * Special Rounding. Similar to normal rounding but we always round down for Shurooq and Imsaak times. (default) - */ - SPECIAL, - - /** - * Aggressive Rounding. Similar to Special Rounding but we add 1 minute if the seconds value are equal to 1 second or more. - */ - AGRESSIVE + } + + /** + * This class is used to round prayer times (seconds). + */ + public static enum Rounding { + + /** + * No Rounding. second is set to the amount of computed seconds. + */ + NONE, + + /** + * Normal Rounding. If seconds are equal to 30 or above, add 1 minute. Sets "Prayer.seconds" to zero. + */ + NORMAL, + + /** + * Special Rounding. Similar to normal rounding but we always round down for Shurooq and Imsaak times. (default) + */ + SPECIAL, + + /** + * Aggressive Rounding. Similar to Special Rounding but we add 1 minute if the seconds value are equal to 1 second or more. + */ + AGRESSIVE - } - - // End of inner classes - - protected double fajrAng; - protected double ishaaAng; - protected double imsaakAng; - protected int fajrInv; - protected int ishaaInv; - protected int imsaakInv; - protected Rounding round; - protected Madhhab mathhab; - protected double nearestLat; - protected ExtremeLatitude extremeLatitude; - protected boolean offset; - protected double fajrOffset; - protected double shurooqOffset; - protected double thuhrOffset; - protected double assrOffset; - protected double maghribOffset; - protected double ishaaOffset; - - public static final Method NONE = new Method(0.0, 0.0, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, Rounding.SPECIAL, Madhhab.SHAFII, - Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - /** - * Egyptian General Authority of Survey
+ } + + // End of inner classes + + protected double fajrAng; + protected double ishaaAng; + protected double imsaakAng; + protected int fajrInv; + protected int ishaaInv; + protected int imsaakInv; + protected Rounding round; + protected Madhhab mathhab; + protected double nearestLat; + protected ExtremeLatitude extremeLatitude; + protected boolean offset; + protected double fajrOffset; + protected double shurooqOffset; + protected double thuhrOffset; + protected double assrOffset; + protected double maghribOffset; + protected double ishaaOffset; + + public static final Method NONE = new Method(0.0, 0.0, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, Rounding.SPECIAL, Madhhab.SHAFII, + Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + /** + * Egyptian General Authority of Survey
*
    *
  • Fajr Angle = 20
  • *
  • Ishaa Angle = 18
  • @@ -211,225 +211,225 @@ public static enum Rounding { * Indonesia, Iraq, Jordan, Lebanon, Malaysia, Singapore, Syria, parts of Africa, * parts of United States *
- */ - public static final Method EGYPT_SURVEY = new Method(20, 18, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, Rounding.SPECIAL, - Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - /** + */ + public static final Method EGYPT_SURVEY = new Method(20, 18, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, Rounding.SPECIAL, + Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + /** * University of Islamic Sciences, Karachi (Shaf'i)
*
  • Fajr Angle = 18
  • *
  • Ishaa Angle = 18
  • *
  • Used in: Iran, Kuwait, parts of Europe *
*/ - public static final Method KARACHI_SHAF = new Method(18, 18, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, Rounding.SPECIAL, - Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - /** - * University of Islamic Sciences, Karachi (Hanafi)
+ public static final Method KARACHI_SHAF = new Method(18, 18, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, Rounding.SPECIAL, + Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + /** + * University of Islamic Sciences, Karachi (Hanafi)
*
  • Fajr Angle = 18
  • *
  • Ishaa Angle = 18
  • *
  • Used in: Afghanistan, Bangladesh, India
  • *
- */ - public static final Method KARACHI_HANAF = new Method(18, 18, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, - Rounding.SPECIAL, Madhhab.HANAFI, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - /** - * Islamic Society of North America
+ */ + public static final Method KARACHI_HANAF = new Method(18, 18, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, + Rounding.SPECIAL, Madhhab.HANAFI, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + /** + * Islamic Society of North America
*
  • Fajr Angle = 15
  • *
  • Ishaa Angle = 15
  • *
  • Used in: Canada, Parts of UK, parts of United States
  • *
- */ - public static final Method NORTH_AMERICA = new Method(15, 15, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, - Rounding.SPECIAL, Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - /** - * Muslim World League (MWL)
+ */ + public static final Method NORTH_AMERICA = new Method(15, 15, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, + Rounding.SPECIAL, Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + /** + * Muslim World League (MWL)
*
  • Fajr Angle = 18
  • *
  • Ishaa Angle = 17
  • *
  • Used in: parts of Europe, Far East, parts of United States
  • *
* - */ - public static final Method MUSLIM_LEAGUE = new Method(18, 17, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, - Rounding.SPECIAL, Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - /** - * Om Al-Qurra University
+ */ + public static final Method MUSLIM_LEAGUE = new Method(18, 17, Utils.DEF_IMSAAK_ANGLE, 0, 0, 0, + Rounding.SPECIAL, Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + /** + * Om Al-Qurra University
*
  • Fajr Angle = 19
  • *
  • Ishaa Angle = 0 (not used)
  • *
  • Ishaa Interval = 90 minutes from Al-Maghrib prayer * but set to 120 during Ramadan.
  • *
  • Used in: Saudi Arabia
  • *
- */ - public static final Method UMM_ALQURRA = new Method(19, 0, Utils.DEF_IMSAAK_ANGLE, 0, 90, 0, Rounding.SPECIAL, - Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - /** - * Fixed Ishaa Angle Interval (always 90)
+ */ + public static final Method UMM_ALQURRA = new Method(19, 0, Utils.DEF_IMSAAK_ANGLE, 0, 90, 0, Rounding.SPECIAL, + Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + /** + * Fixed Ishaa Angle Interval (always 90)
*
  • Fajr Angle = 19.5
  • *
  • Ishaa Angle = 0 (not used)
  • *
  • Ishaa Interval = 90 minutes from Al-Maghrib prayer.
  • *
  • Used in: Bahrain, Oman, Qatar, United Arab Emirates
  • *
- */ - public static final Method FIXED_ISHAA = new Method(19.5, 0, Utils.DEF_IMSAAK_ANGLE, 0, 90, 0, - Rounding.SPECIAL, Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); - - protected Method() { - } - - /** - * Build a method object containing all the information needed to compute - * prayer time. - * - * @param fajrAng Fajr angle - * @param ishaaAng Ishaa angle - * @param imsaakAng The angle difference between Imsaak and Fajr (default - * is 1.5) - * @param fajrInv Fajr Interval is the amount of minutes between Fajr and - * Shurooq (0 if not used) - * @param ishaaInv Ishaa Interval is the amount if minutes between Ishaa and - * Maghrib (0 if not used) - * @param imsaakInv Imsaak Interval is the amount of minutes between Imsaak - * and Fajr. The default is 10 minutes before Fajr if Fajr Interval is set - * @param round Method used for rounding seconds - * @param mathhab mathhab for calculating assr prayer shadow ratio - * @param nearestLat Latitude Used for the 'Nearest Latitude' extreme - * methods. The default is 48.5 - * @param extreme Extreme latitude calculation method (@see ExtremeLatitude) - * @param offset Enable Offsets switch (set this to true to activate). This - * option allows you to add or subtract any amount of minutes to the daily - * computed prayer times based on values (in minutes) for each prayer in - * the next xxxOffset parameters - * For Example: If you want to add 30 seconds to Maghrib and subtract 2 - * minutes from Ishaa:
- * method.setOffset(true); - * method.setMaghribOffset(0.5); - * method.setIshaaOffset(-2); - * @param fajrOffset fajr offset - * @param shurooqOffset shurooq offset - * @param thuhrOffset thuhr offset - * @param assrOffset assr offset - * @param maghribOffset maghrib offset - * @param ishaaOffset ishaa offset - */ - public Method(double fajrAng, double ishaaAng, double imsaakAng, - int fajrInv, int ishaaInv, int imsaakInv, Rounding round, Madhhab mathhab, - double nearestLat, ExtremeLatitude extreme, boolean offset, double fajrOffset, - double shurooqOffset, double thuhrOffset, double assrOffset, - double maghribOffset, double ishaaOffset) { - this.fajrAng = fajrAng; - this.ishaaAng = ishaaAng; - this.imsaakAng = imsaakAng; - this.fajrInv = fajrInv; - this.ishaaInv = ishaaInv; - this.imsaakInv = imsaakInv; - this.round = round; - this.mathhab = mathhab; - this.nearestLat = nearestLat; - this.extremeLatitude = extreme; - this.offset = offset; - - this.fajrOffset = fajrOffset; - this.shurooqOffset = shurooqOffset; - this.thuhrOffset = thuhrOffset; - this.assrOffset = assrOffset; - this.maghribOffset = maghribOffset; - this.ishaaOffset = ishaaOffset; - - } - - public double getAssrOffset() { - return assrOffset; - } - - public ExtremeLatitude getExtremeLatitude() { - return extremeLatitude; - } - - public double getFajrAng() { - return fajrAng; - } - - public int getFajrInv() { - return fajrInv; - } - - public double getFajrOffset() { - return fajrOffset; - } - - public double getImsaakAng() { - return imsaakAng; - } - - public int getImsaakInv() { - return imsaakInv; - } - - public double getIshaaAng() { - return ishaaAng; - } - - public int getIshaaInv() { - return ishaaInv; - } - - public double getIshaaOffset() { - return ishaaOffset; - } - - public double getMaghribOffset() { - return maghribOffset; - } - - public Madhhab getMathhab() { - return mathhab; - } - - public double getNearestLat() { - return nearestLat; - } - - public boolean getOffset() { - return offset; - } - - /* - fajrAng, ishaaAng, imsaakAng, fajrInv = 0, ishaaInv = 0, imsaakInv = 0, round = 2, mathhab = 1, - nearestLat = Utils.DEF_NEAREST_LATITUDE , extreme = 5, offset = 0, offList = null - */ - - public double getOffset(InternalTimeType prayer) { - if (prayer == InternalTimeType.FAJR) - return getFajrOffset(); - if (prayer == InternalTimeType.SUNRISE) - return getShurooqOffset(); - if (prayer == InternalTimeType.ZUHR) - return getThuhrOffset(); - if (prayer == InternalTimeType.ASR) - return getAssrOffset(); - if (prayer == InternalTimeType.MAGHRIB) - return getMaghribOffset(); - if (prayer == InternalTimeType.ISHA) - return getIshaaOffset(); - return 0; - } - - public Rounding getRound() { - return round; - } - + */ + public static final Method FIXED_ISHAA = new Method(19.5, 0, Utils.DEF_IMSAAK_ANGLE, 0, 90, 0, + Rounding.SPECIAL, Madhhab.SHAFII, Utils.DEF_NEAREST_LATITUDE, ExtremeLatitude.GOOD_INVALID, false, 0, 0, 0, 0, 0, 0); + + protected Method() { + } + + /** + * Build a method object containing all the information needed to compute + * prayer time. + * + * @param fajrAng Fajr angle + * @param ishaaAng Ishaa angle + * @param imsaakAng The angle difference between Imsaak and Fajr (default + * is 1.5) + * @param fajrInv Fajr Interval is the amount of minutes between Fajr and + * Shurooq (0 if not used) + * @param ishaaInv Ishaa Interval is the amount if minutes between Ishaa and + * Maghrib (0 if not used) + * @param imsaakInv Imsaak Interval is the amount of minutes between Imsaak + * and Fajr. The default is 10 minutes before Fajr if Fajr Interval is set + * @param round Method used for rounding seconds + * @param mathhab mathhab for calculating assr prayer shadow ratio + * @param nearestLat Latitude Used for the 'Nearest Latitude' extreme + * methods. The default is 48.5 + * @param extreme Extreme latitude calculation method (@see ExtremeLatitude) + * @param offset Enable Offsets switch (set this to true to activate). This + * option allows you to add or subtract any amount of minutes to the daily + * computed prayer times based on values (in minutes) for each prayer in + * the next xxxOffset parameters + * For Example: If you want to add 30 seconds to Maghrib and subtract 2 + * minutes from Ishaa:
+ * method.setOffset(true); + * method.setMaghribOffset(0.5); + * method.setIshaaOffset(-2); + * @param fajrOffset fajr offset + * @param shurooqOffset shurooq offset + * @param thuhrOffset thuhr offset + * @param assrOffset assr offset + * @param maghribOffset maghrib offset + * @param ishaaOffset ishaa offset + */ + public Method(double fajrAng, double ishaaAng, double imsaakAng, + int fajrInv, int ishaaInv, int imsaakInv, Rounding round, Madhhab mathhab, + double nearestLat, ExtremeLatitude extreme, boolean offset, double fajrOffset, + double shurooqOffset, double thuhrOffset, double assrOffset, + double maghribOffset, double ishaaOffset) { + this.fajrAng = fajrAng; + this.ishaaAng = ishaaAng; + this.imsaakAng = imsaakAng; + this.fajrInv = fajrInv; + this.ishaaInv = ishaaInv; + this.imsaakInv = imsaakInv; + this.round = round; + this.mathhab = mathhab; + this.nearestLat = nearestLat; + this.extremeLatitude = extreme; + this.offset = offset; + + this.fajrOffset = fajrOffset; + this.shurooqOffset = shurooqOffset; + this.thuhrOffset = thuhrOffset; + this.assrOffset = assrOffset; + this.maghribOffset = maghribOffset; + this.ishaaOffset = ishaaOffset; + + } + + public double getAssrOffset() { + return assrOffset; + } + + public ExtremeLatitude getExtremeLatitude() { + return extremeLatitude; + } + + public double getFajrAng() { + return fajrAng; + } + + public int getFajrInv() { + return fajrInv; + } + + public double getFajrOffset() { + return fajrOffset; + } + + public double getImsaakAng() { + return imsaakAng; + } + + public int getImsaakInv() { + return imsaakInv; + } + + public double getIshaaAng() { + return ishaaAng; + } + + public int getIshaaInv() { + return ishaaInv; + } + + public double getIshaaOffset() { + return ishaaOffset; + } + + public double getMaghribOffset() { + return maghribOffset; + } + + public Madhhab getMathhab() { + return mathhab; + } + + public double getNearestLat() { + return nearestLat; + } + + public boolean getOffset() { + return offset; + } + + /* + fajrAng, ishaaAng, imsaakAng, fajrInv = 0, ishaaInv = 0, imsaakInv = 0, round = 2, mathhab = 1, + nearestLat = Utils.DEF_NEAREST_LATITUDE , extreme = 5, offset = 0, offList = null + */ + + public double getOffset(InternalTimeType prayer) { + if (prayer == InternalTimeType.FAJR) + return getFajrOffset(); + if (prayer == InternalTimeType.SUNRISE) + return getShurooqOffset(); + if (prayer == InternalTimeType.ZUHR) + return getThuhrOffset(); + if (prayer == InternalTimeType.ASR) + return getAssrOffset(); + if (prayer == InternalTimeType.MAGHRIB) + return getMaghribOffset(); + if (prayer == InternalTimeType.ISHA) + return getIshaaOffset(); + return 0; + } + + public Rounding getRound() { + return round; + } + public double getShurooqOffset() { - return shurooqOffset; - } - - public double getThuhrOffset() { - return thuhrOffset; - } - + return shurooqOffset; + } + + public double getThuhrOffset() { + return thuhrOffset; + } + } diff --git a/src/org/arabeyes/itl/prayer/PrayerTime.java b/src/org/arabeyes/itl/prayer/PrayerTime.java index 69979ce..969b876 100644 --- a/src/org/arabeyes/itl/prayer/PrayerTime.java +++ b/src/org/arabeyes/itl/prayer/PrayerTime.java @@ -4,69 +4,69 @@ * This class encapsulates prayer times. */ public class PrayerTime { - - private int hour; /* prayer time hour */ - private int minute; /* prayer time minute */ - private int second; /* prayer time second */ - private boolean extreme; /* */ - - public PrayerTime() { - } - - public PrayerTime(int hour, int minute, int second, boolean extreme) { - this.hour = hour; - this.minute = minute; - this.second = second; - this.extreme = extreme; - } - - public PrayerTime(PrayerTime src) { - this.hour = src.hour; - this.minute = src.minute; - this.second = src.second; - this.extreme = src.extreme; - } - - public int getHour() { - return hour; - } - - public void setHour(int hour) { - this.hour = hour; - } - - /** - * @return Extreme calculation switch. The 'getPrayerTimes' - * function sets this switch to true to indicate that this - * particular prayer time has been calculated through - * extreme latitude methods and NOT by conventional - * means of calculation. - */ - public boolean isExtreme() { - return extreme; - } - - public void setExtreme(boolean extreme) { - this.extreme = extreme; - } - - public int getMinute() { - return minute; - } - - public void setMinute(int minute) { - this.minute = minute; - } - - public int getSecond() { - return second; - } - - public void setSecond(int second) { - this.second = second; - } - - public String toString() { - return hour + ":" + (minute < 10 ? "0" + minute : minute + "") + ":" + (second < 10 ? "0" + second : second + ""); - } + + private int hour; /* prayer time hour */ + private int minute; /* prayer time minute */ + private int second; /* prayer time second */ + private boolean extreme; /* */ + + public PrayerTime() { + } + + public PrayerTime(int hour, int minute, int second, boolean extreme) { + this.hour = hour; + this.minute = minute; + this.second = second; + this.extreme = extreme; + } + + public PrayerTime(PrayerTime src) { + this.hour = src.hour; + this.minute = src.minute; + this.second = src.second; + this.extreme = src.extreme; + } + + public int getHour() { + return hour; + } + + public void setHour(int hour) { + this.hour = hour; + } + + /** + * @return Extreme calculation switch. The 'getPrayerTimes' + * function sets this switch to true to indicate that this + * particular prayer time has been calculated through + * extreme latitude methods and NOT by conventional + * means of calculation. + */ + public boolean isExtreme() { + return extreme; + } + + public void setExtreme(boolean extreme) { + this.extreme = extreme; + } + + public int getMinute() { + return minute; + } + + public void setMinute(int minute) { + this.minute = minute; + } + + public int getSecond() { + return second; + } + + public void setSecond(int second) { + this.second = second; + } + + public String toString() { + return hour + ":" + (minute < 10 ? "0" + minute : minute + "") + ":" + (second < 10 ? "0" + second : second + ""); + } } diff --git a/src/org/arabeyes/itl/prayer/PrayerTimeCalc.java b/src/org/arabeyes/itl/prayer/PrayerTimeCalc.java index f76d096..5777799 100644 --- a/src/org/arabeyes/itl/prayer/PrayerTimeCalc.java +++ b/src/org/arabeyes/itl/prayer/PrayerTimeCalc.java @@ -21,700 +21,700 @@ */ public class PrayerTimeCalc { - /** - * This class is an enumeration of possible prayer and other - * useful events, i.e. sunrise and imsak (minutes before fajr - * to get ready for saum/fasting). - */ - static enum InternalTimeType { - FAJR, SUNRISE, ZUHR, ASR, MAGHRIB, ISHA, - IMSAK, NEXT_FAJR; - } - - private static class DayCouple { - - private int lastDay; - private double julianDay; + /** + * This class is an enumeration of possible prayer and other + * useful events, i.e. sunrise and imsak (minutes before fajr + * to get ready for saum/fasting). + */ + static enum InternalTimeType { + FAJR, SUNRISE, ZUHR, ASR, MAGHRIB, ISHA, + IMSAK, NEXT_FAJR; + } + + private static class DayCouple { + + private int lastDay; + private double julianDay; - public DayCouple(int lastDay, double julianDay) { - this.lastDay = lastDay; - this.julianDay = julianDay; - } - } - - // End of inner class - - /* This is Used for storing some formulae results between - * multiple getPrayerTimes calls */ - private Astro astroCache = new Astro(); - - private Location loc; - - private Method method; - - /** - * Creates the jitl main class - * @param loc the location - * @param method the method used in the calculation. You can use - * predefined methods for example Method.MUSLIM_LEAGUE or creates - * your own personalized method. - */ - public PrayerTimeCalc(Location loc, Method method) { - this.loc = loc; - this.method = method; - } - - /** - * changes the location - * @param loc the new location - */ - public void setLocation(Location loc) { - this.loc = loc; - } - - /** - * changes the method - * @param method the new method - */ - public void setMethod(Method method) { - this.method = method; - } - - /** - * Create a DayPrayers instance and fill it with prayer times - * @param date hour, minute, and second are ignored - * @return prayer times - */ - public PrayerTimes getPrayerTimes(Date date) { - PrayerTimes dp = new PrayerTimes(); - getPrayerTimes(date, dp); - - return dp; - } - - /** - * Generate prayer times from a SimpleDate date - * @param date hour, minute, and second are ignored - * @param pt object to be filled - */ - public void getPrayerTimes(Date date, PrayerTimes pt) { - DayCouple dc; - - dc = getDayInfo(date, loc.getGmtDiff()); - getPrayerTimesByDay(dc, pt, InternalTimeType.FAJR); - } - - /** - * Generate imsaak time - * @param date SimpleDate date - * @return imsaak time - */ - public PrayerTime getImsak(Date date) { - - CustomMethod tmpConf; - DayCouple dc; - PrayerTimes temp = new PrayerTimes(); - - tmpConf = new CustomMethod(method); - - if (method.getFajrInv() != 0) { - if (method.getImsaakInv() == 0) - tmpConf - .setFajrInv((int) (tmpConf.getFajrInv() + Utils.DEF_IMSAAK_INTERVAL)); - else - tmpConf.setFajrInv((int) (tmpConf.getFajrInv() + method - .getImsaakInv())); - - } else if (method.getImsaakInv() != 0) { - /* use an inv even if al-Fajr is computed (Indonesia?) */ - tmpConf.setFajrOffset(tmpConf.getFajrOffset() - + (method.getImsaakInv() * -1)); - tmpConf.setOffset(true); - } else { - tmpConf.setFajrAng(tmpConf.getFajrAng() + method.getImsaakAng()); - } - - dc = getDayInfo(date, loc.getGmtDiff()); - getPrayerTimesByDay(tmpConf, dc, temp, InternalTimeType.IMSAK); - - /* xxxthamer: We probably need to check whether it's possible to compute - * Imsaak normally for some extreme methods first */ - /* In case of an extreme Fajr time calculation use intervals for Imsaak and - * compute again */ - if (temp.fajr().isExtreme()) { - tmpConf = new CustomMethod(method); - if (method.getImsaakInv() == 0) { - tmpConf.setFajrOffset(tmpConf.getFajrOffset() - - Utils.DEF_IMSAAK_INTERVAL); - tmpConf.setOffset(true); - } else { - tmpConf.setFajrOffset(tmpConf.getFajrOffset() - - method.getImsaakInv()); - tmpConf.setOffset(true); - } - getPrayerTimesByDay(tmpConf, dc, temp, InternalTimeType.IMSAK); - } - - return temp.fajr(); - } - - /* Obtaining the direction of the shortest distance towards Qibla by uMath.sing the - * great circle formula */ - - /** - * Calculate qibla direction. - * @return a Dms object containing qibla direction for the current location - */ - public Dms getNorthQibla() { - return getNorthQibla(loc); - } + public DayCouple(int lastDay, double julianDay) { + this.lastDay = lastDay; + this.julianDay = julianDay; + } + } + + // End of inner class + + /* This is Used for storing some formulae results between + * multiple getPrayerTimes calls */ + private Astro astroCache = new Astro(); + + private Location loc; + + private Method method; + + /** + * Creates the jitl main class + * @param loc the location + * @param method the method used in the calculation. You can use + * predefined methods for example Method.MUSLIM_LEAGUE or creates + * your own personalized method. + */ + public PrayerTimeCalc(Location loc, Method method) { + this.loc = loc; + this.method = method; + } + + /** + * changes the location + * @param loc the new location + */ + public void setLocation(Location loc) { + this.loc = loc; + } + + /** + * changes the method + * @param method the new method + */ + public void setMethod(Method method) { + this.method = method; + } + + /** + * Create a DayPrayers instance and fill it with prayer times + * @param date hour, minute, and second are ignored + * @return prayer times + */ + public PrayerTimes getPrayerTimes(Date date) { + PrayerTimes dp = new PrayerTimes(); + getPrayerTimes(date, dp); + + return dp; + } + + /** + * Generate prayer times from a SimpleDate date + * @param date hour, minute, and second are ignored + * @param pt object to be filled + */ + public void getPrayerTimes(Date date, PrayerTimes pt) { + DayCouple dc; + + dc = getDayInfo(date, loc.getGmtDiff()); + getPrayerTimesByDay(dc, pt, InternalTimeType.FAJR); + } + + /** + * Generate imsaak time + * @param date SimpleDate date + * @return imsaak time + */ + public PrayerTime getImsak(Date date) { + + CustomMethod tmpConf; + DayCouple dc; + PrayerTimes temp = new PrayerTimes(); + + tmpConf = new CustomMethod(method); + + if (method.getFajrInv() != 0) { + if (method.getImsaakInv() == 0) + tmpConf + .setFajrInv((int) (tmpConf.getFajrInv() + Utils.DEF_IMSAAK_INTERVAL)); + else + tmpConf.setFajrInv((int) (tmpConf.getFajrInv() + method + .getImsaakInv())); + + } else if (method.getImsaakInv() != 0) { + /* use an inv even if al-Fajr is computed (Indonesia?) */ + tmpConf.setFajrOffset(tmpConf.getFajrOffset() + + (method.getImsaakInv() * -1)); + tmpConf.setOffset(true); + } else { + tmpConf.setFajrAng(tmpConf.getFajrAng() + method.getImsaakAng()); + } + + dc = getDayInfo(date, loc.getGmtDiff()); + getPrayerTimesByDay(tmpConf, dc, temp, InternalTimeType.IMSAK); + + /* xxxthamer: We probably need to check whether it's possible to compute + * Imsaak normally for some extreme methods first */ + /* In case of an extreme Fajr time calculation use intervals for Imsaak and + * compute again */ + if (temp.fajr().isExtreme()) { + tmpConf = new CustomMethod(method); + if (method.getImsaakInv() == 0) { + tmpConf.setFajrOffset(tmpConf.getFajrOffset() + - Utils.DEF_IMSAAK_INTERVAL); + tmpConf.setOffset(true); + } else { + tmpConf.setFajrOffset(tmpConf.getFajrOffset() + - method.getImsaakInv()); + tmpConf.setOffset(true); + } + getPrayerTimesByDay(tmpConf, dc, temp, InternalTimeType.IMSAK); + } + + return temp.fajr(); + } + + /* Obtaining the direction of the shortest distance towards Qibla by uMath.sing the + * great circle formula */ + + /** + * Calculate qibla direction. + * @return a Dms object containing qibla direction for the current location + */ + public Dms getNorthQibla() { + return getNorthQibla(loc); + } - /* Obtaining the direction of the shortest distance towards Qibla by uMath.sing the - * great circle formula */ - - /** - * Calculate qibla direction. - * @param loc location where to calculate - * @return a Dms object containg qibla direction - */ - public static Dms getNorthQibla(Location loc) { - /* xxxthamer: reduce Utils.DEG_TO_RAD usage */ - double num, denom; - num = Math.sin(Utils.degToRad(loc.getDegreeLong()) - - Utils.degToRad(Utils.KAABA_LONG)); - denom = (Math.cos(Utils.degToRad(loc.getDegreeLat())) * Math - .tan(Utils.degToRad(Utils.KAABA_LAT))) - - (Math.sin(Utils.degToRad(loc.getDegreeLat())) * ((Math - .cos((Utils.degToRad(loc.getDegreeLong()) - Utils - .degToRad(Utils.KAABA_LONG)))))); - return new Dms(Utils.radToDeg(Math.atan2(num, denom))); - - } + /* Obtaining the direction of the shortest distance towards Qibla by uMath.sing the + * great circle formula */ + + /** + * Calculate qibla direction. + * @param loc location where to calculate + * @return a Dms object containg qibla direction + */ + public static Dms getNorthQibla(Location loc) { + /* xxxthamer: reduce Utils.DEG_TO_RAD usage */ + double num, denom; + num = Math.sin(Utils.degToRad(loc.getDegreeLong()) + - Utils.degToRad(Utils.KAABA_LONG)); + denom = (Math.cos(Utils.degToRad(loc.getDegreeLat())) * Math + .tan(Utils.degToRad(Utils.KAABA_LAT))) + - (Math.sin(Utils.degToRad(loc.getDegreeLat())) * ((Math + .cos((Utils.degToRad(loc.getDegreeLong()) - Utils + .degToRad(Utils.KAABA_LONG)))))); + return new Dms(Utils.radToDeg(Math.atan2(num, denom))); + + } - private void getPrayerTimesByDay(DayCouple dc, PrayerTimes pt, InternalTimeType type) { - getPrayerTimesByDay(method, dc, pt, type); - } + private void getPrayerTimesByDay(DayCouple dc, PrayerTimes pt, InternalTimeType type) { + getPrayerTimesByDay(method, dc, pt, type); + } - private void getPrayerTimesByDay(Method method, DayCouple dc, PrayerTimes pt, - InternalTimeType type) { - int i, invalid; - double th, sh, mg, fj, is, ar; - double lat, lon, dec; - double tempPrayer[] = new double[6]; - Astro tAstro = new Astro(); - - lat = loc.getDegreeLat(); - lon = loc.getDegreeLong(); - invalid = 0; - - /* Start by filling the tAstro structure with the appropriate astronomical - * values for this day. We also pass the cache structure to update and check - * if the actual values are already available. */ - AstroLib - .getAstroValuesByDay(dc.julianDay, loc, astroCache, tAstro); - dec = Utils.degToRad(tAstro.getDec()[1]); - - /* Get Prayer Times formulae results for this day of year and this - * location. The results are NOT the actual prayer times */ - fj = getFajIsh(lat, dec, method.getFajrAng()); - sh = getShoMag(loc, tAstro, InternalTimeType.SUNRISE); - th = getThuhr(lon, tAstro); - ar = getAssr(lat, dec, method.getMathhab()); - mg = getShoMag(loc, tAstro, InternalTimeType.MAGHRIB); - is = getFajIsh(lat, dec, method.getIshaaAng()); - - /* Calculate all prayer times as Base-10 numbers in Normal circumstances */ - /* Fajr */ - if (fj == 99) { - tempPrayer[0] = 99; - invalid = 1; - } else { - tempPrayer[0] = th - fj; - } - - if (sh == 99) { - invalid = 1; - } - - tempPrayer[1] = sh; - tempPrayer[2] = th; - tempPrayer[3] = th + ar; - tempPrayer[4] = mg; - - if (mg == 99) { - invalid = 1; - } - - /* Ishaa */ - if (is == 99) { - tempPrayer[5] = 99; - invalid = 1; - } else { - tempPrayer[5] = th + is; - } - - /* Calculate all prayer times as Base-10 numbers in Extreme Latitudes (if - * needed) */ - - /* Reset status of extreme switches */ - pt.setAllExtreme(false); - - if ((method.getExtremeLatitude() != ExtremeLatitude.NONE_EX) - && !((method.getExtremeLatitude() == ExtremeLatitude.GOOD_INVALID - || method.getExtremeLatitude() == ExtremeLatitude.LAT_INVALID - || method.getExtremeLatitude() == ExtremeLatitude.SEVEN_NIGHT_INVALID - || method.getExtremeLatitude() == ExtremeLatitude.SEVEN_DAY_INVALID || method - .getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) && (invalid == 0))) { - double exdecPrev, exdecNext; - double exTh = 99, exFj = 99, exIs = 99, exAr = 99, exSh = 99, exMg = 99; - //exIm=99 - - double portion = 0; - double nGoodDay = 0; - int exinterval = 0; - Location exLoc = new Location(loc); - Astro exAstroPrev; - Astro exAstroNext; - ExtremeLatitude ext = method.getExtremeLatitude(); - - /* Nearest Latitude (Method.nearestLat) */ - if(ext == ExtremeLatitude.LAT_ALL || ext == ExtremeLatitude.LAT_ALWAYS || ext == ExtremeLatitude.LAT_INVALID) { - /* - case LAT_ALL: - case LAT_ALWAYS: - case LAT_INVALID: - */ - - /* xxxthamer: we cannot compute this when interval is set because - * angle==0 . Only the if-invalid methods would work */ - exLoc.setDegreeLat(method.getNearestLat()); - exFj = getFajIsh(method.getNearestLat(), dec, method - .getFajrAng()); - //exIm = getFajIsh(method.getNearestLat(), dec, method.getImsaakAng()); - exIs = getFajIsh(method.getNearestLat(), dec, method - .getIshaaAng()); - exAr = getAssr(method.getNearestLat(), dec, method.getMathhab()); - exSh = getShoMag(exLoc, tAstro, InternalTimeType.SUNRISE); - exMg = getShoMag(exLoc, tAstro, InternalTimeType.MAGHRIB); - - //switch (ext) { - if(ext == ExtremeLatitude.LAT_ALL) { - //case LAT_ALL: - tempPrayer[0] = th - exFj; - tempPrayer[1] = exSh; - tempPrayer[3] = th + exAr; - tempPrayer[4] = exMg; - tempPrayer[5] = th + exIs; - pt.setAllExtreme(true); - } else if (ext == ExtremeLatitude.LAT_ALWAYS) { - tempPrayer[0] = th - exFj; - tempPrayer[5] = th + exIs; - pt.fajr().setExtreme(true); - pt.isha().setExtreme(true); - } else if (ext == ExtremeLatitude.LAT_INVALID) { - if (tempPrayer[0] == 99) { - tempPrayer[0] = th - exFj; - pt.fajr().setExtreme(true); - } - if (tempPrayer[5] == 99) { - tempPrayer[5] = th + exIs; - pt.isha().setExtreme(true); - } - } - - } else if (ext == ExtremeLatitude.GOOD_ALL || ext == ExtremeLatitude.GOOD_INVALID - || ext == ExtremeLatitude.GOOD_DIF) { - /* Nearest Good Day */ - exAstroPrev = astroCache; - exAstroNext = astroCache; - - /* Start by getting last or next nearest Good Day */ - for (i = 0; i <= dc.lastDay; i++) { - - /* last closest day */ - nGoodDay = dc.julianDay - i; - AstroLib.getAstroValuesByDay(nGoodDay, loc, exAstroPrev, - tAstro); - exdecPrev = Utils.degToRad(tAstro.getDec()[1]); - exFj = getFajIsh(lat, exdecPrev, method.getFajrAng()); - - if (exFj != 99) { - exIs = getFajIsh(lat, exdecPrev, method.getIshaaAng()); - if (exIs != 99) { - exTh = getThuhr(lon, tAstro); - exSh = getShoMag(loc, tAstro, InternalTimeType.SUNRISE); - exMg = getShoMag(loc, tAstro, InternalTimeType.MAGHRIB); - exAr = getAssr(lat, exdecPrev, method.getMathhab()); - break; - } - } - - /* Next closest day */ - nGoodDay = dc.julianDay + i; - AstroLib.getAstroValuesByDay(nGoodDay, loc, exAstroNext, - tAstro); - exdecNext = Utils.degToRad(tAstro.getDec()[1]); - exFj = getFajIsh(lat, exdecNext, method.getFajrAng()); - if (exFj != 99) { - exIs = getFajIsh(lat, exdecNext, method.getIshaaAng()); - if (exIs != 99) { - exTh = getThuhr(lon, tAstro); - exSh = getShoMag(loc, tAstro, InternalTimeType.SUNRISE); - exMg = getShoMag(loc, tAstro, InternalTimeType.MAGHRIB); - exAr = getAssr(lat, exdecNext, method.getMathhab()); - break; - } - } - } - - if(ext == ExtremeLatitude.GOOD_ALL) { - tempPrayer[0] = exTh - exFj; - tempPrayer[1] = exSh; - tempPrayer[2] = exTh; - tempPrayer[3] = exTh + exAr; - tempPrayer[4] = exMg; - tempPrayer[5] = exTh + exIs; - pt.setAllExtreme(true); - - } else if (ext == ExtremeLatitude.GOOD_INVALID) { - if (tempPrayer[0] == 99) { - tempPrayer[0] = exTh - exFj; - pt.fajr().setExtreme(true); - } - if (tempPrayer[5] == 99) { - tempPrayer[5] = exTh + exIs; - pt.isha().setExtreme(true); - } - } else if (ext == ExtremeLatitude.GOOD_DIF) { - /* Nearest Good Day: Different good days for Fajr and Ishaa (Not - * implemented) */ - } - } else if (ext == ExtremeLatitude.SEVEN_NIGHT_ALWAYS || ext == ExtremeLatitude.SEVEN_NIGHT_INVALID - || ext == ExtremeLatitude.SEVEN_DAY_ALWAYS || ext == ExtremeLatitude.SEVEN_DAY_INVALID - || ext == ExtremeLatitude.HALF_ALWAYS || ext == ExtremeLatitude.HALF_INVALID) { - - - /* xxxthamer: For clarity, we may need to move the HALF_* methods - * into their own separate case statement. */ - - if(ext == ExtremeLatitude.SEVEN_NIGHT_ALWAYS || ext == ExtremeLatitude.SEVEN_NIGHT_INVALID) { - portion = (24 - (tempPrayer[4] - tempPrayer[1])) - * (1 / 7.0); - } else if (ext == ExtremeLatitude.SEVEN_DAY_ALWAYS || ext == ExtremeLatitude.SEVEN_DAY_INVALID) { - portion = (tempPrayer[4] - tempPrayer[1]) * (1 / 7.0); - } else if (ext == ExtremeLatitude.HALF_ALWAYS || ext == ExtremeLatitude.HALF_INVALID) { - portion = (24 - tempPrayer[4] - tempPrayer[1]) * (1 / 2.0); - } - - if (method.getExtremeLatitude() == ExtremeLatitude.SEVEN_NIGHT_INVALID - || method.getExtremeLatitude() == ExtremeLatitude.SEVEN_DAY_INVALID - || method.getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) { - if (tempPrayer[0] == 99) { - if (method.getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) - tempPrayer[0] = portion - - (method.getFajrInv() / 60.0); - else - tempPrayer[0] = tempPrayer[1] - portion; - pt.fajr().setExtreme(true); - } - if (tempPrayer[5] == 99) { - if (method.getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) - tempPrayer[5] = portion - + (method.getIshaaInv() / 60.0); - else - tempPrayer[5] = tempPrayer[4] + portion; - pt.isha().setExtreme(true); - } - } else { /* for the always methods */ - - if (method.getExtremeLatitude() == ExtremeLatitude.HALF_ALWAYS) { - tempPrayer[0] = portion - (method.getFajrInv() / 60.0); - tempPrayer[5] = portion + (method.getIshaaInv() / 60.0); - } - - else { - tempPrayer[0] = tempPrayer[1] - portion; - tempPrayer[5] = tempPrayer[4] + portion; - } - pt.fajr().setExtreme(true); - pt.isha().setExtreme(true); - } - } else if (ext == ExtremeLatitude.MIN_ALWAYS) { - /* Do nothing here because this is implemented through fajrInv and - * ishaaInv structure members */ - tempPrayer[0] = tempPrayer[1]; - tempPrayer[5] = tempPrayer[4]; - pt.fajr().setExtreme(true); - pt.isha().setExtreme(true); - } else if (ext == ExtremeLatitude.MIN_INVALID) { - if (tempPrayer[0] == 99) { - exinterval = (int) ((double) method.getFajrInv() / 60.0); - tempPrayer[0] = tempPrayer[1] - exinterval; - pt.fajr().setExtreme(true); - } - if (tempPrayer[5] == 99) { - exinterval = (int) ((double) method.getIshaaInv() / 60.0); - tempPrayer[5] = tempPrayer[4] + exinterval; - pt.isha().setExtreme(true); - } - } /* end switch */ - } /* end extreme */ - - /* Apply intervals if set */ - if (method.getExtremeLatitude() != ExtremeLatitude.MIN_INVALID - && method.getExtremeLatitude() != ExtremeLatitude.HALF_INVALID - && method.getExtremeLatitude() != ExtremeLatitude.HALF_ALWAYS) { - if (method.getFajrInv() != 0) - tempPrayer[0] = tempPrayer[1] - (method.getFajrInv() / 60.0); - if (method.getIshaaInv() != 0) - tempPrayer[5] = tempPrayer[4] + (method.getIshaaInv() / 60.0); - } - - /* Final Step: Fill the Prayer array by doing decimal degree to - * Prayer structure conversion*/ - if (type == InternalTimeType.IMSAK /* || type == TimeType.NEXT_FAJR */) { - base6hm(tempPrayer[0], method, pt.fajr(), type); - } else { - PrayerTime[] pArray = pt.getPrayerTime(); - InternalTimeType[] timeArray = { InternalTimeType.FAJR, InternalTimeType.SUNRISE, - InternalTimeType.ZUHR, InternalTimeType.ASR, InternalTimeType.MAGHRIB, - InternalTimeType.ISHA }; - - for (i = 0; i < 6; i++) { - base6hm(tempPrayer[i], method, pArray[i], timeArray[i]); - } - } - - } + private void getPrayerTimesByDay(Method method, DayCouple dc, PrayerTimes pt, + InternalTimeType type) { + int i, invalid; + double th, sh, mg, fj, is, ar; + double lat, lon, dec; + double tempPrayer[] = new double[6]; + Astro tAstro = new Astro(); + + lat = loc.getDegreeLat(); + lon = loc.getDegreeLong(); + invalid = 0; + + /* Start by filling the tAstro structure with the appropriate astronomical + * values for this day. We also pass the cache structure to update and check + * if the actual values are already available. */ + AstroLib + .getAstroValuesByDay(dc.julianDay, loc, astroCache, tAstro); + dec = Utils.degToRad(tAstro.getDec()[1]); + + /* Get Prayer Times formulae results for this day of year and this + * location. The results are NOT the actual prayer times */ + fj = getFajIsh(lat, dec, method.getFajrAng()); + sh = getShoMag(loc, tAstro, InternalTimeType.SUNRISE); + th = getThuhr(lon, tAstro); + ar = getAssr(lat, dec, method.getMathhab()); + mg = getShoMag(loc, tAstro, InternalTimeType.MAGHRIB); + is = getFajIsh(lat, dec, method.getIshaaAng()); + + /* Calculate all prayer times as Base-10 numbers in Normal circumstances */ + /* Fajr */ + if (fj == 99) { + tempPrayer[0] = 99; + invalid = 1; + } else { + tempPrayer[0] = th - fj; + } + + if (sh == 99) { + invalid = 1; + } + + tempPrayer[1] = sh; + tempPrayer[2] = th; + tempPrayer[3] = th + ar; + tempPrayer[4] = mg; + + if (mg == 99) { + invalid = 1; + } + + /* Ishaa */ + if (is == 99) { + tempPrayer[5] = 99; + invalid = 1; + } else { + tempPrayer[5] = th + is; + } + + /* Calculate all prayer times as Base-10 numbers in Extreme Latitudes (if + * needed) */ + + /* Reset status of extreme switches */ + pt.setAllExtreme(false); + + if ((method.getExtremeLatitude() != ExtremeLatitude.NONE_EX) + && !((method.getExtremeLatitude() == ExtremeLatitude.GOOD_INVALID + || method.getExtremeLatitude() == ExtremeLatitude.LAT_INVALID + || method.getExtremeLatitude() == ExtremeLatitude.SEVEN_NIGHT_INVALID + || method.getExtremeLatitude() == ExtremeLatitude.SEVEN_DAY_INVALID || method + .getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) && (invalid == 0))) { + double exdecPrev, exdecNext; + double exTh = 99, exFj = 99, exIs = 99, exAr = 99, exSh = 99, exMg = 99; + //exIm=99 + + double portion = 0; + double nGoodDay = 0; + int exinterval = 0; + Location exLoc = new Location(loc); + Astro exAstroPrev; + Astro exAstroNext; + ExtremeLatitude ext = method.getExtremeLatitude(); + + /* Nearest Latitude (Method.nearestLat) */ + if(ext == ExtremeLatitude.LAT_ALL || ext == ExtremeLatitude.LAT_ALWAYS || ext == ExtremeLatitude.LAT_INVALID) { + /* + case LAT_ALL: + case LAT_ALWAYS: + case LAT_INVALID: + */ + + /* xxxthamer: we cannot compute this when interval is set because + * angle==0 . Only the if-invalid methods would work */ + exLoc.setDegreeLat(method.getNearestLat()); + exFj = getFajIsh(method.getNearestLat(), dec, method + .getFajrAng()); + //exIm = getFajIsh(method.getNearestLat(), dec, method.getImsaakAng()); + exIs = getFajIsh(method.getNearestLat(), dec, method + .getIshaaAng()); + exAr = getAssr(method.getNearestLat(), dec, method.getMathhab()); + exSh = getShoMag(exLoc, tAstro, InternalTimeType.SUNRISE); + exMg = getShoMag(exLoc, tAstro, InternalTimeType.MAGHRIB); + + //switch (ext) { + if(ext == ExtremeLatitude.LAT_ALL) { + //case LAT_ALL: + tempPrayer[0] = th - exFj; + tempPrayer[1] = exSh; + tempPrayer[3] = th + exAr; + tempPrayer[4] = exMg; + tempPrayer[5] = th + exIs; + pt.setAllExtreme(true); + } else if (ext == ExtremeLatitude.LAT_ALWAYS) { + tempPrayer[0] = th - exFj; + tempPrayer[5] = th + exIs; + pt.fajr().setExtreme(true); + pt.isha().setExtreme(true); + } else if (ext == ExtremeLatitude.LAT_INVALID) { + if (tempPrayer[0] == 99) { + tempPrayer[0] = th - exFj; + pt.fajr().setExtreme(true); + } + if (tempPrayer[5] == 99) { + tempPrayer[5] = th + exIs; + pt.isha().setExtreme(true); + } + } + + } else if (ext == ExtremeLatitude.GOOD_ALL || ext == ExtremeLatitude.GOOD_INVALID + || ext == ExtremeLatitude.GOOD_DIF) { + /* Nearest Good Day */ + exAstroPrev = astroCache; + exAstroNext = astroCache; + + /* Start by getting last or next nearest Good Day */ + for (i = 0; i <= dc.lastDay; i++) { + + /* last closest day */ + nGoodDay = dc.julianDay - i; + AstroLib.getAstroValuesByDay(nGoodDay, loc, exAstroPrev, + tAstro); + exdecPrev = Utils.degToRad(tAstro.getDec()[1]); + exFj = getFajIsh(lat, exdecPrev, method.getFajrAng()); + + if (exFj != 99) { + exIs = getFajIsh(lat, exdecPrev, method.getIshaaAng()); + if (exIs != 99) { + exTh = getThuhr(lon, tAstro); + exSh = getShoMag(loc, tAstro, InternalTimeType.SUNRISE); + exMg = getShoMag(loc, tAstro, InternalTimeType.MAGHRIB); + exAr = getAssr(lat, exdecPrev, method.getMathhab()); + break; + } + } + + /* Next closest day */ + nGoodDay = dc.julianDay + i; + AstroLib.getAstroValuesByDay(nGoodDay, loc, exAstroNext, + tAstro); + exdecNext = Utils.degToRad(tAstro.getDec()[1]); + exFj = getFajIsh(lat, exdecNext, method.getFajrAng()); + if (exFj != 99) { + exIs = getFajIsh(lat, exdecNext, method.getIshaaAng()); + if (exIs != 99) { + exTh = getThuhr(lon, tAstro); + exSh = getShoMag(loc, tAstro, InternalTimeType.SUNRISE); + exMg = getShoMag(loc, tAstro, InternalTimeType.MAGHRIB); + exAr = getAssr(lat, exdecNext, method.getMathhab()); + break; + } + } + } + + if(ext == ExtremeLatitude.GOOD_ALL) { + tempPrayer[0] = exTh - exFj; + tempPrayer[1] = exSh; + tempPrayer[2] = exTh; + tempPrayer[3] = exTh + exAr; + tempPrayer[4] = exMg; + tempPrayer[5] = exTh + exIs; + pt.setAllExtreme(true); + + } else if (ext == ExtremeLatitude.GOOD_INVALID) { + if (tempPrayer[0] == 99) { + tempPrayer[0] = exTh - exFj; + pt.fajr().setExtreme(true); + } + if (tempPrayer[5] == 99) { + tempPrayer[5] = exTh + exIs; + pt.isha().setExtreme(true); + } + } else if (ext == ExtremeLatitude.GOOD_DIF) { + /* Nearest Good Day: Different good days for Fajr and Ishaa (Not + * implemented) */ + } + } else if (ext == ExtremeLatitude.SEVEN_NIGHT_ALWAYS || ext == ExtremeLatitude.SEVEN_NIGHT_INVALID + || ext == ExtremeLatitude.SEVEN_DAY_ALWAYS || ext == ExtremeLatitude.SEVEN_DAY_INVALID + || ext == ExtremeLatitude.HALF_ALWAYS || ext == ExtremeLatitude.HALF_INVALID) { + + + /* xxxthamer: For clarity, we may need to move the HALF_* methods + * into their own separate case statement. */ + + if(ext == ExtremeLatitude.SEVEN_NIGHT_ALWAYS || ext == ExtremeLatitude.SEVEN_NIGHT_INVALID) { + portion = (24 - (tempPrayer[4] - tempPrayer[1])) + * (1 / 7.0); + } else if (ext == ExtremeLatitude.SEVEN_DAY_ALWAYS || ext == ExtremeLatitude.SEVEN_DAY_INVALID) { + portion = (tempPrayer[4] - tempPrayer[1]) * (1 / 7.0); + } else if (ext == ExtremeLatitude.HALF_ALWAYS || ext == ExtremeLatitude.HALF_INVALID) { + portion = (24 - tempPrayer[4] - tempPrayer[1]) * (1 / 2.0); + } + + if (method.getExtremeLatitude() == ExtremeLatitude.SEVEN_NIGHT_INVALID + || method.getExtremeLatitude() == ExtremeLatitude.SEVEN_DAY_INVALID + || method.getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) { + if (tempPrayer[0] == 99) { + if (method.getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) + tempPrayer[0] = portion + - (method.getFajrInv() / 60.0); + else + tempPrayer[0] = tempPrayer[1] - portion; + pt.fajr().setExtreme(true); + } + if (tempPrayer[5] == 99) { + if (method.getExtremeLatitude() == ExtremeLatitude.HALF_INVALID) + tempPrayer[5] = portion + + (method.getIshaaInv() / 60.0); + else + tempPrayer[5] = tempPrayer[4] + portion; + pt.isha().setExtreme(true); + } + } else { /* for the always methods */ + + if (method.getExtremeLatitude() == ExtremeLatitude.HALF_ALWAYS) { + tempPrayer[0] = portion - (method.getFajrInv() / 60.0); + tempPrayer[5] = portion + (method.getIshaaInv() / 60.0); + } + + else { + tempPrayer[0] = tempPrayer[1] - portion; + tempPrayer[5] = tempPrayer[4] + portion; + } + pt.fajr().setExtreme(true); + pt.isha().setExtreme(true); + } + } else if (ext == ExtremeLatitude.MIN_ALWAYS) { + /* Do nothing here because this is implemented through fajrInv and + * ishaaInv structure members */ + tempPrayer[0] = tempPrayer[1]; + tempPrayer[5] = tempPrayer[4]; + pt.fajr().setExtreme(true); + pt.isha().setExtreme(true); + } else if (ext == ExtremeLatitude.MIN_INVALID) { + if (tempPrayer[0] == 99) { + exinterval = (int) ((double) method.getFajrInv() / 60.0); + tempPrayer[0] = tempPrayer[1] - exinterval; + pt.fajr().setExtreme(true); + } + if (tempPrayer[5] == 99) { + exinterval = (int) ((double) method.getIshaaInv() / 60.0); + tempPrayer[5] = tempPrayer[4] + exinterval; + pt.isha().setExtreme(true); + } + } /* end switch */ + } /* end extreme */ + + /* Apply intervals if set */ + if (method.getExtremeLatitude() != ExtremeLatitude.MIN_INVALID + && method.getExtremeLatitude() != ExtremeLatitude.HALF_INVALID + && method.getExtremeLatitude() != ExtremeLatitude.HALF_ALWAYS) { + if (method.getFajrInv() != 0) + tempPrayer[0] = tempPrayer[1] - (method.getFajrInv() / 60.0); + if (method.getIshaaInv() != 0) + tempPrayer[5] = tempPrayer[4] + (method.getIshaaInv() / 60.0); + } + + /* Final Step: Fill the Prayer array by doing decimal degree to + * Prayer structure conversion*/ + if (type == InternalTimeType.IMSAK /* || type == TimeType.NEXT_FAJR */) { + base6hm(tempPrayer[0], method, pt.fajr(), type); + } else { + PrayerTime[] pArray = pt.getPrayerTime(); + InternalTimeType[] timeArray = { InternalTimeType.FAJR, InternalTimeType.SUNRISE, + InternalTimeType.ZUHR, InternalTimeType.ASR, InternalTimeType.MAGHRIB, + InternalTimeType.ISHA }; + + for (i = 0; i < 6; i++) { + base6hm(tempPrayer[i], method, pArray[i], timeArray[i]); + } + } + + } - private void base6hm(double bs, Method method, PrayerTime pt, InternalTimeType type) { - double min, sec; - - if (bs == 99) { - pt.setHour(99); - pt.setMinute(99); - pt.setSecond(0); - return; - } - - /* Add offsets */ - if (method.getOffset()) { - if (type == InternalTimeType.IMSAK /* || type == TimeType.NEXT_FAJR */) - bs += (method.getFajrOffset() / 60.0); - else - bs += (method.getOffset(type) / 60.0); - } - - /* Fix after minus offsets before midnight */ - if (bs < 0) { - while (bs < 0) - bs = 24 + bs; - } - - min = (bs - Math.floor(bs)) * 60; - sec = (min - Math.floor(min)) * 60; - - /* Add rounding minutes */ - if (method.getRound() == Rounding.NORMAL) { - if (sec >= Utils.DEFAULT_ROUND_SEC) - bs += 1 / 60.0; - /* compute again */ - min = (bs - Math.floor(bs)) * 60; - sec = 0; - - } else if (method.getRound() == Rounding.SPECIAL || method.getRound() == Rounding.AGRESSIVE) { - if (type == InternalTimeType.FAJR || type == InternalTimeType.ZUHR - || type == InternalTimeType.ASR || type == InternalTimeType.MAGHRIB - || type == InternalTimeType.ISHA /* || type == TimeType.NEXT_FAJR */) { - if (method.getRound() == Rounding.SPECIAL) { - if (sec >= Utils.DEFAULT_ROUND_SEC) { - bs += 1 / 60.0; - min = (bs - Math.floor(bs)) * 60; - } - } else if (method.getRound() == Rounding.AGRESSIVE) { - if (sec >= Utils.AGGRESSIVE_ROUND_SEC) { - bs += 1 / 60.0; - min = (bs - Math.floor(bs)) * 60; - } - } - sec = 0; - } else { - //case Prayer.SHUROOQ: - //case Prayer.IMSAAK: - sec = 0; - } - } - - /* Add daylight saving time and fix after midnight times */ - bs += loc.getDst(); - if (bs >= 24) { - bs = Math.IEEEremainder(bs, 24); - } - - pt.setHour((int) bs); - pt.setMinute((int) min); - pt.setSecond((int) sec); - - } + private void base6hm(double bs, Method method, PrayerTime pt, InternalTimeType type) { + double min, sec; + + if (bs == 99) { + pt.setHour(99); + pt.setMinute(99); + pt.setSecond(0); + return; + } + + /* Add offsets */ + if (method.getOffset()) { + if (type == InternalTimeType.IMSAK /* || type == TimeType.NEXT_FAJR */) + bs += (method.getFajrOffset() / 60.0); + else + bs += (method.getOffset(type) / 60.0); + } + + /* Fix after minus offsets before midnight */ + if (bs < 0) { + while (bs < 0) + bs = 24 + bs; + } + + min = (bs - Math.floor(bs)) * 60; + sec = (min - Math.floor(min)) * 60; + + /* Add rounding minutes */ + if (method.getRound() == Rounding.NORMAL) { + if (sec >= Utils.DEFAULT_ROUND_SEC) + bs += 1 / 60.0; + /* compute again */ + min = (bs - Math.floor(bs)) * 60; + sec = 0; + + } else if (method.getRound() == Rounding.SPECIAL || method.getRound() == Rounding.AGRESSIVE) { + if (type == InternalTimeType.FAJR || type == InternalTimeType.ZUHR + || type == InternalTimeType.ASR || type == InternalTimeType.MAGHRIB + || type == InternalTimeType.ISHA /* || type == TimeType.NEXT_FAJR */) { + if (method.getRound() == Rounding.SPECIAL) { + if (sec >= Utils.DEFAULT_ROUND_SEC) { + bs += 1 / 60.0; + min = (bs - Math.floor(bs)) * 60; + } + } else if (method.getRound() == Rounding.AGRESSIVE) { + if (sec >= Utils.AGGRESSIVE_ROUND_SEC) { + bs += 1 / 60.0; + min = (bs - Math.floor(bs)) * 60; + } + } + sec = 0; + } else { + //case Prayer.SHUROOQ: + //case Prayer.IMSAAK: + sec = 0; + } + } + + /* Add daylight saving time and fix after midnight times */ + bs += loc.getDst(); + if (bs >= 24) { + bs = Math.IEEEremainder(bs, 24); + } + + pt.setHour((int) bs); + pt.setMinute((int) min); + pt.setSecond((int) sec); + + } - private static double getFajIsh(double Lat, double dec, double Ang) { - - double part1 = Math.cos(Utils.degToRad(Lat)) * Math.cos(dec); - double part2 = -Math.sin(Utils.degToRad(Ang)) - - Math.sin(Utils.degToRad(Lat)) * Math.sin(dec); - - double part3 = part2 / part1; - if (part3 <= Utils.INVALID_TRIGGER) { - return 99; - } - - return Utils.DEG_TO_10_BASE * Utils.radToDeg(Math.acos(part3)); - - } - - private static double getShoMag(Location loc, Astro astro, InternalTimeType type) { - double lhour, M, sidG, ra0 = astro.getRa()[0], ra2 = astro.getRa()[2]; - double A, B, H, sunAlt, R, tH; - - double part1 = Math.sin(Utils.degToRad(loc.getDegreeLat())) - * Math.sin(Utils.degToRad(astro.getDec()[1])); - double part2a = Utils.CENTER_OF_SUN_ANGLE; - double part2 = Math.sin(Utils.degToRad(part2a)) - part1; - double part3 = Math.cos(Utils.degToRad(loc.getDegreeLat())) - * Math.cos(Utils.degToRad(astro.getDec()[1])); - - double part4 = part2 / part3; - - if (part4 <= -1 || part4 >= 1) - return 99; - - lhour = AstroLib.limitAngle180((Utils.radToDeg(Math.acos(part4)))); - M = ((astro.getRa()[1] - loc.getDegreeLong() - astro.getSid()[1]) / 360.0); - - if (type == InternalTimeType.SUNRISE) - M = M - (lhour / 360.0); - if (type == InternalTimeType.MAGHRIB) - M = M + (lhour / 360.0); - - M = AstroLib.limitAngle111(M); - - sidG = AstroLib.limitAngle(astro.getSid()[1] + 360.985647 * M); - - ra0 = astro.getRa()[0]; - ra2 = astro.getRa()[2]; - - if (astro.getRa()[1] > 350 && astro.getRa()[2] < 10) - ra2 += 360; - if (astro.getRa()[0] > 350 && astro.getRa()[1] < 10) - ra0 = 0; - - A = astro.getRa()[1] - + (M - * ((astro.getRa()[1] - ra0) + (ra2 - astro.getRa()[1]) + ((ra2 - astro - .getRa()[1]) - (astro.getRa()[1] - ra0)) - * M) / 2.0); - - B = astro.getDec()[1] - + (M - * ((astro.getDec()[1] - astro.getDec()[0]) - + (astro.getDec()[2] - astro.getDec()[1]) + ((astro - .getDec()[2] - astro.getDec()[1]) - (astro - .getDec()[1] - astro.getDec()[0])) - * M) / 2.0); - - H = AstroLib.limitAngle180between(sidG + loc.getDegreeLong() - A); - - tH = H - Utils.radToDeg(astro.getDra()[1]); - - sunAlt = Utils.radToDeg(Math.asin(Math.sin(Utils.degToRad(loc - .getDegreeLat())) - * Math.sin(Utils.degToRad(B)) - + Math.cos(Utils.degToRad(loc.getDegreeLat())) - * Math.cos(Utils.degToRad(B)) - * Math.cos(Utils.degToRad(tH)))); - - sunAlt += AstroLib.getRefraction(loc, sunAlt); - - R = (M + ((sunAlt - Utils.CENTER_OF_SUN_ANGLE + (Utils.ALTITUDE_REFRACTION * Math - .pow(loc.getSeaLevel(), 0.5))) / (360.0 - * Math.cos(Utils.degToRad(B)) - * Math.cos(Utils.degToRad(loc.getDegreeLat())) * Math - .sin(Utils.degToRad(tH))))); - - return (R * 24.0); - - } - - private static double getThuhr(double lon, Astro astro) { - - double M, sidG; - double ra0 = astro.getRa()[0], ra2 = astro.getRa()[2]; - double A, H; - - M = ((astro.getRa()[1] - lon - astro.getSid()[1]) / 360.0); - M = AstroLib.limitAngle111(M); - sidG = astro.getSid()[1] + 360.985647 * M; - - if (astro.getRa()[1] > 350 && astro.getRa()[2] < 10) - ra2 += 360; - if (astro.getRa()[0] > 350 && astro.getRa()[1] < 10) - ra0 = 0; - - A = astro.getRa()[1] - + (M - * ((astro.getRa()[1] - ra0) + (ra2 - astro.getRa()[1]) + ((ra2 - astro - .getRa()[1]) - (astro.getRa()[1] - ra0)) - * M) / 2.0); - - H = AstroLib.limitAngle180between(sidG + lon - A); - - return 24.0 * (M - H / 360.0); - } - - private static double getAssr(double Lat, double dec, Madhhab mathhab) { - double part1, part2, part3, part4; - int mathhabValue = (mathhab == Madhhab.SHAFII ? 1 : 2); - - part1 = mathhabValue + Math.tan(Utils.degToRad(Lat) - dec); - if (part1 < 1 || Lat < 0) - part1 = mathhabValue - Math.tan(Utils.degToRad(Lat) - dec); - - part2 = (Utils.PI / 2.0) - Math.atan(part1); - part3 = Math.sin(part2) - Math.sin(Utils.degToRad(Lat)) - * Math.sin(dec); - part4 = (part3 / (Math.cos(Utils.degToRad(Lat)) * Math.cos(dec))); - - /* if (part4 > 1) */ - /* return 99; */ - - return Utils.DEG_TO_10_BASE * Utils.radToDeg(Math.acos(part4)); - } - - private static int getDayofYear(int year, int month, int day) { - int i; - int isLeap = (((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0)) ? 1 - : 0; - - char dayList[][] = { - { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; - - for (i = 1; i < month; i++) - day += dayList[isLeap][i]; - - return day; - } - - private static DayCouple getDayInfo(Date date, double gmt) { - GregorianCalendar gcal = new GregorianCalendar(); - gcal.setTime(date); - SimpleGregorianDate gdate = new SimpleGregorianDate(gcal); - - int ld; - double jd; - ld = getDayofYear(gdate.getYear(), 12, 31); - jd = AstroLib.getJulianDay(gdate, gmt); - return new DayCouple(ld, jd); - } - + private static double getFajIsh(double Lat, double dec, double Ang) { + + double part1 = Math.cos(Utils.degToRad(Lat)) * Math.cos(dec); + double part2 = -Math.sin(Utils.degToRad(Ang)) + - Math.sin(Utils.degToRad(Lat)) * Math.sin(dec); + + double part3 = part2 / part1; + if (part3 <= Utils.INVALID_TRIGGER) { + return 99; + } + + return Utils.DEG_TO_10_BASE * Utils.radToDeg(Math.acos(part3)); + + } + + private static double getShoMag(Location loc, Astro astro, InternalTimeType type) { + double lhour, M, sidG, ra0 = astro.getRa()[0], ra2 = astro.getRa()[2]; + double A, B, H, sunAlt, R, tH; + + double part1 = Math.sin(Utils.degToRad(loc.getDegreeLat())) + * Math.sin(Utils.degToRad(astro.getDec()[1])); + double part2a = Utils.CENTER_OF_SUN_ANGLE; + double part2 = Math.sin(Utils.degToRad(part2a)) - part1; + double part3 = Math.cos(Utils.degToRad(loc.getDegreeLat())) + * Math.cos(Utils.degToRad(astro.getDec()[1])); + + double part4 = part2 / part3; + + if (part4 <= -1 || part4 >= 1) + return 99; + + lhour = AstroLib.limitAngle180((Utils.radToDeg(Math.acos(part4)))); + M = ((astro.getRa()[1] - loc.getDegreeLong() - astro.getSid()[1]) / 360.0); + + if (type == InternalTimeType.SUNRISE) + M = M - (lhour / 360.0); + if (type == InternalTimeType.MAGHRIB) + M = M + (lhour / 360.0); + + M = AstroLib.limitAngle111(M); + + sidG = AstroLib.limitAngle(astro.getSid()[1] + 360.985647 * M); + + ra0 = astro.getRa()[0]; + ra2 = astro.getRa()[2]; + + if (astro.getRa()[1] > 350 && astro.getRa()[2] < 10) + ra2 += 360; + if (astro.getRa()[0] > 350 && astro.getRa()[1] < 10) + ra0 = 0; + + A = astro.getRa()[1] + + (M + * ((astro.getRa()[1] - ra0) + (ra2 - astro.getRa()[1]) + ((ra2 - astro + .getRa()[1]) - (astro.getRa()[1] - ra0)) + * M) / 2.0); + + B = astro.getDec()[1] + + (M + * ((astro.getDec()[1] - astro.getDec()[0]) + + (astro.getDec()[2] - astro.getDec()[1]) + ((astro + .getDec()[2] - astro.getDec()[1]) - (astro + .getDec()[1] - astro.getDec()[0])) + * M) / 2.0); + + H = AstroLib.limitAngle180between(sidG + loc.getDegreeLong() - A); + + tH = H - Utils.radToDeg(astro.getDra()[1]); + + sunAlt = Utils.radToDeg(Math.asin(Math.sin(Utils.degToRad(loc + .getDegreeLat())) + * Math.sin(Utils.degToRad(B)) + + Math.cos(Utils.degToRad(loc.getDegreeLat())) + * Math.cos(Utils.degToRad(B)) + * Math.cos(Utils.degToRad(tH)))); + + sunAlt += AstroLib.getRefraction(loc, sunAlt); + + R = (M + ((sunAlt - Utils.CENTER_OF_SUN_ANGLE + (Utils.ALTITUDE_REFRACTION * Math + .pow(loc.getSeaLevel(), 0.5))) / (360.0 + * Math.cos(Utils.degToRad(B)) + * Math.cos(Utils.degToRad(loc.getDegreeLat())) * Math + .sin(Utils.degToRad(tH))))); + + return (R * 24.0); + + } + + private static double getThuhr(double lon, Astro astro) { + + double M, sidG; + double ra0 = astro.getRa()[0], ra2 = astro.getRa()[2]; + double A, H; + + M = ((astro.getRa()[1] - lon - astro.getSid()[1]) / 360.0); + M = AstroLib.limitAngle111(M); + sidG = astro.getSid()[1] + 360.985647 * M; + + if (astro.getRa()[1] > 350 && astro.getRa()[2] < 10) + ra2 += 360; + if (astro.getRa()[0] > 350 && astro.getRa()[1] < 10) + ra0 = 0; + + A = astro.getRa()[1] + + (M + * ((astro.getRa()[1] - ra0) + (ra2 - astro.getRa()[1]) + ((ra2 - astro + .getRa()[1]) - (astro.getRa()[1] - ra0)) + * M) / 2.0); + + H = AstroLib.limitAngle180between(sidG + lon - A); + + return 24.0 * (M - H / 360.0); + } + + private static double getAssr(double Lat, double dec, Madhhab mathhab) { + double part1, part2, part3, part4; + int mathhabValue = (mathhab == Madhhab.SHAFII ? 1 : 2); + + part1 = mathhabValue + Math.tan(Utils.degToRad(Lat) - dec); + if (part1 < 1 || Lat < 0) + part1 = mathhabValue - Math.tan(Utils.degToRad(Lat) - dec); + + part2 = (Utils.PI / 2.0) - Math.atan(part1); + part3 = Math.sin(part2) - Math.sin(Utils.degToRad(Lat)) + * Math.sin(dec); + part4 = (part3 / (Math.cos(Utils.degToRad(Lat)) * Math.cos(dec))); + + /* if (part4 > 1) */ + /* return 99; */ + + return Utils.DEG_TO_10_BASE * Utils.radToDeg(Math.acos(part4)); + } + + private static int getDayofYear(int year, int month, int day) { + int i; + int isLeap = (((year & 3) == 0) && ((year % 100) != 0 || (year % 400) == 0)) ? 1 + : 0; + + char dayList[][] = { + { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, + { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; + + for (i = 1; i < month; i++) + day += dayList[isLeap][i]; + + return day; + } + + private static DayCouple getDayInfo(Date date, double gmt) { + GregorianCalendar gcal = new GregorianCalendar(); + gcal.setTime(date); + SimpleGregorianDate gdate = new SimpleGregorianDate(gcal); + + int ld; + double jd; + ld = getDayofYear(gdate.getYear(), 12, 31); + jd = AstroLib.getJulianDay(gdate, gmt); + return new DayCouple(ld, jd); + } + } diff --git a/src/org/arabeyes/itl/prayer/PrayerTimes.java b/src/org/arabeyes/itl/prayer/PrayerTimes.java index 59b1528..924816c 100644 --- a/src/org/arabeyes/itl/prayer/PrayerTimes.java +++ b/src/org/arabeyes/itl/prayer/PrayerTimes.java @@ -5,53 +5,53 @@ * Encapsulates the list of prayers time and shuruq time */ public class PrayerTimes { - - public static final int FAJR = 0; - public static final int SUNRISE = 1; - public static final int ZUHR = 2; - public static final int ASR = 3; - public static final int MAGHRIB = 4; - public static final int ISHA = 5; - - private PrayerTime[] prayers = new PrayerTime[6]; - - public PrayerTimes() { - for (int i = 0; i < prayers.length; i++) - prayers[i] = new PrayerTime(); - } - - public PrayerTime get(int type) { - return prayers[type]; - } - - /** - * Convert prayer times to a string. - * @return prayer times as a string. It contains 6 lines - */ - @Override - public String toString() { - String ret = ""; - for (int i = 0; i < 6; i++) { - ret += prayers[i].toString() + "\n"; - } - return ret; - } - - PrayerTime fajr() { - return prayers[0]; - } - - PrayerTime isha() { - return prayers[5]; - } - - PrayerTime[] getPrayerTime() { - return prayers; - } - - void setAllExtreme(boolean extreme) { - for (int i = 0; i < 6; i++) { - prayers[i].setExtreme(extreme); - } - } + + public static final int FAJR = 0; + public static final int SUNRISE = 1; + public static final int ZUHR = 2; + public static final int ASR = 3; + public static final int MAGHRIB = 4; + public static final int ISHA = 5; + + private PrayerTime[] prayers = new PrayerTime[6]; + + public PrayerTimes() { + for (int i = 0; i < prayers.length; i++) + prayers[i] = new PrayerTime(); + } + + public PrayerTime get(int type) { + return prayers[type]; + } + + /** + * Convert prayer times to a string. + * @return prayer times as a string. It contains 6 lines + */ + @Override + public String toString() { + String ret = ""; + for (int i = 0; i < 6; i++) { + ret += prayers[i].toString() + "\n"; + } + return ret; + } + + PrayerTime fajr() { + return prayers[0]; + } + + PrayerTime isha() { + return prayers[5]; + } + + PrayerTime[] getPrayerTime() { + return prayers; + } + + void setAllExtreme(boolean extreme) { + for (int i = 0; i < 6; i++) { + prayers[i].setExtreme(extreme); + } + } } diff --git a/src/org/arabeyes/itl/prayer/TimeNames.java b/src/org/arabeyes/itl/prayer/TimeNames.java index ed45399..dbfcff3 100644 --- a/src/org/arabeyes/itl/prayer/TimeNames.java +++ b/src/org/arabeyes/itl/prayer/TimeNames.java @@ -4,40 +4,40 @@ import java.util.ResourceBundle; public class TimeNames { - - private static TimeNames instance; - - private ResourceBundle res; - private Locale locale; - - public TimeNames(Locale locale) { - this.res = ResourceBundle.getBundle("org.arabeyes.itl.prayer.name", locale); - this.locale = locale; - } - - public Locale getLocale() { - return locale; - } + + private static TimeNames instance; + + private ResourceBundle res; + private Locale locale; + + public TimeNames(Locale locale) { + this.res = ResourceBundle.getBundle("org.arabeyes.itl.prayer.name", locale); + this.locale = locale; + } + + public Locale getLocale() { + return locale; + } - /** - * - * @param type one of prayer time constants in {@link PrayerTimes}, including {@link PrayerTimes#SUNRISE} - * @return - */ - public String get(int type) { - if (type >= 6 || type < 0) - throw new IllegalArgumentException("Invalid time type: " + type); - return res.getString("time." + type); - } + /** + * + * @param type one of prayer time constants in {@link PrayerTimes}, including {@link PrayerTimes#SUNRISE} + * @return + */ + public String get(int type) { + if (type >= 6 || type < 0) + throw new IllegalArgumentException("Invalid time type: " + type); + return res.getString("time." + type); + } - public String getImsak() { - return res.getString("time.imsak"); - } - - public static TimeNames getInstance(Locale locale) { - if (instance == null || !instance.locale.equals(locale)) - instance = new TimeNames(locale); - return instance; - } + public String getImsak() { + return res.getString("time.imsak"); + } + + public static TimeNames getInstance(Locale locale) { + if (instance == null || !instance.locale.equals(locale)) + instance = new TimeNames(locale); + return instance; + } } diff --git a/src/org/arabeyes/itl/prayer/astro/Astro.java b/src/org/arabeyes/itl/prayer/astro/Astro.java index a1f3b98..5da7c63 100644 --- a/src/org/arabeyes/itl/prayer/astro/Astro.java +++ b/src/org/arabeyes/itl/prayer/astro/Astro.java @@ -5,72 +5,72 @@ package org.arabeyes.itl.prayer.astro; public class Astro { - private double jd; - - private double dec[]; - - private double ra[]; - - private double sid[]; - - private double dra[]; - - private double rsum[]; - - public Astro() { - dec = new double[3]; - ra = new double[3]; - sid = new double[3]; - dra = new double[3]; - rsum = new double[3]; - } - - public double[] getDec() { - return dec; - } - - public void setDec(double[] dec) { - this.dec = dec; - } - - public double[] getDra() { - return dra; - } - - public void setDra(double[] dra) { - this.dra = dra; - } - - public double getJd() { - return jd; - } - - public void setJd(double jd) { - this.jd = jd; - } - - public double[] getRa() { - return ra; - } - - public void setRa(double[] ra) { - this.ra = ra; - } - - public double[] getRsum() { - return rsum; - } - - public void setRsum(double[] rsum) { - this.rsum = rsum; - } - - public double[] getSid() { - return sid; - } - - public void setSid(double[] sid) { - this.sid = sid; - } - + private double jd; + + private double dec[]; + + private double ra[]; + + private double sid[]; + + private double dra[]; + + private double rsum[]; + + public Astro() { + dec = new double[3]; + ra = new double[3]; + sid = new double[3]; + dra = new double[3]; + rsum = new double[3]; + } + + public double[] getDec() { + return dec; + } + + public void setDec(double[] dec) { + this.dec = dec; + } + + public double[] getDra() { + return dra; + } + + public void setDra(double[] dra) { + this.dra = dra; + } + + public double getJd() { + return jd; + } + + public void setJd(double jd) { + this.jd = jd; + } + + public double[] getRa() { + return ra; + } + + public void setRa(double[] ra) { + this.ra = ra; + } + + public double[] getRsum() { + return rsum; + } + + public void setRsum(double[] rsum) { + this.rsum = rsum; + } + + public double[] getSid() { + return sid; + } + + public void setSid(double[] sid) { + this.sid = sid; + } + } diff --git a/src/org/arabeyes/itl/prayer/astro/AstroDay.java b/src/org/arabeyes/itl/prayer/astro/AstroDay.java index c1feb02..b6308f3 100644 --- a/src/org/arabeyes/itl/prayer/astro/AstroDay.java +++ b/src/org/arabeyes/itl/prayer/astro/AstroDay.java @@ -1,54 +1,54 @@ package org.arabeyes.itl.prayer.astro; public class AstroDay { - private double dec; - - private double ra; - - private double sidtime; - - private double dra; - - private double rsum; - - public double getDec() { - return dec; - } - - public void setDec(double dec) { - this.dec = dec; - } - - public double getDra() { - return dra; - } - - public void setDra(double dra) { - this.dra = dra; - } - - public double getRa() { - return ra; - } - - public void setRa(double ra) { - this.ra = ra; - } - - public double getRsum() { - return rsum; - } - - public void setRsum(double rsum) { - this.rsum = rsum; - } - - public double getSidtime() { - return sidtime; - } - - public void setSidtime(double sidtime) { - this.sidtime = sidtime; - } - + private double dec; + + private double ra; + + private double sidtime; + + private double dra; + + private double rsum; + + public double getDec() { + return dec; + } + + public void setDec(double dec) { + this.dec = dec; + } + + public double getDra() { + return dra; + } + + public void setDra(double dra) { + this.dra = dra; + } + + public double getRa() { + return ra; + } + + public void setRa(double ra) { + this.ra = ra; + } + + public double getRsum() { + return rsum; + } + + public void setRsum(double rsum) { + this.rsum = rsum; + } + + public double getSidtime() { + return sidtime; + } + + public void setSidtime(double sidtime) { + this.sidtime = sidtime; + } + } diff --git a/src/org/arabeyes/itl/prayer/astro/AstroLib.java b/src/org/arabeyes/itl/prayer/astro/AstroLib.java index 4016dac..9ecf578 100644 --- a/src/org/arabeyes/itl/prayer/astro/AstroLib.java +++ b/src/org/arabeyes/itl/prayer/astro/AstroLib.java @@ -8,484 +8,484 @@ * */ public class AstroLib { - static final double L0[][] = { { 175347046, 0, 0 }, - { 3341656, 4.6692568, 6283.07585 }, { 34894, 4.6261, 12566.1517 }, - { 3497, 2.7441, 5753.3849 }, { 3418, 2.8289, 3.5231 }, - { 3136, 3.6277, 77713.7715 }, { 2676, 4.4181, 7860.4194 }, - { 2343, 6.1352, 3930.2097 }, { 1324, 0.7425, 11506.7698 }, - { 1273, 2.0371, 529.691 }, { 1199, 1.1096, 1577.3435 }, - { 990, 5.233, 5884.927 }, { 902, 2.045, 26.298 }, - { 857, 3.508, 398.149 }, { 780, 1.179, 5223.694 }, - { 753, 2.533, 5507.553 }, { 505, 4.583, 18849.228 }, - { 492, 4.205, 775.523 }, { 357, 2.92, 0.067 }, - { 317, 5.849, 11790.629 }, { 284, 1.899, 796.298 }, - { 271, 0.315, 10977.079 }, { 243, 0.345, 5486.778 }, - { 206, 4.806, 2544.314 }, { 205, 1.869, 5573.143 }, - { 202, 2.4458, 6069.777 }, { 156, 0.833, 213.299 }, - { 132, 3.411, 2942.463 }, { 126, 1.083, 20.775 }, - { 115, 0.645, 0.98 }, { 103, 0.636, 4694.003 }, - { 102, 0.976, 15720.839 }, { 102, 4.267, 7.114 }, - { 99, 6.21, 2146.17 }, { 98, 0.68, 155.42 }, - { 86, 5.98, 161000.69 }, { 85, 1.3, 6275.96 }, - { 85, 3.67, 71430.7 }, { 80, 1.81, 17260.15 }, - { 79, 3.04, 12036.46 }, { 71, 1.76, 5088.63 }, - { 74, 3.5, 3154.69 }, { 74, 4.68, 801.82 }, { 70, 0.83, 9437.76 }, - { 62, 3.98, 8827.39 }, { 61, 1.82, 7084.9 }, { 57, 2.78, 6286.6 }, - { 56, 4.39, 14143.5 }, { 56, 3.47, 6279.55 }, - { 52, 0.19, 12139.55 }, { 52, 1.33, 1748.02 }, - { 51, 0.28, 5856.48 }, { 49, 0.49, 1194.45 }, - { 41, 5.37, 8429.24 }, { 41, 2.4, 19651.05 }, - { 39, 6.17, 10447.39 }, { 37, 6.04, 10213.29 }, - { 37, 2.57, 1059.38 }, { 36, 1.71, 2352.87 }, - { 36, 1.78, 6812.77 }, { 33, 0.59, 17789.85 }, - { 30, 0.44, 83996.85 }, { 30, 2.74, 1349.87 }, - { 25, 3.16, 4690.48 } }; - - static final double L1[][] = { { 628331966747.0, 0, 0 }, - { 206059, 2.678235, 6283.07585 }, { 4303, 2.6351, 12566.1517 }, - { 425, 1.59, 3.523 }, { 119, 5.796, 26.298 }, - { 109, 2.966, 1577.344 }, { 93, 2.59, 18849.23 }, - { 72, 1.14, 529.69 }, { 68, 1.87, 398.15 }, { 67, 4.41, 5507.55 }, - { 59, 2.89, 5223.69 }, { 56, 2.17, 155.42 }, { 45, 0.4, 796.3 }, - { 36, 0.47, 775.52 }, { 29, 2.65, 7.11 }, { 21, 5.34, 0.98 }, - { 19, 1.85, 5486.78 }, { 19, 4.97, 213.3 }, { 17, 2.99, 6275.96 }, - { 16, 0.03, 2544.31 }, { 16, 1.43, 2146.17 }, - { 15, 1.21, 10977.08 }, { 12, 2.83, 1748.02 }, - { 12, 3.26, 5088.63 }, { 12, 5.27, 1194.45 }, { 12, 2.08, 4694 }, - { 11, 0.77, 553.57 }, { 10, 1.3, 3286.6 }, { 10, 4.24, 1349.87 }, - { 9, 2.7, 242.73 }, { 9, 5.64, 951.72 }, { 8, 5.3, 2352.87 }, - { 6, 2.65, 9437.76 }, { 6, 4.67, 4690.48 } }; - - static final double L2[][] = { { 52919, 0, 0 }, - { 8720, 1.0721, 6283.0758 }, { 309, 0.867, 12566.152 }, - { 27, 0.05, 3.52 }, { 16, 5.19, 26.3 }, { 16, 3.68, 155.42 }, - { 10, 0.76, 18849.23 }, { 9, 2.06, 77713.77 }, { 7, 0.83, 775.52 }, - { 5, 4.66, 1577.34 }, { 4, 1.03, 7.11 }, { 4, 3.44, 5573.14 }, - { 3, 5.14, 796.3 }, { 3, 6.05, 5507.55 }, { 3, 1.19, 242.73 }, - { 3, 6.12, 529.69 }, { 3, 0.31, 398.15 }, { 3, 2.28, 553.57 }, - { 2, 4.38, 5223.69 }, { 2, 3.75, 0.98 } }; - - static final double L3[][] = { { 289, 5.844, 6283.076 }, { 35, 0, 0 }, - { 17, 5.49, 12566.15 }, { 3, 5.2, 155.42 }, { 1, 4.72, 3.52 }, - { 1, 5.3, 18849.23 }, { 1, 5.97, 242.73 } }; - - static final double L4[][] = { { 114.0, 3.142, 0.0 }, - { 8.0, 4.13, 6283.08 }, { 1.0, 3.84, 12566.15 } }; - - static final double L5[][] = { { 1, 3.14, 0 } }; - - static final double B0[][] = { - - { 280, 3.199, 84334.662 }, { 102, 5.422, 5507.553 }, { 80, 3.88, 5223.69 }, - { 44, 3.7, 2352.87 }, { 32, 4, 1577.34 } }; - - static final double B1[][] = { - - { 9, 3.9, 5507.55 }, { 6, 1.73, 5223.69 } }; - - static final double R0[][] = { { 100013989, 0, 0 }, - { 1670700, 3.0984635, 6283.07585 }, { 13956, 3.05525, 12566.1517 }, - { 3084, 5.1985, 77713.7715 }, { 1628, 1.1739, 5753.3849 }, - { 1576, 2.8469, 7860.4194 }, { 925, 5.453, 11506.77 }, - { 542, 4.564, 3930.21 }, { 472, 3.661, 5884.927 }, - { 346, 0.964, 5507.553 }, { 329, 5.9, 5223.694 }, - { 307, 0.299, 5573.143 }, { 243, 4.273, 11790.629 }, - { 212, 5.847, 1577.344 }, { 186, 5.022, 10977.079 }, - { 175, 3.012, 18849.228 }, { 110, 5.055, 5486.778 }, - { 98, 0.89, 6069.78 }, { 86, 5.69, 15720.84 }, - { 86, 1.27, 161000.69 }, { 85, 0.27, 17260.15 }, - { 63, 0.92, 529.69 }, { 57, 2.01, 83996.85 }, - { 56, 5.24, 71430.7 }, { 49, 3.25, 2544.31 }, { 47, 2.58, 775.52 }, - { 45, 5.54, 9437.76 }, { 43, 6.01, 6275.96 }, { 39, 5.36, 4694 }, - { 38, 2.39, 8827.39 }, { 37, 0.83, 19651.05 }, - { 37, 4.9, 12139.55 }, { 36, 1.67, 12036.46 }, - { 35, 1.84, 2942.46 }, { 33, 0.24, 7084.9 }, { 32, 0.18, 5088.63 }, - { 32, 1.78, 398.15 }, { 28, 1.21, 6286.6 }, { 28, 1.9, 6279.55 }, - { 26, 4.59, 10447.39 } }; - - static final double R1[][] = { - - { 103019, 1.10749, 6283.07585 }, { 1721, 1.0644, 12566.1517 }, - { 702, 3.142, 0 }, { 32, 1.02, 18849.23 }, { 31, 2.84, 5507.55 }, - { 25, 1.32, 5223.69 }, { 18, 1.42, 1577.34 }, - { 10, 5.91, 10977.08 }, { 9, 1.42, 6275.96 }, { 9, 0.27, 5486.78 } }; - - static final double R2[][] = { - - { 4359, 5.7846, 6283.0758 }, { 124, 5.579, 12566.152 }, { 12, 3.14, 0 }, - { 9, 3.63, 77713.77 }, { 6, 1.87, 5573.14 }, { 3, 5.47, 18849 } - - }; - - static final double R3[][] = { { 145, 4.273, 6283.076 }, - { 7, 3.92, 12566.15 } }; - - static final double R4[] = { 4, 2.56, 6283.08 }; - - static final double PE[][] = { { -171996, -174.2, 92025, 8.9 }, - { -13187, -1.6, 5736, -3.1 }, { -2274, -0.2, 977, -0.5 }, - { 2062, 0.2, -895, 0.5 }, { 1426, -3.4, 54, -0.1 }, - { 712, 0.1, -7, 0 }, { -517, 1.2, 224, -0.6 }, - { -386, -0.4, 200, 0 }, { -301, 0, 129, -0.1 }, - { 217, -0.5, -95, 0.3 }, { -158, 0, 0, 0 }, { 129, 0.1, -70, 0 }, - { 123, 0, -53, 0 }, { 63, 0, 0, 0 }, { 63, 0.1, -33, 0 }, - { -59, 0, 26, 0 }, { -58, -0.1, 32, 0 }, { -51, 0, 27, 0 }, - { 48, 0, 0, 0 }, { 46, 0, -24, 0 }, { -38, 0, 16, 0 }, - { -31, 0, 13, 0 }, { 29, 0, 0, 0 }, { 29, 0, -12, 0 }, - { 26, 0, 0, 0 }, { -22, 0, 0, 0 }, { 21, 0, -10, 0 }, - { 17, -0.1, 0, 0 }, { 16, 0, -8, 0 }, { -16, 0.1, 7, 0 }, - { -15, 0, 9, 0 }, { -13, 0, 7, 0 }, { -12, 0, 6, 0 }, - { 11, 0, 0, 0 }, { -10, 0, 5, 0 }, { -8, 0, 3, 0 }, - { 7, 0, -3, 0 }, { -7, 0, 0, 0 }, { -7, 0, 3, 0 }, { -7, 0, 3, 0 }, - { 6, 0, 0, 0 }, { 6, 0, -3, 0 }, { 6, 0, -3, 0 }, { -6, 0, 3, 0 }, - { -6, 0, 3, 0 }, { 5, 0, 0, 0 }, { -5, 0, 3, 0 }, { -5, 0, 3, 0 }, - { -5, 0, 3, 0 }, { 4, 0, 0, 0 }, { 4, 0, 0, 0 }, { 4, 0, 0, 0 }, - { -4, 0, 0, 0 }, { -4, 0, 0, 0 }, { -4, 0, 0, 0 }, { 3, 0, 0, 0 }, - { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, - { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 } }; - - static final int SINCOEFF[][] = { { 0, 0, 0, 0, 1 }, { -2, 0, 0, 2, 2 }, - { 0, 0, 0, 2, 2 }, { 0, 0, 0, 0, 2 }, { 0, 1, 0, 0, 0 }, - { 0, 0, 1, 0, 0 }, { -2, 1, 0, 2, 2 }, { 0, 0, 0, 2, 1 }, - { 0, 0, 1, 2, 2 }, { -2, -1, 0, 2, 2 }, { -2, 0, 1, 0, 0 }, - { -2, 0, 0, 2, 1 }, { 0, 0, -1, 2, 2 }, { 2, 0, 0, 0, 0 }, - { 0, 0, 1, 0, 1 }, { 2, 0, -1, 2, 2 }, { 0, 0, -1, 0, 1 }, - { 0, 0, 1, 2, 1 }, { -2, 0, 2, 0, 0 }, { 0, 0, -2, 2, 1 }, - { 2, 0, 0, 2, 2 }, { 0, 0, 2, 2, 2 }, { 0, 0, 2, 0, 0 }, - { -2, 0, 1, 2, 2 }, { 0, 0, 0, 2, 0 }, { -2, 0, 0, 2, 0 }, - { 0, 0, -1, 2, 1 }, { 0, 2, 0, 0, 0 }, { 2, 0, -1, 0, 1 }, - { -2, 2, 0, 2, 2 }, { 0, 1, 0, 0, 1 }, { -2, 0, 1, 0, 1 }, - { 0, -1, 0, 0, 1 }, { 0, 0, 2, -2, 0 }, { 2, 0, -1, 2, 1 }, - { 2, 0, 1, 2, 2 }, { 0, 1, 0, 2, 2 }, { -2, 1, 1, 0, 0 }, - { 0, -1, 0, 2, 2 }, { 2, 0, 0, 2, 1 }, { 2, 0, 1, 0, 0 }, - { -2, 0, 2, 2, 2 }, { -2, 0, 1, 2, 1 }, { 2, 0, -2, 0, 1 }, - { 2, 0, 0, 0, 1 }, { 0, -1, 1, 0, 0 }, { -2, -1, 0, 2, 1 }, - { -2, 0, 0, 0, 1 }, { 0, 0, 2, 2, 1 }, { -2, 0, 2, 0, 1 }, - { -2, 1, 0, 2, 1 }, { 0, 0, 1, -2, 0 }, { -1, 0, 1, 0, 0 }, - { -2, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 }, { 0, 0, 1, 2, 0 }, - { 0, 0, -2, 2, 2 }, { -1, -1, 1, 0, 0 }, { 0, 1, 1, 0, 0 }, - { 0, -1, 1, 2, 2 }, { 2, -1, -1, 2, 2 }, { 0, 0, 3, 2, 2 }, - { 2, -1, 0, 2, 2 } }; - - public static double getRefraction(final Location loc, double sunAlt) { - double part1, part2; - - part1 = (loc.getPressure() / 1010.0) - * (283 / (273 + loc.getTemperature())); - part2 = 1.02 / (Utils.radToDeg(Math.tan(Utils.degToRad(sunAlt + (10.3/(sunAlt + 5.11))))) + 0.0019279); - return (part1 * part2) / 60.0; - } - - public static double getJulianDay(final SimpleGregorianDate date, double gmt) { - - double jdB = 0, jdY, jdM, JD; - - jdY = date.getYear(); - jdM = date.getMonthCompat(); - - if (date.getMonthCompat() <= 2) { - jdY--; - jdM += 12; - } - - if (date.getYear() < 1) - jdY++; - - if ((date.getYear() > 1582) - || ((date.getYear() == 1582) && ((date.getMonthCompat() > 10) || ((date - .getMonthCompat() == 10) && (date.getDay() >= 4))))) - jdB = 2 - Math.floor(jdY / 100.0) + Math.floor((jdY / 100.0) / 4.0); - - JD = Math.floor(365.25 * (jdY + 4716.0)) - + Math.floor(30.6001 * (jdM + 1)) + (date.getDay() + (-gmt) / 24.0) - + jdB - 1524.5; - - return JD; - } - - public static void getAstroValuesByDay(double julianDay, - final Location loc, Astro astro, Astro topAstro) { - AstroDay ad = new AstroDay(); - - if (astro.getJd() == julianDay - 1) { - astro.getRa()[0] = astro.getRa()[1]; - - astro.getRa()[1] = astro.getRa()[2]; - astro.getDec()[0] = astro.getDec()[1]; - astro.getDec()[1] = astro.getDec()[2]; - astro.getSid()[0] = astro.getSid()[1]; - astro.getSid()[1] = astro.getSid()[2]; - astro.getDra()[0] = astro.getDra()[1]; - astro.getDra()[1] = astro.getDra()[2]; - astro.getRsum()[0] = astro.getRsum()[1]; - astro.getRsum()[1] = astro.getRsum()[2]; - computeAstroDay(julianDay + 1, ad); - astro.getRa()[2] = ad.getRa(); - astro.getDec()[2] = ad.getDec(); - astro.getSid()[2] = ad.getSidtime(); - astro.getDra()[2] = ad.getDra(); - astro.getRsum()[2] = ad.getRsum(); - } else if (astro.getJd() == julianDay + 1) { - - astro.getRa()[2] = astro.getRa()[1]; - astro.getRa()[1] = astro.getRa()[0]; - astro.getDec()[2] = astro.getDec()[1]; - astro.getDec()[1] = astro.getDec()[0]; - astro.getSid()[2] = astro.getSid()[1]; - astro.getSid()[1] = astro.getSid()[0]; - astro.getDra()[2] = astro.getDra()[1]; - astro.getDra()[1] = astro.getDra()[0]; - astro.getRsum()[2] = astro.getRsum()[1]; - astro.getRsum()[1] = astro.getRsum()[0]; - computeAstroDay(julianDay - 1, ad); - astro.getRa()[0] = ad.getRa(); - astro.getDec()[0] = ad.getDec(); - astro.getSid()[0] = ad.getSidtime(); - astro.getDra()[0] = ad.getDra(); - astro.getRsum()[0] = ad.getRsum(); - } else if (astro.getJd() != julianDay) { - computeAstroDay(julianDay - 1, ad); - astro.getRa()[0] = ad.getRa(); - astro.getDec()[0] = ad.getDec(); - astro.getSid()[0] = ad.getSidtime(); - astro.getDra()[0] = ad.getDra(); - astro.getRsum()[0] = ad.getRsum(); - computeAstroDay(julianDay, ad); - astro.getRa()[1] = ad.getRa(); - astro.getDec()[1] = ad.getDec(); - astro.getSid()[1] = ad.getSidtime(); - astro.getDra()[1] = ad.getDra(); - astro.getRsum()[1] = ad.getRsum(); - computeAstroDay(julianDay + 1, ad); - astro.getRa()[2] = ad.getRa(); - astro.getDec()[2] = ad.getDec(); - astro.getSid()[2] = ad.getSidtime(); - astro.getDra()[2] = ad.getDra(); - astro.getRsum()[2] = ad.getRsum(); - } - - astro.setJd(julianDay); - computeTopAstro(loc, astro, topAstro); - - } - - public static void computeAstroDay(double JD, AstroDay astroday) { - - int i = 0; - double R, Gg, G; - - double tL, L; - double tB, B; - - double X0, X1, X2, X3, X4; - - double U, E0, E, lamda, V0, V; - - double RAn, RAd, RA, DEC; - - double B0sum = 0, B1sum = 0; - double R0sum = 0, R1sum = 0, R2sum = 0, R3sum = 0, R4sum = 0; - double L0sum = 0, L1sum = 0, L2sum = 0, L3sum = 0, L4sum = 0, L5sum = 0; - - double xsum = 0, psi = 0, epsilon = 0; - double deltaPsi, deltaEps; - - double JC = (JD - 2451545) / 36525.0; - double JM = JC / 10.0; - double JM2 = Math.pow(JM, 2); - double JM3 = Math.pow(JM, 3); - double JM4 = Math.pow(JM, 4); - double JM5 = Math.pow(JM, 5); - - for (i = 0; i < 64; i++) - L0sum += L0[i][0] * Math.cos(L0[i][1] + L0[i][2] * JM); - for (i = 0; i < 34; i++) - L1sum += L1[i][0] * Math.cos(L1[i][1] + L1[i][2] * JM); - for (i = 0; i < 20; i++) - L2sum += L2[i][0] * Math.cos(L2[i][1] + L2[i][2] * JM); - for (i = 0; i < 7; i++) - L3sum += L3[i][0] * Math.cos(L3[i][1] + L3[i][2] * JM); - for (i = 0; i < 3; i++) - L4sum += L4[i][0] * Math.cos(L4[i][1] + L4[i][2] * JM); - L5sum = L5[0][0] * Math.cos(L5[0][1] + L5[0][2] * JM); - - tL = (L0sum + (L1sum * JM) + (L2sum * JM2) + (L3sum * JM3) - + (L4sum * JM4) + (L5sum * JM5)) - / Math.pow(10, 8); - - L = limitAngle(Utils.radToDeg(tL)); - - for (i = 0; i < 5; i++) - B0sum += B0[i][0] * Math.cos(B0[i][1] + B0[i][2] * JM); - for (i = 0; i < 2; i++) - B1sum += B1[i][0] * Math.cos(B1[i][1] + B1[i][2] * JM); - - tB = (B0sum + (B1sum * JM)) / Math.pow(10, 8); - B = Utils.radToDeg(tB); - - for (i = 0; i < 40; i++) - R0sum += R0[i][0] * Math.cos(R0[i][1] + R0[i][2] * JM); - for (i = 0; i < 10; i++) - R1sum += R1[i][0] * Math.cos(R1[i][1] + R1[i][2] * JM); - for (i = 0; i < 6; i++) - R2sum += R2[i][0] * Math.cos(R2[i][1] + R2[i][2] * JM); - for (i = 0; i < 2; i++) - R3sum += R3[i][0] * Math.cos(R3[i][1] + R3[i][2] * JM); - - R4sum = R4[0] * Math.cos(R4[1] + R4[2] * JM); - - R = (R0sum + (R1sum * JM) + (R2sum * JM2) + (R3sum * JM3) + (R4sum * JM4)) - / Math.pow(10, 8); - - G = limitAngle((L + 180)); - Gg = -B; - - X0 = 297.85036 + (445267.111480 * JC) - (0.0019142 * Math.pow(JC, 2)) - + Math.pow(JC, 3) / 189474.0; - X1 = 357.52772 + (35999.050340 * JC) - (0.0001603 * Math.pow(JC, 2)) - - Math.pow(JC, 3) / 300000.0; - X2 = 134.96298 + (477198.867398 * JC) + (0.0086972 * Math.pow(JC, 2)) - + Math.pow(JC, 3) / 56250.0; - X3 = 93.27191 + (483202.017538 * JC) - (0.0036825 * Math.pow(JC, 2)) - + Math.pow(JC, 3) / 327270.0; - X4 = 125.04452 - (1934.136261 * JC) + (0.0020708 * Math.pow(JC, 2)) - + Math.pow(JC, 3) / 450000.0; - - for (i = 0; i < 63; i++) { - xsum += X0 * SINCOEFF[i][0]; - xsum += X1 * SINCOEFF[i][1]; - xsum += X2 * SINCOEFF[i][2]; - xsum += X3 * SINCOEFF[i][3]; - xsum += X4 * SINCOEFF[i][4]; - psi += (PE[i][0] + JC * PE[i][1]) - * Math.sin(Utils.degToRad(xsum)); - epsilon += (PE[i][2] + JC * PE[i][3]) - * Math.cos(Utils.degToRad(xsum)); - xsum = 0; - } - - deltaPsi = psi / 36000000.0; - deltaEps = epsilon / 36000000.0; - - U = JM / 10.0; - E0 = 84381.448 - 4680.93 * U - 1.55 * Math.pow(U, 2) + 1999.25 - * Math.pow(U, 3) - 51.38 * Math.pow(U, 4) - 249.67 - * Math.pow(U, 5) - 39.05 * Math.pow(U, 6) + 7.12 - * Math.pow(U, 7) + 27.87 * Math.pow(U, 8) + 5.79 - * Math.pow(U, 9) + 2.45 * Math.pow(U, 10); - E = E0 / 3600.0 + deltaEps; - lamda = G + deltaPsi + (-20.4898 / (3600.0 * R)); - - V0 = 280.46061837 + 360.98564736629 * (JD - 2451545) + 0.000387933 - * Math.pow(JC, 2) - Math.pow(JC, 3) / 38710000.0; - V = limitAngle(V0) + deltaPsi * Math.cos(Utils.degToRad(E)); - - RAn = Math.sin(Utils.degToRad(lamda)) * Math.cos(Utils.degToRad(E)) - - Math.tan(Utils.degToRad(Gg)) - * Math.sin(Utils.degToRad(E)); - RAd = Math.cos(Utils.degToRad(lamda)); - RA = limitAngle(Utils.radToDeg(Math.atan2(RAn, RAd))); - - DEC = Math.asin(Math.sin(Utils.degToRad(Gg)) - * Math.cos(Utils.degToRad(E)) - + Math.cos(Utils.degToRad(Gg)) - * Math.sin(Utils.degToRad(E)) - * Math.sin(Utils.degToRad(lamda))); - - astroday.setRa(RA); - astroday.setDec(DEC); - astroday.setSidtime(V); - astroday.setDra(0); - astroday.setRsum(R); - - } - - public static void computeTopAstro(final Location loc, final Astro astro, - Astro topAstro) { - int i; - double lHour, SP; - double tU, tCos, tSin, tRA0, tRA, tDEC; - - for (i = 0; i < 3; i++) { - lHour = limitAngle(astro.getSid()[i] + loc.getDegreeLong() - - astro.getRa()[i]); - - SP = 8.794 / (3600 * astro.getRsum()[i]); - - tU = Math.atan(0.99664719 * Math.tan(Utils.degToRad(loc - .getDegreeLat()))); - - tCos = Math.cos(tU) + ((loc.getSeaLevel()) / 6378140.0) - * Math.cos(Utils.degToRad(loc.getDegreeLat())); - - tSin = 0.99664719 * Math.sin(tU) + (loc.getSeaLevel() / 6378140.0) - * Math.sin(Utils.degToRad(loc.getDegreeLat())); - - tRA0 = (((-tCos) * Math.sin(Utils.degToRad(SP)) * Math.sin(Utils - .degToRad(lHour))) / (Math.cos(astro.getDec()[i]) - tCos - * Math.sin(Utils.degToRad(SP)) - * Math.cos(Utils.degToRad(lHour)))); - - tRA = astro.getRa()[i] + Utils.radToDeg(tRA0); - - tDEC = Utils.radToDeg(Math.atan2( - (Math.sin(astro.getDec()[i]) - tSin - * Math.sin(Utils.degToRad(SP))) - * Math.cos(tRA0), Math.cos(astro.getDec()[i]) - - tCos * Math.sin(Utils.degToRad(SP)) - * Math.cos(Utils.degToRad(lHour)))); - - topAstro.getRa()[i] = tRA; - topAstro.getDec()[i] = tDEC; - topAstro.getSid()[i] = astro.getSid()[i]; - topAstro.getDra()[i] = tRA0; - topAstro.getRsum()[i] = astro.getRsum()[i]; - - } - - } - - public static double limitAngle(double L) { - double F; - L /= 360.0; - F = L - Math.floor(L); - if (F > 0) - return 360 * F; - else if (F < 0) - return 360 - 360 * F; - else - return L; - } - - public static double limitAngle180(double L) { - double F; - L /= 180.0; - F = L - Math.floor(L); - if (F > 0) - return 180 * F; - else if (F < 0) - return 180 - 180 * F; - else - return L; - } - - public static double limitAngle111(double L) { - double F; - F = L - Math.floor(L); - if (F < 0) - return F += 1; - return F; - } - - public static double limitAngle180between(double L) { - double F; - L /= 360.0; - F = (L - Math.floor(L)) * 360.0; - if (F < -180) - F += 360; - else if (F > 180) - F -= 360; - return F; - } - + static final double L0[][] = { { 175347046, 0, 0 }, + { 3341656, 4.6692568, 6283.07585 }, { 34894, 4.6261, 12566.1517 }, + { 3497, 2.7441, 5753.3849 }, { 3418, 2.8289, 3.5231 }, + { 3136, 3.6277, 77713.7715 }, { 2676, 4.4181, 7860.4194 }, + { 2343, 6.1352, 3930.2097 }, { 1324, 0.7425, 11506.7698 }, + { 1273, 2.0371, 529.691 }, { 1199, 1.1096, 1577.3435 }, + { 990, 5.233, 5884.927 }, { 902, 2.045, 26.298 }, + { 857, 3.508, 398.149 }, { 780, 1.179, 5223.694 }, + { 753, 2.533, 5507.553 }, { 505, 4.583, 18849.228 }, + { 492, 4.205, 775.523 }, { 357, 2.92, 0.067 }, + { 317, 5.849, 11790.629 }, { 284, 1.899, 796.298 }, + { 271, 0.315, 10977.079 }, { 243, 0.345, 5486.778 }, + { 206, 4.806, 2544.314 }, { 205, 1.869, 5573.143 }, + { 202, 2.4458, 6069.777 }, { 156, 0.833, 213.299 }, + { 132, 3.411, 2942.463 }, { 126, 1.083, 20.775 }, + { 115, 0.645, 0.98 }, { 103, 0.636, 4694.003 }, + { 102, 0.976, 15720.839 }, { 102, 4.267, 7.114 }, + { 99, 6.21, 2146.17 }, { 98, 0.68, 155.42 }, + { 86, 5.98, 161000.69 }, { 85, 1.3, 6275.96 }, + { 85, 3.67, 71430.7 }, { 80, 1.81, 17260.15 }, + { 79, 3.04, 12036.46 }, { 71, 1.76, 5088.63 }, + { 74, 3.5, 3154.69 }, { 74, 4.68, 801.82 }, { 70, 0.83, 9437.76 }, + { 62, 3.98, 8827.39 }, { 61, 1.82, 7084.9 }, { 57, 2.78, 6286.6 }, + { 56, 4.39, 14143.5 }, { 56, 3.47, 6279.55 }, + { 52, 0.19, 12139.55 }, { 52, 1.33, 1748.02 }, + { 51, 0.28, 5856.48 }, { 49, 0.49, 1194.45 }, + { 41, 5.37, 8429.24 }, { 41, 2.4, 19651.05 }, + { 39, 6.17, 10447.39 }, { 37, 6.04, 10213.29 }, + { 37, 2.57, 1059.38 }, { 36, 1.71, 2352.87 }, + { 36, 1.78, 6812.77 }, { 33, 0.59, 17789.85 }, + { 30, 0.44, 83996.85 }, { 30, 2.74, 1349.87 }, + { 25, 3.16, 4690.48 } }; + + static final double L1[][] = { { 628331966747.0, 0, 0 }, + { 206059, 2.678235, 6283.07585 }, { 4303, 2.6351, 12566.1517 }, + { 425, 1.59, 3.523 }, { 119, 5.796, 26.298 }, + { 109, 2.966, 1577.344 }, { 93, 2.59, 18849.23 }, + { 72, 1.14, 529.69 }, { 68, 1.87, 398.15 }, { 67, 4.41, 5507.55 }, + { 59, 2.89, 5223.69 }, { 56, 2.17, 155.42 }, { 45, 0.4, 796.3 }, + { 36, 0.47, 775.52 }, { 29, 2.65, 7.11 }, { 21, 5.34, 0.98 }, + { 19, 1.85, 5486.78 }, { 19, 4.97, 213.3 }, { 17, 2.99, 6275.96 }, + { 16, 0.03, 2544.31 }, { 16, 1.43, 2146.17 }, + { 15, 1.21, 10977.08 }, { 12, 2.83, 1748.02 }, + { 12, 3.26, 5088.63 }, { 12, 5.27, 1194.45 }, { 12, 2.08, 4694 }, + { 11, 0.77, 553.57 }, { 10, 1.3, 3286.6 }, { 10, 4.24, 1349.87 }, + { 9, 2.7, 242.73 }, { 9, 5.64, 951.72 }, { 8, 5.3, 2352.87 }, + { 6, 2.65, 9437.76 }, { 6, 4.67, 4690.48 } }; + + static final double L2[][] = { { 52919, 0, 0 }, + { 8720, 1.0721, 6283.0758 }, { 309, 0.867, 12566.152 }, + { 27, 0.05, 3.52 }, { 16, 5.19, 26.3 }, { 16, 3.68, 155.42 }, + { 10, 0.76, 18849.23 }, { 9, 2.06, 77713.77 }, { 7, 0.83, 775.52 }, + { 5, 4.66, 1577.34 }, { 4, 1.03, 7.11 }, { 4, 3.44, 5573.14 }, + { 3, 5.14, 796.3 }, { 3, 6.05, 5507.55 }, { 3, 1.19, 242.73 }, + { 3, 6.12, 529.69 }, { 3, 0.31, 398.15 }, { 3, 2.28, 553.57 }, + { 2, 4.38, 5223.69 }, { 2, 3.75, 0.98 } }; + + static final double L3[][] = { { 289, 5.844, 6283.076 }, { 35, 0, 0 }, + { 17, 5.49, 12566.15 }, { 3, 5.2, 155.42 }, { 1, 4.72, 3.52 }, + { 1, 5.3, 18849.23 }, { 1, 5.97, 242.73 } }; + + static final double L4[][] = { { 114.0, 3.142, 0.0 }, + { 8.0, 4.13, 6283.08 }, { 1.0, 3.84, 12566.15 } }; + + static final double L5[][] = { { 1, 3.14, 0 } }; + + static final double B0[][] = { + + { 280, 3.199, 84334.662 }, { 102, 5.422, 5507.553 }, { 80, 3.88, 5223.69 }, + { 44, 3.7, 2352.87 }, { 32, 4, 1577.34 } }; + + static final double B1[][] = { + + { 9, 3.9, 5507.55 }, { 6, 1.73, 5223.69 } }; + + static final double R0[][] = { { 100013989, 0, 0 }, + { 1670700, 3.0984635, 6283.07585 }, { 13956, 3.05525, 12566.1517 }, + { 3084, 5.1985, 77713.7715 }, { 1628, 1.1739, 5753.3849 }, + { 1576, 2.8469, 7860.4194 }, { 925, 5.453, 11506.77 }, + { 542, 4.564, 3930.21 }, { 472, 3.661, 5884.927 }, + { 346, 0.964, 5507.553 }, { 329, 5.9, 5223.694 }, + { 307, 0.299, 5573.143 }, { 243, 4.273, 11790.629 }, + { 212, 5.847, 1577.344 }, { 186, 5.022, 10977.079 }, + { 175, 3.012, 18849.228 }, { 110, 5.055, 5486.778 }, + { 98, 0.89, 6069.78 }, { 86, 5.69, 15720.84 }, + { 86, 1.27, 161000.69 }, { 85, 0.27, 17260.15 }, + { 63, 0.92, 529.69 }, { 57, 2.01, 83996.85 }, + { 56, 5.24, 71430.7 }, { 49, 3.25, 2544.31 }, { 47, 2.58, 775.52 }, + { 45, 5.54, 9437.76 }, { 43, 6.01, 6275.96 }, { 39, 5.36, 4694 }, + { 38, 2.39, 8827.39 }, { 37, 0.83, 19651.05 }, + { 37, 4.9, 12139.55 }, { 36, 1.67, 12036.46 }, + { 35, 1.84, 2942.46 }, { 33, 0.24, 7084.9 }, { 32, 0.18, 5088.63 }, + { 32, 1.78, 398.15 }, { 28, 1.21, 6286.6 }, { 28, 1.9, 6279.55 }, + { 26, 4.59, 10447.39 } }; + + static final double R1[][] = { + + { 103019, 1.10749, 6283.07585 }, { 1721, 1.0644, 12566.1517 }, + { 702, 3.142, 0 }, { 32, 1.02, 18849.23 }, { 31, 2.84, 5507.55 }, + { 25, 1.32, 5223.69 }, { 18, 1.42, 1577.34 }, + { 10, 5.91, 10977.08 }, { 9, 1.42, 6275.96 }, { 9, 0.27, 5486.78 } }; + + static final double R2[][] = { + + { 4359, 5.7846, 6283.0758 }, { 124, 5.579, 12566.152 }, { 12, 3.14, 0 }, + { 9, 3.63, 77713.77 }, { 6, 1.87, 5573.14 }, { 3, 5.47, 18849 } + + }; + + static final double R3[][] = { { 145, 4.273, 6283.076 }, + { 7, 3.92, 12566.15 } }; + + static final double R4[] = { 4, 2.56, 6283.08 }; + + static final double PE[][] = { { -171996, -174.2, 92025, 8.9 }, + { -13187, -1.6, 5736, -3.1 }, { -2274, -0.2, 977, -0.5 }, + { 2062, 0.2, -895, 0.5 }, { 1426, -3.4, 54, -0.1 }, + { 712, 0.1, -7, 0 }, { -517, 1.2, 224, -0.6 }, + { -386, -0.4, 200, 0 }, { -301, 0, 129, -0.1 }, + { 217, -0.5, -95, 0.3 }, { -158, 0, 0, 0 }, { 129, 0.1, -70, 0 }, + { 123, 0, -53, 0 }, { 63, 0, 0, 0 }, { 63, 0.1, -33, 0 }, + { -59, 0, 26, 0 }, { -58, -0.1, 32, 0 }, { -51, 0, 27, 0 }, + { 48, 0, 0, 0 }, { 46, 0, -24, 0 }, { -38, 0, 16, 0 }, + { -31, 0, 13, 0 }, { 29, 0, 0, 0 }, { 29, 0, -12, 0 }, + { 26, 0, 0, 0 }, { -22, 0, 0, 0 }, { 21, 0, -10, 0 }, + { 17, -0.1, 0, 0 }, { 16, 0, -8, 0 }, { -16, 0.1, 7, 0 }, + { -15, 0, 9, 0 }, { -13, 0, 7, 0 }, { -12, 0, 6, 0 }, + { 11, 0, 0, 0 }, { -10, 0, 5, 0 }, { -8, 0, 3, 0 }, + { 7, 0, -3, 0 }, { -7, 0, 0, 0 }, { -7, 0, 3, 0 }, { -7, 0, 3, 0 }, + { 6, 0, 0, 0 }, { 6, 0, -3, 0 }, { 6, 0, -3, 0 }, { -6, 0, 3, 0 }, + { -6, 0, 3, 0 }, { 5, 0, 0, 0 }, { -5, 0, 3, 0 }, { -5, 0, 3, 0 }, + { -5, 0, 3, 0 }, { 4, 0, 0, 0 }, { 4, 0, 0, 0 }, { 4, 0, 0, 0 }, + { -4, 0, 0, 0 }, { -4, 0, 0, 0 }, { -4, 0, 0, 0 }, { 3, 0, 0, 0 }, + { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, + { -3, 0, 0, 0 }, { -3, 0, 0, 0 }, { -3, 0, 0, 0 } }; + + static final int SINCOEFF[][] = { { 0, 0, 0, 0, 1 }, { -2, 0, 0, 2, 2 }, + { 0, 0, 0, 2, 2 }, { 0, 0, 0, 0, 2 }, { 0, 1, 0, 0, 0 }, + { 0, 0, 1, 0, 0 }, { -2, 1, 0, 2, 2 }, { 0, 0, 0, 2, 1 }, + { 0, 0, 1, 2, 2 }, { -2, -1, 0, 2, 2 }, { -2, 0, 1, 0, 0 }, + { -2, 0, 0, 2, 1 }, { 0, 0, -1, 2, 2 }, { 2, 0, 0, 0, 0 }, + { 0, 0, 1, 0, 1 }, { 2, 0, -1, 2, 2 }, { 0, 0, -1, 0, 1 }, + { 0, 0, 1, 2, 1 }, { -2, 0, 2, 0, 0 }, { 0, 0, -2, 2, 1 }, + { 2, 0, 0, 2, 2 }, { 0, 0, 2, 2, 2 }, { 0, 0, 2, 0, 0 }, + { -2, 0, 1, 2, 2 }, { 0, 0, 0, 2, 0 }, { -2, 0, 0, 2, 0 }, + { 0, 0, -1, 2, 1 }, { 0, 2, 0, 0, 0 }, { 2, 0, -1, 0, 1 }, + { -2, 2, 0, 2, 2 }, { 0, 1, 0, 0, 1 }, { -2, 0, 1, 0, 1 }, + { 0, -1, 0, 0, 1 }, { 0, 0, 2, -2, 0 }, { 2, 0, -1, 2, 1 }, + { 2, 0, 1, 2, 2 }, { 0, 1, 0, 2, 2 }, { -2, 1, 1, 0, 0 }, + { 0, -1, 0, 2, 2 }, { 2, 0, 0, 2, 1 }, { 2, 0, 1, 0, 0 }, + { -2, 0, 2, 2, 2 }, { -2, 0, 1, 2, 1 }, { 2, 0, -2, 0, 1 }, + { 2, 0, 0, 0, 1 }, { 0, -1, 1, 0, 0 }, { -2, -1, 0, 2, 1 }, + { -2, 0, 0, 0, 1 }, { 0, 0, 2, 2, 1 }, { -2, 0, 2, 0, 1 }, + { -2, 1, 0, 2, 1 }, { 0, 0, 1, -2, 0 }, { -1, 0, 1, 0, 0 }, + { -2, 1, 0, 0, 0 }, { 1, 0, 0, 0, 0 }, { 0, 0, 1, 2, 0 }, + { 0, 0, -2, 2, 2 }, { -1, -1, 1, 0, 0 }, { 0, 1, 1, 0, 0 }, + { 0, -1, 1, 2, 2 }, { 2, -1, -1, 2, 2 }, { 0, 0, 3, 2, 2 }, + { 2, -1, 0, 2, 2 } }; + + public static double getRefraction(final Location loc, double sunAlt) { + double part1, part2; + + part1 = (loc.getPressure() / 1010.0) + * (283 / (273 + loc.getTemperature())); + part2 = 1.02 / (Utils.radToDeg(Math.tan(Utils.degToRad(sunAlt + (10.3/(sunAlt + 5.11))))) + 0.0019279); + return (part1 * part2) / 60.0; + } + + public static double getJulianDay(final SimpleGregorianDate date, double gmt) { + + double jdB = 0, jdY, jdM, JD; + + jdY = date.getYear(); + jdM = date.getMonthCompat(); + + if (date.getMonthCompat() <= 2) { + jdY--; + jdM += 12; + } + + if (date.getYear() < 1) + jdY++; + + if ((date.getYear() > 1582) + || ((date.getYear() == 1582) && ((date.getMonthCompat() > 10) || ((date + .getMonthCompat() == 10) && (date.getDay() >= 4))))) + jdB = 2 - Math.floor(jdY / 100.0) + Math.floor((jdY / 100.0) / 4.0); + + JD = Math.floor(365.25 * (jdY + 4716.0)) + + Math.floor(30.6001 * (jdM + 1)) + (date.getDay() + (-gmt) / 24.0) + + jdB - 1524.5; + + return JD; + } + + public static void getAstroValuesByDay(double julianDay, + final Location loc, Astro astro, Astro topAstro) { + AstroDay ad = new AstroDay(); + + if (astro.getJd() == julianDay - 1) { + astro.getRa()[0] = astro.getRa()[1]; + + astro.getRa()[1] = astro.getRa()[2]; + astro.getDec()[0] = astro.getDec()[1]; + astro.getDec()[1] = astro.getDec()[2]; + astro.getSid()[0] = astro.getSid()[1]; + astro.getSid()[1] = astro.getSid()[2]; + astro.getDra()[0] = astro.getDra()[1]; + astro.getDra()[1] = astro.getDra()[2]; + astro.getRsum()[0] = astro.getRsum()[1]; + astro.getRsum()[1] = astro.getRsum()[2]; + computeAstroDay(julianDay + 1, ad); + astro.getRa()[2] = ad.getRa(); + astro.getDec()[2] = ad.getDec(); + astro.getSid()[2] = ad.getSidtime(); + astro.getDra()[2] = ad.getDra(); + astro.getRsum()[2] = ad.getRsum(); + } else if (astro.getJd() == julianDay + 1) { + + astro.getRa()[2] = astro.getRa()[1]; + astro.getRa()[1] = astro.getRa()[0]; + astro.getDec()[2] = astro.getDec()[1]; + astro.getDec()[1] = astro.getDec()[0]; + astro.getSid()[2] = astro.getSid()[1]; + astro.getSid()[1] = astro.getSid()[0]; + astro.getDra()[2] = astro.getDra()[1]; + astro.getDra()[1] = astro.getDra()[0]; + astro.getRsum()[2] = astro.getRsum()[1]; + astro.getRsum()[1] = astro.getRsum()[0]; + computeAstroDay(julianDay - 1, ad); + astro.getRa()[0] = ad.getRa(); + astro.getDec()[0] = ad.getDec(); + astro.getSid()[0] = ad.getSidtime(); + astro.getDra()[0] = ad.getDra(); + astro.getRsum()[0] = ad.getRsum(); + } else if (astro.getJd() != julianDay) { + computeAstroDay(julianDay - 1, ad); + astro.getRa()[0] = ad.getRa(); + astro.getDec()[0] = ad.getDec(); + astro.getSid()[0] = ad.getSidtime(); + astro.getDra()[0] = ad.getDra(); + astro.getRsum()[0] = ad.getRsum(); + computeAstroDay(julianDay, ad); + astro.getRa()[1] = ad.getRa(); + astro.getDec()[1] = ad.getDec(); + astro.getSid()[1] = ad.getSidtime(); + astro.getDra()[1] = ad.getDra(); + astro.getRsum()[1] = ad.getRsum(); + computeAstroDay(julianDay + 1, ad); + astro.getRa()[2] = ad.getRa(); + astro.getDec()[2] = ad.getDec(); + astro.getSid()[2] = ad.getSidtime(); + astro.getDra()[2] = ad.getDra(); + astro.getRsum()[2] = ad.getRsum(); + } + + astro.setJd(julianDay); + computeTopAstro(loc, astro, topAstro); + + } + + public static void computeAstroDay(double JD, AstroDay astroday) { + + int i = 0; + double R, Gg, G; + + double tL, L; + double tB, B; + + double X0, X1, X2, X3, X4; + + double U, E0, E, lamda, V0, V; + + double RAn, RAd, RA, DEC; + + double B0sum = 0, B1sum = 0; + double R0sum = 0, R1sum = 0, R2sum = 0, R3sum = 0, R4sum = 0; + double L0sum = 0, L1sum = 0, L2sum = 0, L3sum = 0, L4sum = 0, L5sum = 0; + + double xsum = 0, psi = 0, epsilon = 0; + double deltaPsi, deltaEps; + + double JC = (JD - 2451545) / 36525.0; + double JM = JC / 10.0; + double JM2 = Math.pow(JM, 2); + double JM3 = Math.pow(JM, 3); + double JM4 = Math.pow(JM, 4); + double JM5 = Math.pow(JM, 5); + + for (i = 0; i < 64; i++) + L0sum += L0[i][0] * Math.cos(L0[i][1] + L0[i][2] * JM); + for (i = 0; i < 34; i++) + L1sum += L1[i][0] * Math.cos(L1[i][1] + L1[i][2] * JM); + for (i = 0; i < 20; i++) + L2sum += L2[i][0] * Math.cos(L2[i][1] + L2[i][2] * JM); + for (i = 0; i < 7; i++) + L3sum += L3[i][0] * Math.cos(L3[i][1] + L3[i][2] * JM); + for (i = 0; i < 3; i++) + L4sum += L4[i][0] * Math.cos(L4[i][1] + L4[i][2] * JM); + L5sum = L5[0][0] * Math.cos(L5[0][1] + L5[0][2] * JM); + + tL = (L0sum + (L1sum * JM) + (L2sum * JM2) + (L3sum * JM3) + + (L4sum * JM4) + (L5sum * JM5)) + / Math.pow(10, 8); + + L = limitAngle(Utils.radToDeg(tL)); + + for (i = 0; i < 5; i++) + B0sum += B0[i][0] * Math.cos(B0[i][1] + B0[i][2] * JM); + for (i = 0; i < 2; i++) + B1sum += B1[i][0] * Math.cos(B1[i][1] + B1[i][2] * JM); + + tB = (B0sum + (B1sum * JM)) / Math.pow(10, 8); + B = Utils.radToDeg(tB); + + for (i = 0; i < 40; i++) + R0sum += R0[i][0] * Math.cos(R0[i][1] + R0[i][2] * JM); + for (i = 0; i < 10; i++) + R1sum += R1[i][0] * Math.cos(R1[i][1] + R1[i][2] * JM); + for (i = 0; i < 6; i++) + R2sum += R2[i][0] * Math.cos(R2[i][1] + R2[i][2] * JM); + for (i = 0; i < 2; i++) + R3sum += R3[i][0] * Math.cos(R3[i][1] + R3[i][2] * JM); + + R4sum = R4[0] * Math.cos(R4[1] + R4[2] * JM); + + R = (R0sum + (R1sum * JM) + (R2sum * JM2) + (R3sum * JM3) + (R4sum * JM4)) + / Math.pow(10, 8); + + G = limitAngle((L + 180)); + Gg = -B; + + X0 = 297.85036 + (445267.111480 * JC) - (0.0019142 * Math.pow(JC, 2)) + + Math.pow(JC, 3) / 189474.0; + X1 = 357.52772 + (35999.050340 * JC) - (0.0001603 * Math.pow(JC, 2)) + - Math.pow(JC, 3) / 300000.0; + X2 = 134.96298 + (477198.867398 * JC) + (0.0086972 * Math.pow(JC, 2)) + + Math.pow(JC, 3) / 56250.0; + X3 = 93.27191 + (483202.017538 * JC) - (0.0036825 * Math.pow(JC, 2)) + + Math.pow(JC, 3) / 327270.0; + X4 = 125.04452 - (1934.136261 * JC) + (0.0020708 * Math.pow(JC, 2)) + + Math.pow(JC, 3) / 450000.0; + + for (i = 0; i < 63; i++) { + xsum += X0 * SINCOEFF[i][0]; + xsum += X1 * SINCOEFF[i][1]; + xsum += X2 * SINCOEFF[i][2]; + xsum += X3 * SINCOEFF[i][3]; + xsum += X4 * SINCOEFF[i][4]; + psi += (PE[i][0] + JC * PE[i][1]) + * Math.sin(Utils.degToRad(xsum)); + epsilon += (PE[i][2] + JC * PE[i][3]) + * Math.cos(Utils.degToRad(xsum)); + xsum = 0; + } + + deltaPsi = psi / 36000000.0; + deltaEps = epsilon / 36000000.0; + + U = JM / 10.0; + E0 = 84381.448 - 4680.93 * U - 1.55 * Math.pow(U, 2) + 1999.25 + * Math.pow(U, 3) - 51.38 * Math.pow(U, 4) - 249.67 + * Math.pow(U, 5) - 39.05 * Math.pow(U, 6) + 7.12 + * Math.pow(U, 7) + 27.87 * Math.pow(U, 8) + 5.79 + * Math.pow(U, 9) + 2.45 * Math.pow(U, 10); + E = E0 / 3600.0 + deltaEps; + lamda = G + deltaPsi + (-20.4898 / (3600.0 * R)); + + V0 = 280.46061837 + 360.98564736629 * (JD - 2451545) + 0.000387933 + * Math.pow(JC, 2) - Math.pow(JC, 3) / 38710000.0; + V = limitAngle(V0) + deltaPsi * Math.cos(Utils.degToRad(E)); + + RAn = Math.sin(Utils.degToRad(lamda)) * Math.cos(Utils.degToRad(E)) + - Math.tan(Utils.degToRad(Gg)) + * Math.sin(Utils.degToRad(E)); + RAd = Math.cos(Utils.degToRad(lamda)); + RA = limitAngle(Utils.radToDeg(Math.atan2(RAn, RAd))); + + DEC = Math.asin(Math.sin(Utils.degToRad(Gg)) + * Math.cos(Utils.degToRad(E)) + + Math.cos(Utils.degToRad(Gg)) + * Math.sin(Utils.degToRad(E)) + * Math.sin(Utils.degToRad(lamda))); + + astroday.setRa(RA); + astroday.setDec(DEC); + astroday.setSidtime(V); + astroday.setDra(0); + astroday.setRsum(R); + + } + + public static void computeTopAstro(final Location loc, final Astro astro, + Astro topAstro) { + int i; + double lHour, SP; + double tU, tCos, tSin, tRA0, tRA, tDEC; + + for (i = 0; i < 3; i++) { + lHour = limitAngle(astro.getSid()[i] + loc.getDegreeLong() + - astro.getRa()[i]); + + SP = 8.794 / (3600 * astro.getRsum()[i]); + + tU = Math.atan(0.99664719 * Math.tan(Utils.degToRad(loc + .getDegreeLat()))); + + tCos = Math.cos(tU) + ((loc.getSeaLevel()) / 6378140.0) + * Math.cos(Utils.degToRad(loc.getDegreeLat())); + + tSin = 0.99664719 * Math.sin(tU) + (loc.getSeaLevel() / 6378140.0) + * Math.sin(Utils.degToRad(loc.getDegreeLat())); + + tRA0 = (((-tCos) * Math.sin(Utils.degToRad(SP)) * Math.sin(Utils + .degToRad(lHour))) / (Math.cos(astro.getDec()[i]) - tCos + * Math.sin(Utils.degToRad(SP)) + * Math.cos(Utils.degToRad(lHour)))); + + tRA = astro.getRa()[i] + Utils.radToDeg(tRA0); + + tDEC = Utils.radToDeg(Math.atan2( + (Math.sin(astro.getDec()[i]) - tSin + * Math.sin(Utils.degToRad(SP))) + * Math.cos(tRA0), Math.cos(astro.getDec()[i]) + - tCos * Math.sin(Utils.degToRad(SP)) + * Math.cos(Utils.degToRad(lHour)))); + + topAstro.getRa()[i] = tRA; + topAstro.getDec()[i] = tDEC; + topAstro.getSid()[i] = astro.getSid()[i]; + topAstro.getDra()[i] = tRA0; + topAstro.getRsum()[i] = astro.getRsum()[i]; + + } + + } + + public static double limitAngle(double L) { + double F; + L /= 360.0; + F = L - Math.floor(L); + if (F > 0) + return 360 * F; + else if (F < 0) + return 360 - 360 * F; + else + return L; + } + + public static double limitAngle180(double L) { + double F; + L /= 180.0; + F = L - Math.floor(L); + if (F > 0) + return 180 * F; + else if (F < 0) + return 180 - 180 * F; + else + return L; + } + + public static double limitAngle111(double L) { + double F; + F = L - Math.floor(L); + if (F < 0) + return F += 1; + return F; + } + + public static double limitAngle180between(double L) { + double F; + L /= 360.0; + F = (L - Math.floor(L)) * 360.0; + if (F < -180) + F += 360; + else if (F > 180) + F -= 360; + return F; + } + } diff --git a/src/org/arabeyes/itl/prayer/astro/Direction.java b/src/org/arabeyes/itl/prayer/astro/Direction.java index 7955b22..07c4dbf 100644 --- a/src/org/arabeyes/itl/prayer/astro/Direction.java +++ b/src/org/arabeyes/itl/prayer/astro/Direction.java @@ -1,6 +1,6 @@ package org.arabeyes.itl.prayer.astro; public enum Direction { - NORTH, SOUTH, EAST, WEST; - + NORTH, SOUTH, EAST, WEST; + } diff --git a/src/org/arabeyes/itl/prayer/astro/Dms.java b/src/org/arabeyes/itl/prayer/astro/Dms.java index cb4ee6b..365db6e 100644 --- a/src/org/arabeyes/itl/prayer/astro/Dms.java +++ b/src/org/arabeyes/itl/prayer/astro/Dms.java @@ -5,83 +5,83 @@ * Minutes, Seconds) format and provides some utility methods */ public class Dms { - - private int degree; - - private int minute; - - private double second; - - /** - * - * @return degree value of the angle - */ - public int getDegree() { - return degree; - } - - /** - * - * @return minute value of the angle - */ - public int getMinute() { - return minute; - } - - /** - * - * @return second value of the angle - */ - public double getSecond() { - return second; - } - - /** - * Construct a DMS object using degree, minute and second values - * @param degree - * @param minute - * @param second - */ - public Dms(int degree, int minute, double second) { - this.degree = degree; - this.minute = minute; - this.second = second; - } - - /** - * construct a DMS object from a decimal value - * @param decimal - */ - public Dms(double decimal) { - double tempmin; - double v; - v = Math.floor(decimal); - degree = (int) v; - tempmin = (decimal - v) * 60.0; - - v = Math.floor(tempmin); - minute = (int) v; - second = (tempmin - v) * 60.0; - - } - - /** - * return decimal value of the DMS angle. - * @param dir reference direction. If direction is Direction.SOUTH - * or Direction.WEST then the decimal value is multiplied by -1 - * @return signed decimal value of the DMS angle - * @see Direction - */ - public double getDecimalValue(Direction dir) { - double sum = degree + ((minute / 60.0) + (second / 3600.0)); - if (dir == Direction.WEST || dir == Direction.SOUTH) { - return sum * (-1.0); - } - return sum; - } - - public String toString() { - return degree + "�" + minute + "'" + second + "''"; - } - + + private int degree; + + private int minute; + + private double second; + + /** + * + * @return degree value of the angle + */ + public int getDegree() { + return degree; + } + + /** + * + * @return minute value of the angle + */ + public int getMinute() { + return minute; + } + + /** + * + * @return second value of the angle + */ + public double getSecond() { + return second; + } + + /** + * Construct a DMS object using degree, minute and second values + * @param degree + * @param minute + * @param second + */ + public Dms(int degree, int minute, double second) { + this.degree = degree; + this.minute = minute; + this.second = second; + } + + /** + * construct a DMS object from a decimal value + * @param decimal + */ + public Dms(double decimal) { + double tempmin; + double v; + v = Math.floor(decimal); + degree = (int) v; + tempmin = (decimal - v) * 60.0; + + v = Math.floor(tempmin); + minute = (int) v; + second = (tempmin - v) * 60.0; + + } + + /** + * return decimal value of the DMS angle. + * @param dir reference direction. If direction is Direction.SOUTH + * or Direction.WEST then the decimal value is multiplied by -1 + * @return signed decimal value of the DMS angle + * @see Direction + */ + public double getDecimalValue(Direction dir) { + double sum = degree + ((minute / 60.0) + (second / 3600.0)); + if (dir == Direction.WEST || dir == Direction.SOUTH) { + return sum * (-1.0); + } + return sum; + } + + public String toString() { + return degree + "�" + minute + "'" + second + "''"; + } + } diff --git a/src/org/arabeyes/itl/prayer/astro/Location.java b/src/org/arabeyes/itl/prayer/astro/Location.java index 2c0fd3d..acf6ffc 100644 --- a/src/org/arabeyes/itl/prayer/astro/Location.java +++ b/src/org/arabeyes/itl/prayer/astro/Location.java @@ -1,147 +1,147 @@ package org.arabeyes.itl.prayer.astro; public class Location { - - static final double DEFAULT_SEA_LEVEL = 0; - - static final double DEFAULT_PRESSURE = 1010; - - static final double DEFAULT_TEMPERATURE = 10; - - private double degreeLong; - - private double degreeLat; - - private double gmtDiff; - - private int dst; - - private double seaLevel; - - private double pressure; - - private double temperature; - - /** - * default constructor of location object. Latitude, Longitude, - * GMT difference and day saving time flag are required. Other - * settings (sea level, pressure, temperature) are given standard - * astronomical values and can be set later using setters. - * - * - * @param degreeLat latitude in degrees - * @param degreeLong longitude in degrees - * @param gmtDiff difference with GMT - * @param dst day saving time (1 to add one hour, 2 to add two, 0 - * if none, etc..) - */ - public Location(double degreeLat, double degreeLong, double gmtDiff, int dst) { - this.degreeLong = degreeLong; - this.degreeLat = degreeLat; - this.gmtDiff = gmtDiff; - this.dst = dst; - - this.seaLevel = DEFAULT_SEA_LEVEL; - this.pressure = DEFAULT_PRESSURE; - this.temperature = DEFAULT_TEMPERATURE; - } - - public Location(Location src) { - degreeLat = (src.degreeLat); - degreeLong = (src.degreeLong); - gmtDiff = (src.gmtDiff); - dst = (src.dst); - seaLevel = (src.seaLevel); - pressure = (src.pressure); - temperature = (src.temperature); - } - - public double getDegreeLat() { - return degreeLat; - } - - /** - * - * @param degreeLat Latitude in decimal degree. - */ - public void setDegreeLat(double degreeLat) { - this.degreeLat = degreeLat; - } - - public double getDegreeLong() { - return degreeLong; - } - - /** - * - * @param degreeLong Longitude in decimal degree. - */ - public void setDegreeLong(double degreeLong) { - this.degreeLong = degreeLong; - } - - public int getDst() { - return dst; - } - + + static final double DEFAULT_SEA_LEVEL = 0; + + static final double DEFAULT_PRESSURE = 1010; + + static final double DEFAULT_TEMPERATURE = 10; + + private double degreeLong; + + private double degreeLat; + + private double gmtDiff; + + private int dst; + + private double seaLevel; + + private double pressure; + + private double temperature; + + /** + * default constructor of location object. Latitude, Longitude, + * GMT difference and day saving time flag are required. Other + * settings (sea level, pressure, temperature) are given standard + * astronomical values and can be set later using setters. + * + * + * @param degreeLat latitude in degrees + * @param degreeLong longitude in degrees + * @param gmtDiff difference with GMT + * @param dst day saving time (1 to add one hour, 2 to add two, 0 + * if none, etc..) + */ + public Location(double degreeLat, double degreeLong, double gmtDiff, int dst) { + this.degreeLong = degreeLong; + this.degreeLat = degreeLat; + this.gmtDiff = gmtDiff; + this.dst = dst; + + this.seaLevel = DEFAULT_SEA_LEVEL; + this.pressure = DEFAULT_PRESSURE; + this.temperature = DEFAULT_TEMPERATURE; + } + + public Location(Location src) { + degreeLat = (src.degreeLat); + degreeLong = (src.degreeLong); + gmtDiff = (src.gmtDiff); + dst = (src.dst); + seaLevel = (src.seaLevel); + pressure = (src.pressure); + temperature = (src.temperature); + } + + public double getDegreeLat() { + return degreeLat; + } + + /** + * + * @param degreeLat Latitude in decimal degree. + */ + public void setDegreeLat(double degreeLat) { + this.degreeLat = degreeLat; + } + + public double getDegreeLong() { + return degreeLong; + } + + /** + * + * @param degreeLong Longitude in decimal degree. + */ + public void setDegreeLong(double degreeLong) { + this.degreeLong = degreeLong; + } + + public int getDst() { + return dst; + } + - /** - * Daylight savings time switch (0 if not used). Set - * this to 1 should add 1 hour to all the calculated - * prayer times - * @param dst - */ - public void setDst(int dst) { - this.dst = dst; - } - - public double getGmtDiff() { - return gmtDiff; - } - - /** - * - * @param gmtDiff GMT difference at regular time. - */ - public void setGmtDiff(double gmtDiff) { - this.gmtDiff = gmtDiff; - } - - public double getPressure() { - return pressure; - } - - /** - * @param pressure Atmospheric pressure in millibars (the - * astronomical standard value is 1010 (Location.DEFAULT_PRESSURE)) - */ - public void setPressure(double pressure) { - this.pressure = pressure; - } - - - public double getSeaLevel() { - return seaLevel; - } - - /** - * - * @param seaLevel Height above Sea level in meters - */ - public void setSeaLevel(double seaLevel) { - this.seaLevel = seaLevel; - } - - public double getTemperature() { - return temperature; - } - - /** - * - * @param temperature Temperature in Celsius degree (the - * astronomical standard value is 10) - */ - public void setTemperature(double temperature) { - this.temperature = temperature; - } + /** + * Daylight savings time switch (0 if not used). Set + * this to 1 should add 1 hour to all the calculated + * prayer times + * @param dst + */ + public void setDst(int dst) { + this.dst = dst; + } + + public double getGmtDiff() { + return gmtDiff; + } + + /** + * + * @param gmtDiff GMT difference at regular time. + */ + public void setGmtDiff(double gmtDiff) { + this.gmtDiff = gmtDiff; + } + + public double getPressure() { + return pressure; + } + + /** + * @param pressure Atmospheric pressure in millibars (the + * astronomical standard value is 1010 (Location.DEFAULT_PRESSURE)) + */ + public void setPressure(double pressure) { + this.pressure = pressure; + } + + + public double getSeaLevel() { + return seaLevel; + } + + /** + * + * @param seaLevel Height above Sea level in meters + */ + public void setSeaLevel(double seaLevel) { + this.seaLevel = seaLevel; + } + + public double getTemperature() { + return temperature; + } + + /** + * + * @param temperature Temperature in Celsius degree (the + * astronomical standard value is 10) + */ + public void setTemperature(double temperature) { + this.temperature = temperature; + } } diff --git a/src/org/arabeyes/itl/prayer/astro/SimpleGregorianDate.java b/src/org/arabeyes/itl/prayer/astro/SimpleGregorianDate.java index ea231e3..984b601 100644 --- a/src/org/arabeyes/itl/prayer/astro/SimpleGregorianDate.java +++ b/src/org/arabeyes/itl/prayer/astro/SimpleGregorianDate.java @@ -3,43 +3,43 @@ import java.util.GregorianCalendar; public class SimpleGregorianDate { - - private int day; - private int month; - private int year; - - public SimpleGregorianDate(int day, int month, int year) { - this.day = day; - this.month = month; - this.year = year; - } - - public SimpleGregorianDate(SimpleGregorianDate src) { - this.day = src.day; - this.month = src.month; - this.year = src.year; - } - - public SimpleGregorianDate(GregorianCalendar gCalendar) { - this.day = gCalendar.get(GregorianCalendar.DATE); - this.month = gCalendar.get(GregorianCalendar.MONTH); - this.year = gCalendar.get(GregorianCalendar.YEAR); - } - - public int getDay() { - return day; - } - - int getMonthCompat() { - return month + 1; - } - - public int getMonth() { - return month; - } - - public int getYear() { - return year; - } - + + private int day; + private int month; + private int year; + + public SimpleGregorianDate(int day, int month, int year) { + this.day = day; + this.month = month; + this.year = year; + } + + public SimpleGregorianDate(SimpleGregorianDate src) { + this.day = src.day; + this.month = src.month; + this.year = src.year; + } + + public SimpleGregorianDate(GregorianCalendar gCalendar) { + this.day = gCalendar.get(GregorianCalendar.DATE); + this.month = gCalendar.get(GregorianCalendar.MONTH); + this.year = gCalendar.get(GregorianCalendar.YEAR); + } + + public int getDay() { + return day; + } + + int getMonthCompat() { + return month + 1; + } + + public int getMonth() { + return month; + } + + public int getYear() { + return year; + } + } diff --git a/src/org/arabeyes/itl/prayer/astro/Utils.java b/src/org/arabeyes/itl/prayer/astro/Utils.java index 0f43feb..f0078b4 100644 --- a/src/org/arabeyes/itl/prayer/astro/Utils.java +++ b/src/org/arabeyes/itl/prayer/astro/Utils.java @@ -1,39 +1,39 @@ package org.arabeyes.itl.prayer.astro; public class Utils { - - public static final double INVALID_TRIGGER = -.999; - - public static final double PI = 3.1415926535898; - - public static final double DEG_TO_10_BASE = 1 / 15.0; - - public static final double CENTER_OF_SUN_ANGLE = -0.833370; - - public static final double ALTITUDE_REFRACTION = 0.0347; - - public static final double REF_LIMIT = 9999999; - - public static final double KAABA_LAT = 21.423333; - - public static final double KAABA_LONG = 39.823333; - - public static final double DEF_NEAREST_LATITUDE = 48.5; - - public static final double DEF_IMSAAK_ANGLE = 1.5; - - public static final double DEF_IMSAAK_INTERVAL = 10; - - public static final double DEFAULT_ROUND_SEC = 30; - - public static final double AGGRESSIVE_ROUND_SEC = 1; - - /* UTILITIES */ - public static double degToRad(double angle) { - return angle * (PI / 180.0); - } - - public static double radToDeg(double angle) { - return angle / (PI / 180.0); - } + + public static final double INVALID_TRIGGER = -.999; + + public static final double PI = 3.1415926535898; + + public static final double DEG_TO_10_BASE = 1 / 15.0; + + public static final double CENTER_OF_SUN_ANGLE = -0.833370; + + public static final double ALTITUDE_REFRACTION = 0.0347; + + public static final double REF_LIMIT = 9999999; + + public static final double KAABA_LAT = 21.423333; + + public static final double KAABA_LONG = 39.823333; + + public static final double DEF_NEAREST_LATITUDE = 48.5; + + public static final double DEF_IMSAAK_ANGLE = 1.5; + + public static final double DEF_IMSAAK_INTERVAL = 10; + + public static final double DEFAULT_ROUND_SEC = 30; + + public static final double AGGRESSIVE_ROUND_SEC = 1; + + /* UTILITIES */ + public static double degToRad(double angle) { + return angle * (PI / 180.0); + } + + public static double radToDeg(double angle) { + return angle / (PI / 180.0); + } }