Skip to content

Commit 14bcdc0

Browse files
authored
Add getLocalMeanTime()
and make two constants public
1 parent 8880b6c commit 14bcdc0

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ public class AstronomicalCalendar implements Cloneable {
8787
public static final double ASTRONOMICAL_ZENITH = 108;
8888

8989
/** constant for milliseconds in a minute (60,000) */
90-
static final long MINUTE_MILLIS = 60 * 1000;
90+
public static final long MINUTE_MILLIS = 60 * 1000;
9191

9292
/** constant for milliseconds in an hour (3,600,000) */
93-
static final long HOUR_MILLIS = MINUTE_MILLIS * 60;
93+
public static final long HOUR_MILLIS = MINUTE_MILLIS * 60;
9494

9595
/**
9696
* The Java Calendar encapsulated by this class to track the current date used by the class
@@ -638,6 +638,31 @@ public double getSunsetSolarDipFromOffset(double minutes) {
638638
return degrees.doubleValue();
639639
}
640640

641+
/**
642+
* A method that returns <a href="https://en.wikipedia.org/wiki/Local_mean_time">local mean time (LMT)</a> time
643+
* converted to regular clock time for the number of hours (0.0 to 23.999...) passed to this method. This time is
644+
* adjusted from standard time to account for the local latitude. The 360&deg; of the globe divided by 24 calculates
645+
* to 15&deg; per hour with 4 minutes per degree, so at a longitude of 0 , 15, 30 etc... noon is at exactly 12:00pm.
646+
* Lakewood, N.J., with a longitude of -74.222, is 0.7906 away from the closest multiple of 15 at -75&deg;. This is
647+
* multiplied by 4 clock minutes (per degree) to yield 3 minutes and 7 seconds for a noon time of 11:56:53am. This
648+
* method is not tied to the theoretical 15&deg; time zones, but will adjust to the actual time zone and <a href=
649+
* "https://en.wikipedia.org/wiki/Daylight_saving_time">Daylight saving time</a> to return LMT.
650+
*
651+
* @param hours
652+
* the hour (such as 12.0 for noon and 0.0 for midnight) to calculate as LMT. Valid values are in the range of
653+
* 0.0 to 23.999.... An IllegalArgumentException will be thrown if the value does not fit in the expected range.
654+
* @return the Date representing the local mean time (LMT) for the number of hours passed in. In Lakewood, NJ, passing 12
655+
* (noon) will return 11:56:50am.
656+
* @see GeoLocation#getLocalMeanTimeOffset()
657+
*/
658+
public Date getLocalMeanTime(double hours) {
659+
if(hours < 0 || hours >= 24) {
660+
throw new IllegalArgumentException("Hours must between 0 and 23.9999...");
661+
}
662+
return getTimeOffset(getDateFromTime(hours - getGeoLocation().getTimeZone().getRawOffset()
663+
/ (double) HOUR_MILLIS, true), -getGeoLocation().getLocalMeanTimeOffset());
664+
}
665+
641666
/**
642667
* Adjusts the <code>Calendar</code> to deal with edge cases where the location crosses the antimeridian.
643668
*

0 commit comments

Comments
 (0)