1
1
/*
2
2
* Zmanim Java API
3
- * Copyright (C) 2004-2023 Eliyahu Hershfeld
3
+ * Copyright (C) 2004-2025 Eliyahu Hershfeld
4
4
*
5
5
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
6
6
* Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
26
26
* account for leap years. It is not as accurate as the Jean Meeus based {@link NOAACalculator} that is the default calculator
27
27
* use by the KosherJava <em>zmanim</em> library.
28
28
*
29
- * @author © Eliyahu Hershfeld 2004 - 2023
29
+ * @author © Eliyahu Hershfeld 2004 - 2025
30
30
* @author © Kevin Boone 2000
31
31
*/
32
32
public class SunTimesCalculator extends AstronomicalCalculator {
33
+
34
+ /**
35
+ * Default constructor of the SunTimesCalculator.
36
+ */
37
+ public SunTimesCalculator () {
38
+ super ();
39
+ }
33
40
34
41
/**
35
42
* @see com.kosherjava.zmanim.util.AstronomicalCalculator#getCalculatorName()
@@ -57,11 +64,12 @@ public double getUTCSunset(Calendar calendar, GeoLocation geoLocation, double ze
57
64
}
58
65
59
66
/**
60
- * The number of degrees of longitude that corresponds to one- hour time difference.
67
+ * The number of degrees of longitude that corresponds to one hour of time difference.
61
68
*/
62
69
private static final double DEG_PER_HOUR = 360.0 / 24.0 ;
63
70
64
71
/**
72
+ * The sine in degrees.
65
73
* @param deg the degrees
66
74
* @return sin of the angle in degrees
67
75
*/
@@ -70,6 +78,7 @@ private static double sinDeg(double deg) {
70
78
}
71
79
72
80
/**
81
+ * Return the arc cosine in degrees.
73
82
* @param x angle
74
83
* @return acos of the angle in degrees
75
84
*/
@@ -78,6 +87,7 @@ private static double acosDeg(double x) {
78
87
}
79
88
80
89
/**
90
+ * Return the arc sine in degrees.
81
91
* @param x angle
82
92
* @return asin of the angle in degrees
83
93
*/
@@ -86,6 +96,7 @@ private static double asinDeg(double x) {
86
96
}
87
97
88
98
/**
99
+ * Return the tangent in degrees.
89
100
* @param deg degrees
90
101
* @return tan of the angle in degrees
91
102
*/
@@ -145,6 +156,7 @@ private static double getMeanAnomaly(int dayOfYear, double longitude, boolean is
145
156
}
146
157
147
158
/**
159
+ * Returns the Sun's true longitude in degrees.
148
160
* @param sunMeanAnomaly the Sun's mean anomaly in degrees
149
161
* @return the Sun's true longitude in degrees. The result is an angle >= 0 and <= 360.
150
162
*/
@@ -239,14 +251,8 @@ private static double getTimeUTC(Calendar calendar, GeoLocation geoLocation, dou
239
251
240
252
double localMeanTime = getLocalMeanTime (localHour , sunRightAscensionHours ,
241
253
getApproxTimeDays (dayOfYear , getHoursFromMeridian (geoLocation .getLongitude ()), isSunrise ));
242
- double processedTime = localMeanTime - getHoursFromMeridian (geoLocation .getLongitude ());
243
- while (processedTime < 0.0 ) {
244
- processedTime += 24.0 ;
245
- }
246
- while (processedTime >= 24.0 ) {
247
- processedTime -= 24.0 ;
248
- }
249
- return processedTime ;
254
+ double pocessedTime = localMeanTime - getHoursFromMeridian (geoLocation .getLongitude ());
255
+ return pocessedTime > 0 ? pocessedTime % 24 : pocessedTime % 24 + 24 ; // ensure that the time is >= 0 and < 24
250
256
}
251
257
252
258
/**
@@ -278,4 +284,25 @@ public double getUTCNoon(Calendar calendar, GeoLocation geoLocation) {
278
284
}
279
285
return noon ;
280
286
}
287
+
288
+ /**
289
+ * Return the <a href="https://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
290
+ * of midnight for the given day at the given location on earth. This implementation returns solar midnight as 12 hours
291
+ * after utc noon that is halfway between sunrise and sunset.
292
+ * {@link NOAACalculator}, the default calculator, returns true solar noon. See <a href=
293
+ * "https://kosherjava.com/2020/07/02/definition-of-chatzos/">The Definition of Chatzos</a> for details on solar
294
+ * noon calculations.
295
+ * @see com.kosherjava.zmanim.util.AstronomicalCalculator#getUTCNoon(Calendar, GeoLocation)
296
+ * @see NOAACalculator
297
+ *
298
+ * @param calendar
299
+ * The Calendar representing the date to calculate solar noon for
300
+ * @param geoLocation
301
+ * The location information used for astronomical calculating sun times.
302
+ * @return the time in minutes from zero UTC. If an error was encountered in the calculation (expected behavior for
303
+ * some locations such as near the poles, {@link Double#NaN} will be returned.
304
+ */
305
+ public double getUTCMidnight (Calendar calendar , GeoLocation geoLocation ) {
306
+ return (getUTCNoon (calendar , geoLocation ) + 12 );
307
+ }
281
308
}
0 commit comments