Skip to content

Commit

Permalink
Return null if the sun does not reach the time on that day
Browse files Browse the repository at this point in the history
  • Loading branch information
shred committed Apr 30, 2016
1 parent 2c4162e commit cfb687a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/org/shredzone/commons/suncalc/SunTimes.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ private SunTimes(double jnoon, double lw, double phi, double dec, long n, double
*
* @param time
* Time type
* @return Time
* @return Time, or {@code null} if the sun does not reach the {@link Time} on the
* given date (e.g. midnight sun).
*/
public Date getTime(Time time) {
if (time == Time.SOLAR_NOON) {
Expand All @@ -223,6 +224,9 @@ public Date getTime(Time time) {

/**
* Calculates the time when the rising sun reaches the given angle.
*
* @return Time, or {@code null} if the sun does not reach the angle on the
* given date (e.g. midnight sun).
*/
public Date sunriseTime(double angle) {
double jset = getSetJ(angle * RAD, lw, phi, dec, n, m, l);
Expand All @@ -232,6 +236,9 @@ public Date sunriseTime(double angle) {

/**
* Calculates the time when the setting sun reaches the given angle.
*
* @return Time, or {@code null} if the sun does not reach the angle on the
* given date (e.g. midnight sun).
*/
public Date sunsetTime(double angle) {
double jset = getSetJ(angle * RAD, lw, phi, dec, n, m, l);
Expand All @@ -258,6 +265,9 @@ private static long julianCycle(double d, double lw) {
}

private static Date fromJulian(double j) {
if (Double.isNaN(j)) {
return null;
}
return new Date(round((j + 0.5 - J1970) * DAY_MS));
}

Expand Down

0 comments on commit cfb687a

Please sign in to comment.