use of android.icu.impl.CalendarAstronomer in project android_frameworks_base by ResurrectionRemix.
the class TwilightService method calculateTwilightState.
/**
* Calculates the twilight state for a specific location and time.
*
* @param location the location to use
* @param timeMillis the reference time to use
* @return the calculated {@link TwilightState}, or {@code null} if location is {@code null}
*/
private static TwilightState calculateTwilightState(Location location, long timeMillis) {
if (location == null) {
return null;
}
final CalendarAstronomer ca = new CalendarAstronomer(location.getLongitude(), location.getLatitude());
final Calendar noon = Calendar.getInstance();
noon.setTimeInMillis(timeMillis);
noon.set(Calendar.HOUR_OF_DAY, 12);
noon.set(Calendar.MINUTE, 0);
noon.set(Calendar.SECOND, 0);
noon.set(Calendar.MILLISECOND, 0);
ca.setTime(noon.getTimeInMillis());
long sunriseTimeMillis = ca.getSunRiseSet(true);
long sunsetTimeMillis = ca.getSunRiseSet(false);
if (sunsetTimeMillis < timeMillis) {
noon.add(Calendar.DATE, 1);
ca.setTime(noon.getTimeInMillis());
sunriseTimeMillis = ca.getSunRiseSet(true);
} else if (sunriseTimeMillis > timeMillis) {
noon.add(Calendar.DATE, -1);
ca.setTime(noon.getTimeInMillis());
sunsetTimeMillis = ca.getSunRiseSet(false);
}
return new TwilightState(sunriseTimeMillis, sunsetTimeMillis);
}
use of android.icu.impl.CalendarAstronomer in project platform_frameworks_base by android.
the class TwilightService method calculateTwilightState.
/**
* Calculates the twilight state for a specific location and time.
*
* @param location the location to use
* @param timeMillis the reference time to use
* @return the calculated {@link TwilightState}, or {@code null} if location is {@code null}
*/
private static TwilightState calculateTwilightState(Location location, long timeMillis) {
if (location == null) {
return null;
}
final CalendarAstronomer ca = new CalendarAstronomer(location.getLongitude(), location.getLatitude());
final Calendar noon = Calendar.getInstance();
noon.setTimeInMillis(timeMillis);
noon.set(Calendar.HOUR_OF_DAY, 12);
noon.set(Calendar.MINUTE, 0);
noon.set(Calendar.SECOND, 0);
noon.set(Calendar.MILLISECOND, 0);
ca.setTime(noon.getTimeInMillis());
long sunriseTimeMillis = ca.getSunRiseSet(true);
long sunsetTimeMillis = ca.getSunRiseSet(false);
if (sunsetTimeMillis < timeMillis) {
noon.add(Calendar.DATE, 1);
ca.setTime(noon.getTimeInMillis());
sunriseTimeMillis = ca.getSunRiseSet(true);
} else if (sunriseTimeMillis > timeMillis) {
noon.add(Calendar.DATE, -1);
ca.setTime(noon.getTimeInMillis());
sunsetTimeMillis = ca.getSunRiseSet(false);
}
return new TwilightState(sunriseTimeMillis, sunsetTimeMillis);
}
use of android.icu.impl.CalendarAstronomer in project android_frameworks_base by DirtyUnicorns.
the class TwilightService method calculateTwilightState.
/**
* Calculates the twilight state for a specific location and time.
*
* @param location the location to use
* @param timeMillis the reference time to use
* @return the calculated {@link TwilightState}, or {@code null} if location is {@code null}
*/
private static TwilightState calculateTwilightState(Location location, long timeMillis) {
if (location == null) {
return null;
}
final CalendarAstronomer ca = new CalendarAstronomer(location.getLongitude(), location.getLatitude());
final Calendar noon = Calendar.getInstance();
noon.setTimeInMillis(timeMillis);
noon.set(Calendar.HOUR_OF_DAY, 12);
noon.set(Calendar.MINUTE, 0);
noon.set(Calendar.SECOND, 0);
noon.set(Calendar.MILLISECOND, 0);
ca.setTime(noon.getTimeInMillis());
long sunriseTimeMillis = ca.getSunRiseSet(true);
long sunsetTimeMillis = ca.getSunRiseSet(false);
if (sunsetTimeMillis < timeMillis) {
noon.add(Calendar.DATE, 1);
ca.setTime(noon.getTimeInMillis());
sunriseTimeMillis = ca.getSunRiseSet(true);
} else if (sunriseTimeMillis > timeMillis) {
noon.add(Calendar.DATE, -1);
ca.setTime(noon.getTimeInMillis());
sunsetTimeMillis = ca.getSunRiseSet(false);
}
return new TwilightState(sunriseTimeMillis, sunsetTimeMillis);
}
use of android.icu.impl.CalendarAstronomer in project j2objc by google.
the class AstroTest method TestCoverage.
@Test
public void TestCoverage() {
GregorianCalendar cal = new GregorianCalendar(1958, Calendar.AUGUST, 15);
Date then = cal.getTime();
CalendarAstronomer myastro = new CalendarAstronomer(then);
// Latitude: 34 degrees 05' North
// Longitude: 118 degrees 22' West
double laLat = 34 + 5d / 60, laLong = 360 - (118 + 22d / 60);
CalendarAstronomer myastro2 = new CalendarAstronomer(laLong, laLat);
double eclLat = laLat * Math.PI / 360;
double eclLong = laLong * Math.PI / 360;
Ecliptic ecl = new Ecliptic(eclLat, eclLong);
logln("ecliptic: " + ecl);
CalendarAstronomer myastro3 = new CalendarAstronomer();
myastro3.setJulianDay((4713 + 2000) * 365.25);
CalendarAstronomer[] astronomers = { // check cache
myastro, // check cache
myastro2, // check cache
myastro3, // check cache
myastro2 };
for (int i = 0; i < astronomers.length; ++i) {
CalendarAstronomer astro = astronomers[i];
logln("astro: " + astro);
logln(" time: " + astro.getTime());
logln(" date: " + astro.getDate());
logln(" cent: " + astro.getJulianCentury());
logln(" gw sidereal: " + astro.getGreenwichSidereal());
logln(" loc sidereal: " + astro.getLocalSidereal());
logln(" equ ecl: " + astro.eclipticToEquatorial(ecl));
logln(" equ long: " + astro.eclipticToEquatorial(eclLong));
logln(" horiz: " + astro.eclipticToHorizon(eclLong));
logln(" sunrise: " + new Date(astro.getSunRiseSet(true)));
logln(" sunset: " + new Date(astro.getSunRiseSet(false)));
logln(" moon phase: " + astro.getMoonPhase());
logln(" moonrise: " + new Date(astro.getMoonRiseSet(true)));
logln(" moonset: " + new Date(astro.getMoonRiseSet(false)));
logln(" prev summer solstice: " + new Date(astro.getSunTime(CalendarAstronomer.SUMMER_SOLSTICE, false)));
logln(" next summer solstice: " + new Date(astro.getSunTime(CalendarAstronomer.SUMMER_SOLSTICE, true)));
logln(" prev full moon: " + new Date(astro.getMoonTime(CalendarAstronomer.FULL_MOON, false)));
logln(" next full moon: " + new Date(astro.getMoonTime(CalendarAstronomer.FULL_MOON, true)));
}
}
use of android.icu.impl.CalendarAstronomer in project j2objc by google.
the class AstroTest method TestSolarLongitude.
@Test
public void TestSolarLongitude() {
GregorianCalendar gc = new GregorianCalendar(new SimpleTimeZone(0, "UTC"));
CalendarAstronomer astro = new CalendarAstronomer();
// year, month, day, hour, minute, longitude (radians), ascension(radians), declination(radians)
final double[][] tests = { { 1980, 7, 27, 00, 00, 2.166442986535465, 2.2070499713207730, 0.3355704075759270 }, { 1988, 7, 27, 00, 00, 2.167484927693959, 2.2081183335606176, 0.3353093444275315 } };
logln("");
for (int i = 0; i < tests.length; i++) {
gc.clear();
gc.set((int) tests[i][0], (int) tests[i][1] - 1, (int) tests[i][2], (int) tests[i][3], (int) tests[i][4]);
astro.setDate(gc.getTime());
double longitude = astro.getSunLongitude();
if (longitude != tests[i][5]) {
if ((float) longitude == (float) tests[i][5]) {
logln("longitude(" + longitude + ") != tests[i][5](" + tests[i][5] + ") in double for test " + i);
} else {
errln("FAIL: longitude(" + longitude + ") != tests[i][5](" + tests[i][5] + ") for test " + i);
}
}
Equatorial result = astro.getSunPosition();
if (result.ascension != tests[i][6]) {
if ((float) result.ascension == (float) tests[i][6]) {
logln("result.ascension(" + result.ascension + ") != tests[i][6](" + tests[i][6] + ") in double for test " + i);
} else {
errln("FAIL: result.ascension(" + result.ascension + ") != tests[i][6](" + tests[i][6] + ") for test " + i);
}
}
if (result.declination != tests[i][7]) {
if ((float) result.declination == (float) tests[i][7]) {
logln("result.declination(" + result.declination + ") != tests[i][7](" + tests[i][7] + ") in double for test " + i);
} else {
errln("FAIL: result.declination(" + result.declination + ") != tests[i][7](" + tests[i][7] + ") for test " + i);
}
}
}
}
Aggregations