v7/appcompat/src/main/java/androidx/appcompat/app/TwilightCalculator.java
@SuppressWarnings("FloatingPointLiteralPrecision")
    public void calculateTwilight(long time, double latitude, double longitude) {
        final float daysSince2000 = (float) (time - UTC_2000) / DateUtils.DAY_IN_MILLIS;

        // mean anomaly
        final float meanAnomaly = 6.240059968f + daysSince2000 * 0.01720197f;

        // true anomaly
        final double trueAnomaly = meanAnomaly + C1 * Math.sin(meanAnomaly) + C2
                * Math.sin(2 * meanAnomaly) + C3 * Math.sin(3 * meanAnomaly);

        // ecliptic longitude
        final double solarLng = trueAnomaly + 1.796593063d + Math.PI;

        // solar transit in days since 2000
        final double arcLongitude = -longitude / 360;
        float n = Math.round(daysSince2000 - J0 - arcLongitude);
        double solarTransitJ2000 = n + J0 + arcLongitude + 0.0053d * Math.sin(meanAnomaly)
                + -0.0069d * Math.sin(2 * solarLng);

        // declination of sun
        double solarDec = Math.asin(Math.sin(solarLng) * Math.sin(OBLIQUITY));

        final double latRad = latitude * DEGREES_TO_RADIANS;

        double cosHourAngle = (Math.sin(ALTIDUTE_CORRECTION_CIVIL_TWILIGHT) - Math.sin(latRad)
                * Math.sin(solarDec)) / (Math.cos(latRad) * Math.cos(solarDec));
        // The day or night never ends for the given date and location, if this value is out of
        // range.
        if (cosHourAngle >= 1) {
            state = NIGHT;
            sunset = -1;
            sunrise = -1;
            return;
        } else if (cosHourAngle <= -1) {
            state = DAY;
            sunset = -1;
            sunrise = -1;
            return;
        }

        float hourAngle = (float) (Math.acos(cosHourAngle) / (2 * Math.PI));

        sunset = Math.round((solarTransitJ2000 + hourAngle) * DateUtils.DAY_IN_MILLIS) + UTC_2000;
        sunrise = Math.round((solarTransitJ2000 - hourAngle) * DateUtils.DAY_IN_MILLIS) + UTC_2000;

        if (sunrise < time && sunset > time) {
            state = DAY;
        } else {
            state = NIGHT;
        }
    }
/**
     * calculates the civil twilight bases on time and geo-coordinates.
     *
     * @param time time in milliseconds.
     * @param latitude latitude in degrees.
     * @param longitude latitude in degrees.
     */
calculates the civil twilight bases on time and geo-coordinates.
@param time time in milliseconds.
@param latitude latitude in degrees.
@param longitude latitude in degrees.
calculates the civil twilight bases on time and geo - coordinates . @param time time in milliseconds . @param latitude latitude in degrees . @param longitude latitude in degrees .
@SuppressWarnings("FloatingPointLiteralPrecision")
    public void calculateTwilight(long time, double latitude, double longitude) {
        final float daysSince2000 = (float) (time - UTC_2000) / DateUtils.DAY_IN_MILLIS;
        final float meanAnomaly = 6.240059968f + daysSince2000 * 0.01720197f;
        final double trueAnomaly = meanAnomaly + C1 * Math.sin(meanAnomaly) + C2
                * Math.sin(2 * meanAnomaly) + C3 * Math.sin(3 * meanAnomaly);
        final double solarLng = trueAnomaly + 1.796593063d + Math.PI;
        final double arcLongitude = -longitude / 360;
        float n = Math.round(daysSince2000 - J0 - arcLongitude);
        double solarTransitJ2000 = n + J0 + arcLongitude + 0.0053d * Math.sin(meanAnomaly)
                + -0.0069d * Math.sin(2 * solarLng);
        double solarDec = Math.asin(Math.sin(solarLng) * Math.sin(OBLIQUITY));
        final double latRad = latitude * DEGREES_TO_RADIANS;
        double cosHourAngle = (Math.sin(ALTIDUTE_CORRECTION_CIVIL_TWILIGHT) - Math.sin(latRad)
                * Math.sin(solarDec)) / (Math.cos(latRad) * Math.cos(solarDec));
        if (cosHourAngle >= 1) {
            state = NIGHT;
            sunset = -1;
            sunrise = -1;
            return;
        } else if (cosHourAngle <= -1) {
            state = DAY;
            sunset = -1;
            sunrise = -1;
            return;
        }
        float hourAngle = (float) (Math.acos(cosHourAngle) / (2 * Math.PI));
        sunset = Math.round((solarTransitJ2000 + hourAngle) * DateUtils.DAY_IN_MILLIS) + UTC_2000;
        sunrise = Math.round((solarTransitJ2000 - hourAngle) * DateUtils.DAY_IN_MILLIS) + UTC_2000;
        if (sunrise < time && sunset > time) {
            state = DAY;
        } else {
            state = NIGHT;
        }
    }
@ SuppressWarnings ( "FloatingPointLiteralPrecision" ) public void calculateTwilight ( long time , double latitude , double longitude ) { final float daysSince2000 = ( float ) ( time - UTC_2000 ) / DateUtils . DAY_IN_MILLIS ; final float meanAnomaly = 6.240059968f + daysSince2000 * 0.01720197f ; final double trueAnomaly = meanAnomaly + C1 * Math . sin ( meanAnomaly ) + C2 * Math . sin ( 2 * meanAnomaly ) + C3 * Math . sin ( 3 * meanAnomaly ) ; final double solarLng = trueAnomaly + 1.796593063d + Math . PI ; final double arcLongitude = - longitude / 360 ; float n = Math . round ( daysSince2000 - J0 - arcLongitude ) ; double solarTransitJ2000 = n + J0 + arcLongitude + 0.0053d * Math . sin ( meanAnomaly ) + - 0.0069d * Math . sin ( 2 * solarLng ) ; double solarDec = Math . asin ( Math . sin ( solarLng ) * Math . sin ( OBLIQUITY ) ) ; final double latRad = latitude * DEGREES_TO_RADIANS ; double cosHourAngle = ( Math . sin ( ALTIDUTE_CORRECTION_CIVIL_TWILIGHT ) - Math . sin ( latRad ) * Math . sin ( solarDec ) ) / ( Math . cos ( latRad ) * Math . cos ( solarDec ) ) ; if ( cosHourAngle >= 1 ) { state = NIGHT ; sunset = - 1 ; sunrise = - 1 ; return ; } else if ( cosHourAngle <= - 1 ) { state = DAY ; sunset = - 1 ; sunrise = - 1 ; return ; } float hourAngle = ( float ) ( Math . acos ( cosHourAngle ) / ( 2 * Math . PI ) ) ; sunset = Math . round ( ( solarTransitJ2000 + hourAngle ) * DateUtils . DAY_IN_MILLIS ) + UTC_2000 ; sunrise = Math . round ( ( solarTransitJ2000 - hourAngle ) * DateUtils . DAY_IN_MILLIS ) + UTC_2000 ; if ( sunrise < time && sunset > time ) { state = DAY ; } else { state = NIGHT ; } }
calculates the civil twilight bases on time and geo-coordinates.
calculates the civil twilight bases on time and geo - coordinates .
// mean anomaly // true anomaly // ecliptic longitude // solar transit in days since 2000 // declination of sun // The day or night never ends for the given date and location, if this value is out of // range.