@@ -833,7 +833,7 @@ public Date getPlagHamincha120Minutes() {
833833 }
834834
835835 /**
836- * * Method to return <em>alos</em> (dawn) calculated as 60 minutes before {@link #getSunrise() sunrise} or
836+ * Method to return <em>alos</em> (dawn) calculated as 60 minutes before {@link #getSunrise() sunrise} or
837837 * {@link #getSeaLevelSunrise() sea level sunrise} (depending on the {@link #isUseElevation()} setting). This is the
838838 * time to walk the distance of 4 <a href="https://en.wikipedia.org/wiki/Biblical_and_Talmudic_units_of_measurement"
839839 * >mil</a> at 15 minutes a mil. This seems to be the opinion of the
@@ -3486,18 +3486,22 @@ public Date getSofZmanKidushLevanaBetweenMoldos(Date alos, Date tzais) {
34863486 */
34873487 private Date getMoladBasedTime (Date moladBasedTime , Date alos , Date tzais , boolean techila ) {
34883488 Date lastMidnight = getMidnightLastNight ();
3489- Date midnightTonight = getMidnightTonight ();
3490- if (!(moladBasedTime .before (lastMidnight ) || moladBasedTime .after (midnightTonight ))){
3491- if (alos != null || tzais != null ) {
3492- if (techila && !(moladBasedTime .before (tzais ) || moladBasedTime .after (alos ))){
3489+ Date midnightTonight = getMidnightTonight ();
3490+ if (moladBasedTime .before (lastMidnight ) || moladBasedTime .after (midnightTonight )){ // Invalid time, bailout
3491+ return null ;
3492+ } else if (alos == null || tzais == null ){ // Not enough info to adjust
3493+ return moladBasedTime ;
3494+ } else { // It's the daytime, get the next/prev night
3495+ if (moladBasedTime .after (alos ) && moladBasedTime .before (tzais )) {
3496+ if (techila ) {
34933497 return tzais ;
34943498 } else {
34953499 return alos ;
34963500 }
3501+ } else { // It's the night, the provided time is valid
3502+ return moladBasedTime ;
34973503 }
3498- return moladBasedTime ;
34993504 }
3500- return null ;
35013505 }
35023506
35033507 /**
0 commit comments