Skip to content

Commit 61ae480

Browse files
authored
Remove code duplication, minor documentation cleanup
1 parent 46d39f5 commit 61ae480

1 file changed

Lines changed: 13 additions & 24 deletions

File tree

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

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
/**
3232
* A Java calendar that calculates astronomical times such as {@link #getSunriseWithElevation() sunrise}, {@link #getSunsetWithElevation()
33-
* sunset} and twilight times. This class contains a {@link #getLocalDate() zonedDateTime} and can therefore use the standard
33+
* sunset} and twilight times. This class contains a {@link #getLocalDate() LocalDate} and can therefore use the standard
3434
* Calendar functionality to change dates etc. The calculation engine used to calculate the astronomical times can be
3535
* changed to a different implementation by implementing the abstract {@link AstronomicalCalculator} and setting it with
3636
* the {@link #setAstronomicalCalculator(AstronomicalCalculator)}. A number of different calculation engine
@@ -61,8 +61,8 @@
6161
* To get the time of sunrise, first set the date you want (if not set, the date will default to today):
6262
*
6363
* <pre>
64-
* ZonedDateTime dateTime = ZonedDateTime.of(1969, Month.FEBRUARY.getValue(), 8, 0, 0, 0, 0, location.getZoneId());
65-
* ac.setZonedDateTime(dateTime);
64+
* LocalDate localDate = LocalDate.of(1969, Month.FEBRUARY, 8);
65+
* ac.setLocalDate(localDate);
6666
* Instant sunrise = ac.getSunrise();
6767
* </pre>
6868
*
@@ -95,7 +95,7 @@ public class AstronomicalCalendar implements Cloneable {
9595
public static final long HOUR_MILLIS = MINUTE_MILLIS * 60;
9696

9797
/**
98-
* The <code>ZonedDateTime</code> encapsulated by this class to track the current date used by the class
98+
* The <code>LocalDate</code> encapsulated by this class to track the current date used by the class
9999
*/
100100
private LocalDate localDate;
101101

@@ -148,12 +148,7 @@ public Instant getSunriseWithElevation() {
148148
*/
149149
@Deprecated(forRemoval = false)
150150
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-
}
151+
return getSunriseWithElevation();
157152
}
158153

159154
/**
@@ -217,7 +212,7 @@ public Instant getBeginAstronomicalTwilight() {
217212
}
218213

219214
/**
220-
* The getSunsetWithElevation method returns a <code>Instant</code> representing the
215+
* The getSunsetWithElevation method returns an <code>Instant</code> representing the
221216
* {@link AstronomicalCalculator#getElevationAdjustment(double) elevation adjusted} sunset time. The zenith used for
222217
* the calculation uses {@link #GEOMETRIC_ZENITH geometric zenith} of 90&deg; plus
223218
* {@link AstronomicalCalculator#getElevationAdjustment(double)}. This is adjusted by the
@@ -259,12 +254,7 @@ public Instant getSunsetWithElevation() {
259254
*/
260255
@Deprecated(forRemoval = false)
261256
public Instant getSunset() {
262-
double sunset = getUTCSunset(GEOMETRIC_ZENITH);
263-
if (Double.isNaN(sunset)) {
264-
return null;
265-
} else {
266-
return getInstantFromTime(sunset, SolarEvent.SUNSET);
267-
}
257+
return getSunsetWithElevation();
268258
}
269259

270260
/**
@@ -401,7 +391,7 @@ public Instant getSunsetOffsetByDegrees(double offsetZenith) {
401391

402392
/**
403393
* Default constructor will set a default {@link GeoLocation#GeoLocation()}, a default
404-
* {@link AstronomicalCalculator#getDefault() AstronomicalCalculator} and default the ZonedDateTime to the current date.
394+
* {@link AstronomicalCalculator#getDefault() AstronomicalCalculator} and default the LocalDate to the current date.
405395
*/
406396
public AstronomicalCalendar() {
407397
this(new GeoLocation());
@@ -765,7 +755,7 @@ public Instant getLocalMeanTime(double hours) {
765755
}
766756

767757
/**
768-
* Adjusts the <code>ZonedDateTime</code> to deal with edge cases where the location crosses the antimeridian.
758+
* Adjusts the <code>LocalDate</code> to deal with edge cases where the location crosses the antimeridian.
769759
*
770760
* @see GeoLocation#getAntimeridianAdjustment(Instant)
771761
* @return the adjusted Calendar
@@ -893,18 +883,18 @@ public void setAstronomicalCalculator(AstronomicalCalculator astronomicalCalcula
893883
}
894884

895885
/**
896-
* returns the <code>ZonedDateTime</code> object encapsulated in this class.
886+
* returns the <code>LocalDate</code> object encapsulated in this class.
897887
*
898-
* @return Returns the ZonedDateTime.
888+
* @return Returns the <code>LocalDate</code>.
899889
*/
900890
public LocalDate getLocalDate() {
901891
return this.localDate;
902892
}
903893

904894
/**
905-
* Sets the <code>ZonedDateTime</code> object for us in this class.
895+
* Sets the <code>LocalDate</code> object for us in this class.
906896
* @param localDate
907-
* The <code>ZonedDateTime</code> to set.
897+
* The <code>LocalDate</code> to set.
908898
*/
909899
public void setLocalDate(LocalDate localDate) {
910900
this.localDate = localDate;
@@ -927,7 +917,6 @@ public Object clone() {
927917
}
928918
if (clone != null) {
929919
clone.setGeoLocation((GeoLocation) getGeoLocation().clone());
930-
//clone.setZonedDateTime(getZonedDateTime().clone());
931920
clone.setAstronomicalCalculator((AstronomicalCalculator) getAstronomicalCalculator().clone());
932921
}
933922
return clone;

0 commit comments

Comments
 (0)