Package com.kosherjava.zmanim.util
Class SunTimesCalculator
java.lang.Object
com.kosherjava.zmanim.util.AstronomicalCalculator
com.kosherjava.zmanim.util.SunTimesCalculator
- All Implemented Interfaces:
Cloneable
Implementation of sunrise and sunset methods to calculate astronomical times. This calculator uses the Java algorithm
written by Kevin
Boone that is based on the US Naval Observatory'sAstronomical Almanac and used with his permission. Added to Kevin's
code is adjustment of the zenith to account for elevation. This algorithm returns the same time every year and does not
account for leap years. It is not as accurate as the Jean Meeus based
NOAACalculator
that is the default calculator
use by the KosherJava zmanim library.- Author:
- © Eliyahu Hershfeld 2004 - 2023, © Kevin Boone 2000
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final double
The number of degrees of longitude that corresponds to one hour time difference. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprivate static double
acosDeg
(double x) private static double
asinDeg
(double x) private static double
cosDeg
(double deg) Calculate cosine of the angle in degreesprivate static double
getApproxTimeDays
(int dayOfYear, double hoursFromMeridian, boolean isSunrise) Calculate the approximate time of sunset or sunrise in days since midnight Jan 1st, assuming 6am and 6pm events.Returns the name of the algorithm.private static double
getCosLocalHourAngle
(double sunTrueLongitude, double latitude, double zenith) Calculate the cosine of the Sun's local hour angleprivate static double
getHoursFromMeridian
(double longitude) Get time difference between location's longitude and the Meridian, in hours.private static double
getLocalMeanTime
(double localHour, double sunRightAscensionHours, double approxTimeDays) Calculate local mean time of rising or setting.private static double
getMeanAnomaly
(int dayOfYear, double longitude, boolean isSunrise) Calculate the Sun's mean anomaly in degrees, at sunrise or sunset, given the longitude in degreesprivate static double
getSunRightAscensionHours
(double sunTrueLongitude) Calculates the Sun's right ascension in hours.private static double
getSunTrueLongitude
(double sunMeanAnomaly) private static double
getTimeUTC
(Calendar calendar, GeoLocation geoLocation, double zenith, boolean isSunrise) Get sunrise or sunset time in UTC, according to flag.double
getUTCNoon
(Calendar calendar, GeoLocation geoLocation) Return the Universal Coordinated Time (UTC) of solar noon for the given day at the given location on earth.double
getUTCSunrise
(Calendar calendar, GeoLocation geoLocation, double zenith, boolean adjustForElevation) A method that calculates UTC sunrise as well as any time based on an angle above or below sunrise.double
getUTCSunset
(Calendar calendar, GeoLocation geoLocation, double zenith, boolean adjustForElevation) A method that calculates UTC sunset as well as any time based on an angle above or below sunset.private static double
sinDeg
(double deg) private static double
tanDeg
(double deg) Methods inherited from class com.kosherjava.zmanim.util.AstronomicalCalculator
adjustZenith, clone, getDefault, getEarthRadius, getElevationAdjustment, getRefraction, getSolarRadius, setEarthRadius, setRefraction, setSolarRadius
-
Field Details
-
DEG_PER_HOUR
The number of degrees of longitude that corresponds to one hour time difference.- See Also:
-
-
Constructor Details
-
SunTimesCalculator
public SunTimesCalculator()
-
-
Method Details
-
getCalculatorName
Description copied from class:AstronomicalCalculator
Returns the name of the algorithm.- Specified by:
getCalculatorName
in classAstronomicalCalculator
- Returns:
- the descriptive name of the algorithm.
- See Also:
-
getUTCSunrise
public double getUTCSunrise(Calendar calendar, GeoLocation geoLocation, double zenith, boolean adjustForElevation) Description copied from class:AstronomicalCalculator
A method that calculates UTC sunrise as well as any time based on an angle above or below sunrise. This abstract method is implemented by the classes that extend this class.- Specified by:
getUTCSunrise
in classAstronomicalCalculator
- Parameters:
calendar
- Used to calculate day of year.geoLocation
- The location information used for astronomical calculating sun times.zenith
- the azimuth below the vertical zenith of 90 degrees. for sunrise typically thezenith
used for the calculation uses geometric zenith of 90° andadjusts
this slightly to account for solar refraction and the sun's radius. Another example would beAstronomicalCalendar.getBeginNauticalTwilight()
that passesAstronomicalCalendar.NAUTICAL_ZENITH
to this method.adjustForElevation
- Should the time be adjusted for elevation- Returns:
- The UTC time of sunrise in 24 hour format. 5:45:00 AM will return 5.75.0. If an error was encountered in
the calculation (expected behavior for some locations such as near the poles,
Double.NaN
will be returned. - See Also:
-
getUTCSunset
public double getUTCSunset(Calendar calendar, GeoLocation geoLocation, double zenith, boolean adjustForElevation) Description copied from class:AstronomicalCalculator
A method that calculates UTC sunset as well as any time based on an angle above or below sunset. This abstract method is implemented by the classes that extend this class.- Specified by:
getUTCSunset
in classAstronomicalCalculator
- Parameters:
calendar
- Used to calculate day of year.geoLocation
- The location information used for astronomical calculating sun times.zenith
- the azimuth below the vertical zenith of 90°. For sunset typically thezenith
used for the calculation uses geometric zenith of 90° andadjusts
this slightly to account for solar refraction and the sun's radius. Another example would beAstronomicalCalendar.getEndNauticalTwilight()
that passesAstronomicalCalendar.NAUTICAL_ZENITH
to this method.adjustForElevation
- Should the time be adjusted for elevation- Returns:
- The UTC time of sunset in 24 hour format. 5:45:00 AM will return 5.75.0. If an error was encountered in
the calculation (expected behavior for some locations such as near the poles,
Double.NaN
will be returned. - See Also:
-
sinDeg
- Parameters:
deg
- the degrees- Returns:
- sin of the angle in degrees
-
acosDeg
- Parameters:
x
- angle- Returns:
- acos of the angle in degrees
-
asinDeg
- Parameters:
x
- angle- Returns:
- asin of the angle in degrees
-
tanDeg
- Parameters:
deg
- degrees- Returns:
- tan of the angle in degrees
-
cosDeg
Calculate cosine of the angle in degrees- Parameters:
deg
- degrees- Returns:
- cosine of the angle in degrees
-
getHoursFromMeridian
Get time difference between location's longitude and the Meridian, in hours.- Parameters:
longitude
- the longitude- Returns:
- time difference between the location's longitude and the Meridian, in hours. West of Meridian has a negative time difference
-
getApproxTimeDays
Calculate the approximate time of sunset or sunrise in days since midnight Jan 1st, assuming 6am and 6pm events. We need this figure to derive the Sun's mean anomaly.- Parameters:
dayOfYear
- the day of yearhoursFromMeridian
- hours from the meridianisSunrise
- true for sunrise and false for sunset- Returns:
- the approximate time of sunset or sunrise in days since midnight Jan 1st, assuming 6am and 6pm events. We need this figure to derive the Sun's mean anomaly.
-
getMeanAnomaly
Calculate the Sun's mean anomaly in degrees, at sunrise or sunset, given the longitude in degrees- Parameters:
dayOfYear
- the day of the yearlongitude
- longitudeisSunrise
- true for sunrise and false for sunset- Returns:
- the Sun's mean anomaly in degrees
-
getSunTrueLongitude
- Parameters:
sunMeanAnomaly
- the Sun's mean anomaly in degrees- Returns:
- the Sun's true longitude in degrees. The result is an angle >= 0 and <= 360.
-
getSunRightAscensionHours
Calculates the Sun's right ascension in hours.- Parameters:
sunTrueLongitude
- the Sun's true longitude in degrees > 0 and < 360.- Returns:
- the Sun's right ascension in hours in angles > 0 and < 360.
-
getCosLocalHourAngle
Calculate the cosine of the Sun's local hour angle- Parameters:
sunTrueLongitude
- the sun's true longitudelatitude
- the latitudezenith
- the zenith- Returns:
- the cosine of the Sun's local hour angle
-
getLocalMeanTime
private static double getLocalMeanTime(double localHour, double sunRightAscensionHours, double approxTimeDays) Calculate local mean time of rising or setting. By 'local' is meant the exact time at the location, assuming that there were no time zone. That is, the time difference between the location and the Meridian depended entirely on the longitude. We can't do anything with this time directly; we must convert it to UTC and then to a local time.- Parameters:
localHour
- the local hoursunRightAscensionHours
- the sun's right ascention in hoursapproxTimeDays
- approximate time days- Returns:
- the fractional number of hours since midnight as a double
-
getTimeUTC
private static double getTimeUTC(Calendar calendar, GeoLocation geoLocation, double zenith, boolean isSunrise) Get sunrise or sunset time in UTC, according to flag. This time is returned as a double and is not adjusted for time-zone.- Parameters:
calendar
- the Calendar object to extract the day of year for calculationgeoLocation
- the GeoLocation object that contains the latitude and longitudezenith
- Sun's zenith, in degreesisSunrise
- True for sunrise and false for sunset.- Returns:
- the time as a double. If an error was encountered in the calculation
(expected behavior for some locations such as near the poles,
Double.NaN
will be returned.
-
getUTCNoon
Return the Universal Coordinated Time (UTC) of solar noon for the given day at the given location on earth. This implementation returns solar noon as the time halfway between sunrise and sunset.NOAACalculator
, the default calculator, returns true solar noon. See The Definition of Chatzos for details on solar noon calculations.- Specified by:
getUTCNoon
in classAstronomicalCalculator
- Parameters:
calendar
- The Calendar representing the date to calculate solar noon forgeoLocation
- The location information used for astronomical calculating sun times.- Returns:
- the time in minutes from zero UTC. If an error was encountered in the calculation (expected behavior for
some locations such as near the poles,
Double.NaN
will be returned. - See Also:
-