Search in sources :

Example 1 with CalendarAstronomer

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);
}
Also used : Calendar(android.icu.util.Calendar) CalendarAstronomer(android.icu.impl.CalendarAstronomer)

Example 2 with CalendarAstronomer

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);
}
Also used : Calendar(android.icu.util.Calendar) CalendarAstronomer(android.icu.impl.CalendarAstronomer)

Example 3 with CalendarAstronomer

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);
}
Also used : Calendar(android.icu.util.Calendar) CalendarAstronomer(android.icu.impl.CalendarAstronomer)

Example 4 with CalendarAstronomer

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)));
    }
}
Also used : GregorianCalendar(android.icu.util.GregorianCalendar) Ecliptic(android.icu.impl.CalendarAstronomer.Ecliptic) Date(java.util.Date) CalendarAstronomer(android.icu.impl.CalendarAstronomer) Test(org.junit.Test)

Example 5 with CalendarAstronomer

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);
            }
        }
    }
}
Also used : SimpleTimeZone(android.icu.util.SimpleTimeZone) GregorianCalendar(android.icu.util.GregorianCalendar) CalendarAstronomer(android.icu.impl.CalendarAstronomer) Equatorial(android.icu.impl.CalendarAstronomer.Equatorial) Test(org.junit.Test)

Aggregations

CalendarAstronomer (android.icu.impl.CalendarAstronomer)13 Test (org.junit.Test)8 GregorianCalendar (android.icu.util.GregorianCalendar)7 Calendar (android.icu.util.Calendar)5 SimpleTimeZone (android.icu.util.SimpleTimeZone)4 Equatorial (android.icu.impl.CalendarAstronomer.Equatorial)3 DateFormat (android.icu.text.DateFormat)3 Date (java.util.Date)3 Ecliptic (android.icu.impl.CalendarAstronomer.Ecliptic)1 CalendarCache (android.icu.impl.CalendarCache)1 SimpleDateFormat (android.icu.text.SimpleDateFormat)1 BuddhistCalendar (android.icu.util.BuddhistCalendar)1 ChineseCalendar (android.icu.util.ChineseCalendar)1 JapaneseCalendar (android.icu.util.JapaneseCalendar)1 TaiwanCalendar (android.icu.util.TaiwanCalendar)1 TimeZone (android.icu.util.TimeZone)1 ULocale (android.icu.util.ULocale)1