Skip to content

Commit 46d39f5

Browse files
authored
Improve sunrise/set method names (#254)
* Migrate AstronomicalCalendar to use LocalDate - Fix Timezone Bug - Use correct SUNRISE enum in getInstantFromTime * Fix Javadocs * Rename getSunrise to getSunriseWithElevation. Fix javadoc on `isUseElevation` * Rename getElevationAdjustedSunset/rise to avoid further confusion.
1 parent 3e54af7 commit 46d39f5

4 files changed

Lines changed: 231 additions & 191 deletions

File tree

src/main/java/com/kosherjava/zmanim/AstronomicalCalendar.java

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,13 @@
2323
import java.time.LocalTime;
2424
import java.time.ZoneOffset;
2525
import java.time.ZonedDateTime;
26-
import java.time.temporal.ChronoUnit;
27-
import java.util.TimeZone;
2826

2927
import com.kosherjava.zmanim.util.AstronomicalCalculator;
3028
import com.kosherjava.zmanim.util.GeoLocation;
3129
import com.kosherjava.zmanim.util.ZmanimFormatter;
3230

3331
/**
34-
* A Java calendar that calculates astronomical times such as {@link #getSunrise() sunrise}, {@link #getSunset()
32+
* A Java calendar that calculates astronomical times such as {@link #getSunriseWithElevation() sunrise}, {@link #getSunsetWithElevation()
3533
* sunset} and twilight times. This class contains a {@link #getLocalDate() zonedDateTime} and can therefore use the standard
3634
* Calendar functionality to change dates etc. The calculation engine used to calculate the astronomical times can be
3735
* changed to a different implementation by implementing the abstract {@link AstronomicalCalculator} and setting it with
@@ -112,7 +110,7 @@ public class AstronomicalCalendar implements Cloneable {
112110
private AstronomicalCalculator astronomicalCalculator;
113111

114112
/**
115-
* The getSunrise method returns a <code>Instant</code> representing the
113+
* The getSunriseWithElevation method returns a <code>Instant</code> representing the
116114
* {@link AstronomicalCalculator#getElevationAdjustment(double) elevation adjusted} sunrise time. The zenith used
117115
* for the calculation uses {@link #GEOMETRIC_ZENITH geometric zenith} of 90&deg; plus
118116
* {@link AstronomicalCalculator#getElevationAdjustment(double)}. This is adjusted by the
@@ -127,14 +125,36 @@ public class AstronomicalCalendar implements Cloneable {
127125
* @see #getSeaLevelSunrise()
128126
* @see AstronomicalCalendar#getUTCSunrise
129127
*/
130-
public Instant getSunrise() {
128+
public Instant getSunriseWithElevation() {
131129
double sunrise = getUTCSunrise(GEOMETRIC_ZENITH);
132130
if (Double.isNaN(sunrise)) {
133131
return null;
134132
} else {
135133
return getInstantFromTime(sunrise, SolarEvent.SUNRISE);
136134
}
137135
}
136+
/**
137+
* @deprecated Use {@link #getSunriseWithElevation()} instead.
138+
* This method already accounts for the observer's elevation, but the name
139+
* does not clearly indicate this behavior. The replacement method has a
140+
* clearer and more descriptive name.
141+
*
142+
* @return the <code>Instant</code> representing the exact sunrise time. If the calculation can't be computed such as
143+
* in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
144+
* does not set, a <code>null</code> will be returned. See detailed explanation on top of the page.
145+
* @see AstronomicalCalculator#adjustZenith
146+
* @see #getSeaLevelSunrise()
147+
* @see AstronomicalCalendar#getUTCSunrise
148+
*/
149+
@Deprecated(forRemoval = false)
150+
public Instant getSunrise() {
151+
double sunrise = getUTCSunrise(GEOMETRIC_ZENITH);
152+
if (Double.isNaN(sunrise)) {
153+
return null;
154+
} else {
155+
return getInstantFromTime(sunrise, SolarEvent.SUNRISE);
156+
}
157+
}
138158

139159
/**
140160
* A method that returns the sunrise without {@link AstronomicalCalculator#getElevationAdjustment(double) elevation
@@ -145,7 +165,7 @@ public Instant getSunrise() {
145165
* @return the <code>Instant</code> representing the exact sea-level sunrise time. If the calculation can't be computed
146166
* such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
147167
* where it does not set, a <code>null</code> will be returned. See detailed explanation on top of the page.
148-
* @see AstronomicalCalendar#getSunrise
168+
* @see AstronomicalCalendar#getSunriseWithElevation
149169
* @see AstronomicalCalendar#getUTCSeaLevelSunrise
150170
* @see #getSeaLevelSunset()
151171
*/
@@ -196,25 +216,48 @@ public Instant getBeginAstronomicalTwilight() {
196216
return getSunriseOffsetByDegrees(ASTRONOMICAL_ZENITH);
197217
}
198218

219+
/**
220+
* The getSunsetWithElevation method returns a <code>Instant</code> representing the
221+
* {@link AstronomicalCalculator#getElevationAdjustment(double) elevation adjusted} sunset time. The zenith used for
222+
* the calculation uses {@link #GEOMETRIC_ZENITH geometric zenith} of 90&deg; plus
223+
* {@link AstronomicalCalculator#getElevationAdjustment(double)}. This is adjusted by the
224+
* {@link AstronomicalCalculator} to add approximately 50/60 of a degree to account for 34 archminutes of refraction
225+
* and 16 archminutes for the sun's radius for a total of {@link AstronomicalCalculator#adjustZenith 90.83333&deg;}.
226+
* See documentation for the specific implementation of the {@link AstronomicalCalculator} that you are using. Note:
227+
* In certain cases the calculates sunset will occur before sunrise. This will typically happen when a timezone
228+
* other than the local timezone is used (calculating Los Angeles sunset using a GMT timezone for example). In this
229+
* case the sunset date will be incremented to the following date.
230+
*
231+
* @return the <code>Instant</code> representing the exact sunset time. If the calculation can't be computed such as in
232+
* the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
233+
* does not set, a <code>null</code> will be returned. See detailed explanation on top of the page.
234+
* @see AstronomicalCalculator#adjustZenith
235+
* @see #getSeaLevelSunset()
236+
* @see AstronomicalCalendar#getUTCSunset
237+
*/
238+
public Instant getSunsetWithElevation() {
239+
double sunset = getUTCSunset(GEOMETRIC_ZENITH);
240+
if (Double.isNaN(sunset)) {
241+
return null;
242+
} else {
243+
return getInstantFromTime(sunset, SolarEvent.SUNSET);
244+
}
245+
}
246+
199247
/**
200-
* The getSunset method returns a <code>Instant</code> representing the
201-
* {@link AstronomicalCalculator#getElevationAdjustment(double) elevation adjusted} sunset time. The zenith used for
202-
* the calculation uses {@link #GEOMETRIC_ZENITH geometric zenith} of 90&deg; plus
203-
* {@link AstronomicalCalculator#getElevationAdjustment(double)}. This is adjusted by the
204-
* {@link AstronomicalCalculator} to add approximately 50/60 of a degree to account for 34 archminutes of refraction
205-
* and 16 archminutes for the sun's radius for a total of {@link AstronomicalCalculator#adjustZenith 90.83333&deg;}.
206-
* See documentation for the specific implementation of the {@link AstronomicalCalculator} that you are using. Note:
207-
* In certain cases the calculates sunset will occur before sunrise. This will typically happen when a timezone
208-
* other than the local timezone is used (calculating Los Angeles sunset using a GMT timezone for example). In this
209-
* case the sunset date will be incremented to the following date.
210-
*
248+
* @deprecated Use {@link #getSunsetWithElevation()} instead.
249+
* This method already accounts for the observer's elevation, but its name
250+
* does not clearly reflect that behavior. The replacement method provides
251+
* a more accurate and descriptive name.
252+
*
211253
* @return the <code>Instant</code> representing the exact sunset time. If the calculation can't be computed such as in
212254
* the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
213255
* does not set, a <code>null</code> will be returned. See detailed explanation on top of the page.
214256
* @see AstronomicalCalculator#adjustZenith
215257
* @see #getSeaLevelSunset()
216258
* @see AstronomicalCalendar#getUTCSunset
217259
*/
260+
@Deprecated(forRemoval = false)
218261
public Instant getSunset() {
219262
double sunset = getUTCSunset(GEOMETRIC_ZENITH);
220263
if (Double.isNaN(sunset)) {
@@ -233,9 +276,9 @@ public Instant getSunset() {
233276
* @return the <code>Instant</code> representing the exact sea-level sunset time. If the calculation can't be computed
234277
* such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
235278
* where it does not set, a <code>null</code> will be returned. See detailed explanation on top of the page.
236-
* @see AstronomicalCalendar#getSunset
279+
* @see AstronomicalCalendar#getSunsetWithElevation
237280
* @see AstronomicalCalendar#getUTCSeaLevelSunset
238-
* @see #getSunset()
281+
* @see #getSunsetWithElevation()
239282
*/
240283
public Instant getSeaLevelSunset() {
241284
double sunset = getUTCSeaLevelSunset(GEOMETRIC_ZENITH);
@@ -317,15 +360,15 @@ public static Instant getTimeOffset(Instant time, long offsetMillis) {
317360

318361
/**
319362
* A utility method that returns the time of an offset by degrees below or above the horizon of
320-
* {@link #getSunrise() sunrise}. Note that the degree offset is from the vertical, so for a calculation of 14&deg;
363+
* {@link #getSunriseWithElevation() sunrise}. Note that the degree offset is from the vertical, so for a calculation of 14&deg;
321364
* before sunrise, an offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
322365
*
323366
* @param offsetZenith
324-
* the degrees before {@link #getSunrise()} to use in the calculation. For time after sunrise use
367+
* the degrees before {@link #getSunriseWithElevation()} to use in the calculation. For time after sunrise use
325368
* negative numbers. Note that the degree offset is from the vertical, so for a calculation of 14&deg;
326369
* before sunrise, an offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a
327370
* parameter.
328-
* @return The {@link java.time.Instant} of the offset after (or before) {@link #getSunrise()}. If the calculation
371+
* @return The {@link java.time.Instant} of the offset after (or before) {@link #getSunriseWithElevation()}. If the calculation
329372
* can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does
330373
* not rise, and one where it does not set, a <code>null</code> will be returned. See detailed explanation
331374
* on top of the page.
@@ -337,15 +380,15 @@ public Instant getSunriseOffsetByDegrees(double offsetZenith) {
337380
}
338381

339382
/**
340-
* A utility method that returns the time of an offset by degrees below or above the horizon of {@link #getSunset()
383+
* A utility method that returns the time of an offset by degrees below or above the horizon of {@link #getSunsetWithElevation()
341384
* sunset}. Note that the degree offset is from the vertical, so for a calculation of 14&deg; after sunset, an
342385
* offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
343386
*
344387
* @param offsetZenith
345-
* the degrees after {@link #getSunset()} to use in the calculation. For time before sunset use negative
388+
* the degrees after {@link #getSunsetWithElevation()} to use in the calculation. For time before sunset use negative
346389
* numbers. Note that the degree offset is from the vertical, so for a calculation of 14&deg; after
347390
* sunset, an offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
348-
* @return The {@link java.time.Instant} of the offset after (or before) {@link #getSunset()}. If the calculation can't
391+
* @return The {@link java.time.Instant} of the offset after (or before) {@link #getSunsetWithElevation()}. If the calculation can't
349392
* be computed such as in the Arctic Circle where there is at least one day a year where the sun does not
350393
* rise, and one where it does not set, a <code>null</code> will be returned. See detailed explanation on
351394
* top of the page.
@@ -466,8 +509,8 @@ public long getTemporalHour() {
466509
/**
467510
* A utility method that will allow the calculation of a temporal (solar) hour based on the sunrise and sunset
468511
* passed as parameters to this method. An example of the use of this method would be the calculation of a
469-
* elevation adjusted temporal hour by passing in {@link #getSunrise() sunrise} and
470-
* {@link #getSunset() sunset} as parameters.
512+
* elevation adjusted temporal hour by passing in {@link #getSunriseWithElevation() sunrise} and
513+
* {@link #getSunsetWithElevation() sunset} as parameters.
471514
*
472515
* @param startOfDay
473516
* The start of the day.

0 commit comments

Comments
 (0)