@@ -127,7 +127,7 @@ public Date getSunrise() {
127
127
if (Double .isNaN (sunrise )) {
128
128
return null ;
129
129
} else {
130
- return getDateFromTime (sunrise , true );
130
+ return getDateFromTime (sunrise , SolarEvent . SUNRISE );
131
131
}
132
132
}
133
133
@@ -149,7 +149,7 @@ public Date getSeaLevelSunrise() {
149
149
if (Double .isNaN (sunrise )) {
150
150
return null ;
151
151
} else {
152
- return getDateFromTime (sunrise , true );
152
+ return getDateFromTime (sunrise , SolarEvent . SUNRISE );
153
153
}
154
154
}
155
155
@@ -215,7 +215,7 @@ public Date getSunset() {
215
215
if (Double .isNaN (sunset )) {
216
216
return null ;
217
217
} else {
218
- return getDateFromTime (sunset , false );
218
+ return getDateFromTime (sunset , SolarEvent . SUNSET );
219
219
}
220
220
}
221
221
@@ -236,7 +236,7 @@ public Date getSeaLevelSunset() {
236
236
if (Double .isNaN (sunset )) {
237
237
return null ;
238
238
} else {
239
- return getDateFromTime (sunset , false );
239
+ return getDateFromTime (sunset , SolarEvent . SUNSET );
240
240
}
241
241
}
242
242
@@ -329,7 +329,7 @@ public Date getSunriseOffsetByDegrees(double offsetZenith) {
329
329
if (Double .isNaN (dawn )) {
330
330
return null ;
331
331
} else {
332
- return getDateFromTime (dawn , true );
332
+ return getDateFromTime (dawn , SolarEvent . SUNRISE );
333
333
}
334
334
}
335
335
@@ -352,7 +352,7 @@ public Date getSunsetOffsetByDegrees(double offsetZenith) {
352
352
if (Double .isNaN (sunset )) {
353
353
return null ;
354
354
} else {
355
- return getDateFromTime (sunset , false );
355
+ return getDateFromTime (sunset , SolarEvent . SUNSET );
356
356
}
357
357
}
358
358
@@ -511,7 +511,21 @@ public long getTemporalHour(Date startOfDay, Date endOfDay) {
511
511
*/
512
512
public Date getSunTransit () {
513
513
double noon = getAstronomicalCalculator ().getUTCNoon (getAdjustedCalendar (), getGeoLocation ());
514
- return getDateFromTime (noon , false );
514
+ return getDateFromTime (noon , SolarEvent .NOON );
515
+ }
516
+
517
+ public Date getSunLowerTransit () {
518
+ Calendar cal = getAdjustedCalendar ();
519
+ GeoLocation lowerGeoLocation = (GeoLocation ) getGeoLocation ().clone ();
520
+ double meridian = lowerGeoLocation .getLongitude ();
521
+ double lowerMeridian = meridian + 180 ;
522
+ if (lowerMeridian > 180 ){
523
+ lowerMeridian = lowerMeridian - 360 ;
524
+ cal .add (Calendar .DAY_OF_MONTH , -1 );
525
+ }
526
+ lowerGeoLocation .setLongitude (lowerMeridian );
527
+ double noon = getAstronomicalCalculator ().getUTCNoon (cal , lowerGeoLocation );
528
+ return getDateFromTime (noon , SolarEvent .MIDNIGHT );
515
529
}
516
530
517
531
/**
@@ -556,6 +570,9 @@ public Date getSunTransit(Date startOfDay, Date endOfDay) {
556
570
return getTimeOffset (startOfDay , temporalHour * 6 );
557
571
}
558
572
573
+ protected enum SolarEvent {
574
+ SUNRISE , SUNSET , NOON , MIDNIGHT
575
+ }
559
576
/**
560
577
* A method that returns a <code>Date</code> from the time passed in as a parameter.
561
578
*
@@ -565,7 +582,7 @@ public Date getSunTransit(Date startOfDay, Date endOfDay) {
565
582
* @param isSunrise true if this time is for sunrise
566
583
* @return The Date object representation of the time double
567
584
*/
568
- protected Date getDateFromTime (double time , boolean isSunrise ) {
585
+ protected Date getDateFromTime (double time , SolarEvent solarEvent ) {
569
586
if (Double .isNaN (time )) {
570
587
return null ;
571
588
}
@@ -588,10 +605,12 @@ protected Date getDateFromTime(double time, boolean isSunrise) {
588
605
// Check if a date transition has occurred, or is about to occur - this indicates the date of the event is
589
606
// actually not the target date, but the day prior or after
590
607
int localTimeHours = (int )getGeoLocation ().getLongitude () / 15 ;
591
- if (isSunrise && localTimeHours + hours > 18 ) {
608
+ if (solarEvent == SolarEvent . SUNRISE && localTimeHours + hours > 18 ) {
592
609
cal .add (Calendar .DAY_OF_MONTH , -1 );
593
- } else if (! isSunrise && localTimeHours + hours < 6 ) {
610
+ } else if (solarEvent == SolarEvent . SUNSET && localTimeHours + hours < 6 ) {
594
611
cal .add (Calendar .DAY_OF_MONTH , 1 );
612
+ } else if (solarEvent == SolarEvent .MIDNIGHT && localTimeHours + hours > 12 ) {
613
+ cal .add (Calendar .DAY_OF_MONTH , -1 );
595
614
}
596
615
597
616
cal .set (Calendar .HOUR_OF_DAY , hours );
0 commit comments