Skip to content

Commit 3e14159

Browse files
committed
do not apply day offset to lmt calc
1 parent c9dc1be commit 3e14159

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,6 @@ protected enum SolarEvent {
612612
/**SUNRISE A solar event related to sunrise*/SUNRISE, /**SUNSET A solar event related to sunset*/SUNSET,
613613
/**NOON A solar event related to noon*/NOON, /**MIDNIGHT A solar event related to midnight*/MIDNIGHT
614614
}
615-
616615
/**
617616
* A method that returns a <code>Date</code> from the time passed in as a parameter.
618617
*
@@ -623,6 +622,19 @@ protected enum SolarEvent {
623622
* @return The Date object representation of the time double
624623
*/
625624
protected Date getDateFromTime(double time, SolarEvent solarEvent) {
625+
return getDateFromTime(time, solarEvent, true);
626+
}
627+
628+
/**
629+
* A method that returns a <code>Date</code> from the time passed in as a parameter.
630+
*
631+
* @param time
632+
* The time to be set as the time for the <code>Date</code>. The time expected is in the format: 18.75
633+
* for 6:45:00 PM.time is sunrise and false if it is sunset
634+
* @param solarEvent the type of {@link SolarEvent}
635+
* @return The Date object representation of the time double
636+
*/
637+
protected Date getDateFromTime(double time, SolarEvent solarEvent, boolean adjust) {
626638
if (Double.isNaN(time)) {
627639
return null;
628640
}
@@ -645,18 +657,20 @@ protected Date getDateFromTime(double time, SolarEvent solarEvent) {
645657

646658
// Check if a date transition has occurred, or is about to occur - this indicates the date of the event is
647659
// actually not the target date, but the day prior or after
648-
int localTimeHours = (int)getGeoLocation().getLongitude() / 15;
649-
if (solarEvent == SolarEvent.SUNRISE && localTimeHours + hours > 18) {
650-
cal.add(Calendar.DAY_OF_MONTH, -1);
651-
} else if (solarEvent == SolarEvent.SUNSET && localTimeHours + hours < 6) {
652-
cal.add(Calendar.DAY_OF_MONTH, 1);
653-
} else if (solarEvent == SolarEvent.MIDNIGHT && localTimeHours + hours < 12) {
654-
cal.add(Calendar.DAY_OF_MONTH, 1);
655-
} else if (solarEvent == SolarEvent.NOON && localTimeHours + hours < 0) {
656-
cal.add(Calendar.DAY_OF_MONTH, 1);
657-
} else if (solarEvent == SolarEvent.NOON && localTimeHours + hours > 24) {
658-
cal.add(Calendar.DAY_OF_MONTH, -1);
659-
}
660+
if (adjust) {
661+
int localTimeHours = (int)getGeoLocation().getLongitude() / 15;
662+
if (solarEvent == SolarEvent.SUNRISE && localTimeHours + hours > 18) {
663+
cal.add(Calendar.DAY_OF_MONTH, -1);
664+
} else if (solarEvent == SolarEvent.SUNSET && localTimeHours + hours < 6) {
665+
cal.add(Calendar.DAY_OF_MONTH, 1);
666+
} else if (solarEvent == SolarEvent.MIDNIGHT && localTimeHours + hours < 12) {
667+
cal.add(Calendar.DAY_OF_MONTH, 1);
668+
} else if (solarEvent == SolarEvent.NOON && localTimeHours + hours < 0) {
669+
cal.add(Calendar.DAY_OF_MONTH, 1);
670+
} else if (solarEvent == SolarEvent.NOON && localTimeHours + hours > 24) {
671+
cal.add(Calendar.DAY_OF_MONTH, -1);
672+
}
673+
}
660674

661675
cal.set(Calendar.HOUR_OF_DAY, hours);
662676
cal.set(Calendar.MINUTE, minutes);
@@ -764,7 +778,7 @@ public Date getLocalMeanTime(double hours) {
764778
}
765779
long timezoneOffsetMillis = getCalendar().getTimeZone().getOffset(getCalendar().getTimeInMillis());
766780
return getTimeOffset(getDateFromTime(hours - timezoneOffsetMillis
767-
/ (double) HOUR_MILLIS, SolarEvent.SUNRISE), -getGeoLocation().getLocalMeanTimeOffset(calendar));
781+
/ (double) HOUR_MILLIS, SolarEvent.SUNRISE, false), -getGeoLocation().getLocalMeanTimeOffset(calendar));
768782
}
769783

770784
/**

0 commit comments

Comments
 (0)