@hebcal/noaa 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/esm/index.js DELETED
@@ -1,1060 +0,0 @@
1
- import { Temporal } from 'temporal-polyfill';
2
- /**
3
- * java.lang.Math.toRadians
4
- * @param degrees
5
- */
6
- function degreesToRadians(degrees) {
7
- return (degrees * Math.PI) / 180;
8
- }
9
- /**
10
- * java.lang.Math.toDegrees
11
- * @param radians
12
- */
13
- function radiansToDegrees(radians) {
14
- return (radians * 180) / Math.PI;
15
- }
16
- const Long_MIN_VALUE = NaN;
17
- /**
18
- * A class that contains location information such as latitude and longitude required for astronomical calculations. The
19
- * elevation field may not be used by some calculation engines and would be ignored if set. Check the documentation for
20
- * specific implementations of the {@link AstronomicalCalculator} to see if elevation is calculated as part of the
21
- * algorithm.
22
- *
23
- * @author © Eliyahu Hershfeld 2004 - 2016
24
- * @version 1.1
25
- */
26
- export class GeoLocation {
27
- /**
28
- * Method to get the elevation in Meters.
29
- *
30
- * @return Returns the elevation in Meters.
31
- */
32
- getElevation() {
33
- return this.elevation;
34
- }
35
- /**
36
- * Method to set the elevation in Meters <b>above </b> sea level.
37
- *
38
- * @param elevation
39
- * The elevation to set in Meters. An IllegalArgumentException will be thrown if the value is a negative.
40
- */
41
- setElevation(elevation) {
42
- this.elevation = elevation;
43
- }
44
- constructor(name = 'Greenwich, England', latitude = 51.4772, longitude = 0, elevationOrTimeZoneId, timeZoneId) {
45
- /**
46
- * @see #getLocationName()
47
- * @see #setLocationName(String)
48
- */
49
- this.locationName = null;
50
- let elevation = 0;
51
- if (timeZoneId) {
52
- elevation = elevationOrTimeZoneId;
53
- }
54
- else {
55
- timeZoneId = elevationOrTimeZoneId;
56
- }
57
- this.setLocationName(name);
58
- this.setLatitude(latitude);
59
- this.setLongitude(longitude);
60
- this.setElevation(elevation);
61
- this.setTimeZone(timeZoneId);
62
- }
63
- setLatitude(latitude) {
64
- this.latitude = latitude;
65
- }
66
- /**
67
- * @return Returns the latitude.
68
- */
69
- getLatitude() {
70
- return this.latitude;
71
- }
72
- setLongitude(longitude) {
73
- this.longitude = longitude;
74
- }
75
- /**
76
- * @return Returns the longitude.
77
- */
78
- getLongitude() {
79
- return this.longitude;
80
- }
81
- /**
82
- * @return Returns the location name.
83
- */
84
- getLocationName() {
85
- return this.locationName;
86
- }
87
- /**
88
- * @param name
89
- * The setter method for the display name.
90
- */
91
- setLocationName(name) {
92
- this.locationName = name;
93
- }
94
- /**
95
- * @return Returns the timeZone.
96
- */
97
- getTimeZone() {
98
- return this.timeZoneId;
99
- }
100
- /**
101
- * Method to set the TimeZone. If this is ever set after the GeoLocation is set in the
102
- * {@link AstronomicalCalendar}, it is critical that
103
- * {@link AstronomicalCalendar#getCalendar()}.
104
- * {@link java.util.Calendar#setTimeZone(TimeZone) setTimeZone(TimeZone)} be called in order for the
105
- * AstronomicalCalendar to output times in the expected offset. This situation will arise if the
106
- * AstronomicalCalendar is ever {@link AstronomicalCalendar#clone() cloned}.
107
- *
108
- * @param timeZone
109
- * The timeZone to set.
110
- */
111
- setTimeZone(timeZoneId) {
112
- this.timeZoneId = timeZoneId;
113
- }
114
- }
115
- /**
116
- * The commonly used average solar refraction. Calendrical Calculations lists a more accurate global average of
117
- * 34.478885263888294
118
- */
119
- const refraction = 34 / 60;
120
- // private double refraction = 34.478885263888294 / 60d;
121
- /**
122
- * The commonly used average solar radius in minutes of a degree.
123
- */
124
- const solarRadius = 16 / 60;
125
- /**
126
- * The commonly used average earth radius in KM. At this time, this only affects elevation adjustment and not the
127
- * sunrise and sunset calculations. The value currently defaults to 6356.9 KM.
128
- */
129
- const earthRadius = 6356.9; // in KM
130
- /**
131
- * Implementation of sunrise and sunset methods to calculate astronomical times based on the <a
132
- * href="http://noaa.gov">NOAA</a> algorithm. This calculator uses the Java algorithm based on the implementation by <a
133
- * href="http://noaa.gov">NOAA - National Oceanic and Atmospheric Administration</a>'s <a href =
134
- * "http://www.srrb.noaa.gov/highlights/sunrise/sunrise.html">Surface Radiation Research Branch</a>. NOAA's <a
135
- * href="http://www.srrb.noaa.gov/highlights/sunrise/solareqns.PDF">implementation</a> is based on equations from <a
136
- * href="http://www.willbell.com/math/mc1.htm">Astronomical Algorithms</a> by <a
137
- * href="http://en.wikipedia.org/wiki/Jean_Meeus">Jean Meeus</a>. Added to the algorithm is an adjustment of the zenith
138
- * to account for elevation. The algorithm can be found in the <a
139
- * href="http://en.wikipedia.org/wiki/Sunrise_equation">Wikipedia Sunrise Equation</a> article.
140
- *
141
- * @author &copy; Eliyahu Hershfeld 2011 - 2019
142
- */
143
- export class NOAACalculator {
144
- /**
145
- * The getSunrise method Returns a <code>Date</code> representing the
146
- * {@link AstronomicalCalculator#getElevationAdjustment(double) elevation adjusted} sunrise time. The zenith used
147
- * for the calculation uses {@link #GEOMETRIC_ZENITH geometric zenith} of 90&deg; plus
148
- * {@link AstronomicalCalculator#getElevationAdjustment(double)}. This is adjusted by the
149
- * {@link AstronomicalCalculator} to add approximately 50/60 of a degree to account for 34 archminutes of refraction
150
- * and 16 archminutes for the sun's radius for a total of {@link AstronomicalCalculator#adjustZenith 90.83333&deg;}.
151
- * See documentation for the specific implementation of the {@link AstronomicalCalculator} that you are using.
152
- *
153
- * @return the <code>Date</code> representing the exact sunrise time. If the calculation can't be computed such as
154
- * in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
155
- * does not set, a null will be returned. See detailed explanation on top of the page.
156
- * @see AstronomicalCalculator#adjustZenith
157
- * @see #getSeaLevelSunrise()
158
- * @see AstronomicalCalendar#getUTCSunrise
159
- */
160
- getSunrise() {
161
- const sunrise = this.getUTCSunrise0(NOAACalculator.GEOMETRIC_ZENITH);
162
- if (Number.isNaN(sunrise))
163
- return null;
164
- return this.getDateFromTime(sunrise, true);
165
- }
166
- /**
167
- * A method that returns the sunrise without {@link AstronomicalCalculator#getElevationAdjustment(double) elevation
168
- * adjustment}. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light,
169
- * something that is not affected by elevation. This method returns sunrise calculated at sea level. This forms the
170
- * base for dawn calculations that are calculated as a dip below the horizon before sunrise.
171
- *
172
- * @return the <code>Date</code> representing the exact sea-level sunrise time. If the calculation can't be computed
173
- * such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
174
- * where it does not set, a null will be returned. See detailed explanation on top of the page.
175
- * @see AstronomicalCalendar#getSunrise
176
- * @see AstronomicalCalendar#getUTCSeaLevelSunrise
177
- * @see #getSeaLevelSunset()
178
- */
179
- getSeaLevelSunrise() {
180
- const sunrise = this.getUTCSeaLevelSunrise(NOAACalculator.GEOMETRIC_ZENITH);
181
- if (Number.isNaN(sunrise))
182
- return null;
183
- return this.getDateFromTime(sunrise, true);
184
- }
185
- /**
186
- * A method that returns the beginning of civil twilight (dawn) using a zenith of {@link #CIVIL_ZENITH 96&deg;}.
187
- *
188
- * @return The <code>Date</code> of the beginning of civil twilight using a zenith of 96&deg;. If the calculation
189
- * can't be computed, null will be returned. See detailed explanation on top of the page.
190
- * @see #CIVIL_ZENITH
191
- */
192
- getBeginCivilTwilight() {
193
- return this.getSunriseOffsetByDegrees(NOAACalculator.CIVIL_ZENITH);
194
- }
195
- /**
196
- * A method that returns the beginning of nautical twilight using a zenith of {@link #NAUTICAL_ZENITH 102&deg;}.
197
- *
198
- * @return The <code>Date</code> of the beginning of nautical twilight using a zenith of 102&deg;. If the
199
- * calculation can't be computed null will be returned. See detailed explanation on top of the page.
200
- * @see #NAUTICAL_ZENITH
201
- */
202
- getBeginNauticalTwilight() {
203
- return this.getSunriseOffsetByDegrees(NOAACalculator.NAUTICAL_ZENITH);
204
- }
205
- /**
206
- * A method that returns the beginning of astronomical twilight using a zenith of {@link #ASTRONOMICAL_ZENITH
207
- * 108&deg;}.
208
- *
209
- * @return The <code>Date</code> of the beginning of astronomical twilight using a zenith of 108&deg;. If the
210
- * calculation can't be computed, null will be returned. See detailed explanation on top of the page.
211
- * @see #ASTRONOMICAL_ZENITH
212
- */
213
- getBeginAstronomicalTwilight() {
214
- return this.getSunriseOffsetByDegrees(NOAACalculator.ASTRONOMICAL_ZENITH);
215
- }
216
- /**
217
- * The getSunset method Returns a <code>Date</code> representing the
218
- * {@link AstronomicalCalculator#getElevationAdjustment(double) elevation adjusted} sunset time. The zenith used for
219
- * the calculation uses {@link #GEOMETRIC_ZENITH geometric zenith} of 90&deg; plus
220
- * {@link AstronomicalCalculator#getElevationAdjustment(double)}. This is adjusted by the
221
- * {@link AstronomicalCalculator} to add approximately 50/60 of a degree to account for 34 archminutes of refraction
222
- * and 16 archminutes for the sun's radius for a total of {@link AstronomicalCalculator#adjustZenith 90.83333&deg;}.
223
- * See documentation for the specific implementation of the {@link AstronomicalCalculator} that you are using. Note:
224
- * In certain cases the calculates sunset will occur before sunrise. This will typically happen when a timezone
225
- * other than the local timezone is used (calculating Los Angeles sunset using a GMT timezone for example). In this
226
- * case the sunset date will be incremented to the following date.
227
- *
228
- * @return the <code>Date</code> representing the exact sunset time. If the calculation can't be computed such as in
229
- * the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
230
- * does not set, a null will be returned. See detailed explanation on top of the page.
231
- * @see AstronomicalCalculator#adjustZenith
232
- * @see #getSeaLevelSunset()
233
- * @see AstronomicalCalendar#getUTCSunset
234
- */
235
- getSunset() {
236
- const sunset = this.getUTCSunset0(NOAACalculator.GEOMETRIC_ZENITH);
237
- if (Number.isNaN(sunset))
238
- return null;
239
- return this.getDateFromTime(sunset, false);
240
- }
241
- /**
242
- * A method that returns the sunset without {@link AstronomicalCalculator#getElevationAdjustment(double) elevation
243
- * adjustment}. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light,
244
- * something that is not affected by elevation. This method returns sunset calculated at sea level. This forms the
245
- * base for dusk calculations that are calculated as a dip below the horizon after sunset.
246
- *
247
- * @return the <code>Date</code> representing the exact sea-level sunset time. If the calculation can't be computed
248
- * such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
249
- * where it does not set, a null will be returned. See detailed explanation on top of the page.
250
- * @see AstronomicalCalendar#getSunset
251
- * @see AstronomicalCalendar#getUTCSeaLevelSunset 2see {@link #getSunset()}
252
- */
253
- getSeaLevelSunset() {
254
- const sunset = this.getUTCSeaLevelSunset(NOAACalculator.GEOMETRIC_ZENITH);
255
- if (Number.isNaN(sunset))
256
- return null;
257
- return this.getDateFromTime(sunset, false);
258
- }
259
- /**
260
- * A method that returns the end of civil twilight using a zenith of {@link #CIVIL_ZENITH 96&deg;}.
261
- *
262
- * @return The <code>Date</code> of the end of civil twilight using a zenith of {@link #CIVIL_ZENITH 96&deg;}. If
263
- * the calculation can't be computed, null will be returned. See detailed explanation on top of the page.
264
- * @see #CIVIL_ZENITH
265
- */
266
- getEndCivilTwilight() {
267
- return this.getSunsetOffsetByDegrees(NOAACalculator.CIVIL_ZENITH);
268
- }
269
- /**
270
- * A method that returns the end of nautical twilight using a zenith of {@link #NAUTICAL_ZENITH 102&deg;}.
271
- *
272
- * @return The <code>Date</code> of the end of nautical twilight using a zenith of {@link #NAUTICAL_ZENITH 102&deg;}
273
- * . If the calculation can't be computed, null will be returned. See detailed explanation on top of the
274
- * page.
275
- * @see #NAUTICAL_ZENITH
276
- */
277
- getEndNauticalTwilight() {
278
- return this.getSunsetOffsetByDegrees(NOAACalculator.NAUTICAL_ZENITH);
279
- }
280
- /**
281
- * A method that returns the end of astronomical twilight using a zenith of {@link #ASTRONOMICAL_ZENITH 108&deg;}.
282
- *
283
- * @return the <code>Date</code> of the end of astronomical twilight using a zenith of {@link #ASTRONOMICAL_ZENITH
284
- * 108&deg;}. If the calculation can't be computed, null will be returned. See detailed explanation on top
285
- * of the page.
286
- * @see #ASTRONOMICAL_ZENITH
287
- */
288
- getEndAstronomicalTwilight() {
289
- return this.getSunsetOffsetByDegrees(NOAACalculator.ASTRONOMICAL_ZENITH);
290
- }
291
- /**
292
- * A utility method that returns a date offset by the offset time passed in. Please note that the level of light
293
- * during twilight is not affected by elevation, so if this is being used to calculate an offset before sunrise or
294
- * after sunset with the intent of getting a rough "level of light" calculation, the sunrise or sunset time passed
295
- * to this method should be sea level sunrise and sunset.
296
- *
297
- * @param time
298
- * the start time
299
- * @param offset
300
- * the offset in milliseconds to add to the time.
301
- * @return the {@link java.util.Date} with the offset in milliseconds added to it
302
- */
303
- static getTimeOffset(time, offset) {
304
- if (time === null || offset === Long_MIN_VALUE || Number.isNaN(offset)) {
305
- return null;
306
- }
307
- return time.add({ milliseconds: offset });
308
- }
309
- /**
310
- * A utility method that returns the time of an offset by degrees below or above the horizon of
311
- * {@link #getSunrise() sunrise}. Note that the degree offset is from the vertical, so for a calculation of 14&deg;
312
- * before sunrise, an offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
313
- *
314
- * @param offsetZenith
315
- * the degrees before {@link #getSunrise()} to use in the calculation. For time after sunrise use
316
- * negative numbers. Note that the degree offset is from the vertical, so for a calculation of 14&deg;
317
- * before sunrise, an offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a
318
- * parameter.
319
- * @return The {@link java.util.Date} of the offset after (or before) {@link #getSunrise()}. If the calculation
320
- * can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does
321
- * not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the
322
- * page.
323
- */
324
- getSunriseOffsetByDegrees(offsetZenith) {
325
- const dawn = this.getUTCSunrise0(offsetZenith);
326
- if (Number.isNaN(dawn))
327
- return null;
328
- return this.getDateFromTime(dawn, true);
329
- }
330
- /**
331
- * A utility method that returns the time of an offset by degrees below or above the horizon of {@link #getSunset()
332
- * sunset}. Note that the degree offset is from the vertical, so for a calculation of 14&deg; after sunset, an
333
- * offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
334
- *
335
- * @param offsetZenith
336
- * the degrees after {@link #getSunset()} to use in the calculation. For time before sunset use negative
337
- * numbers. Note that the degree offset is from the vertical, so for a calculation of 14&deg; after
338
- * sunset, an offset of 14 + {@link #GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
339
- * @return The {@link java.util.Date}of the offset after (or before) {@link #getSunset()}. If the calculation can't
340
- * be computed such as in the Arctic Circle where there is at least one day a year where the sun does not
341
- * rise, and one where it does not set, a null will be returned. See detailed explanation on top of the
342
- * page.
343
- */
344
- getSunsetOffsetByDegrees(offsetZenith) {
345
- const sunset = this.getUTCSunset0(offsetZenith);
346
- if (Number.isNaN(sunset))
347
- return null;
348
- return this.getDateFromTime(sunset, false);
349
- }
350
- /**
351
- * A constructor that takes in <a href="http://en.wikipedia.org/wiki/Geolocation">geolocation</a> information as a
352
- * parameter. The default {@link AstronomicalCalculator#getDefault() AstronomicalCalculator} used for solar
353
- * calculations is the the {@link NOAACalculator}.
354
- *
355
- * @param geoLocation
356
- * The location information used for calculating astronomical sun times.
357
- *
358
- * @see #setAstronomicalCalculator(AstronomicalCalculator) for changing the calculator class.
359
- */
360
- constructor(geoLocation, date) {
361
- this.date = date;
362
- this.geoLocation = geoLocation;
363
- }
364
- /**
365
- * A method that returns the sunrise in UTC time without correction for time zone offset from GMT and without using
366
- * daylight savings time.
367
- *
368
- * @param zenith
369
- * the degrees below the horizon. For time after sunrise use negative numbers.
370
- * @return The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
371
- * Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
372
- * not set, {@link Double#NaN} will be returned. See detailed explanation on top of the page.
373
- */
374
- getUTCSunrise0(zenith) {
375
- return this.getUTCSunrise(this.getAdjustedDate(), this.geoLocation, zenith, true);
376
- }
377
- /**
378
- * A method that returns the sunrise in UTC time without correction for time zone offset from GMT and without using
379
- * daylight savings time. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible
380
- * light, something that is not affected by elevation. This method returns UTC sunrise calculated at sea level. This
381
- * forms the base for dawn calculations that are calculated as a dip below the horizon before sunrise.
382
- *
383
- * @param zenith
384
- * the degrees below the horizon. For time after sunrise use negative numbers.
385
- * @return The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
386
- * Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
387
- * not set, {@link Double#NaN} will be returned. See detailed explanation on top of the page.
388
- * @see AstronomicalCalendar#getUTCSunrise
389
- * @see AstronomicalCalendar#getUTCSeaLevelSunset
390
- */
391
- getUTCSeaLevelSunrise(zenith) {
392
- return this.getUTCSunrise(this.getAdjustedDate(), this.geoLocation, zenith, false);
393
- }
394
- /**
395
- * A method that returns the sunset in UTC time without correction for time zone offset from GMT and without using
396
- * daylight savings time.
397
- *
398
- * @param zenith
399
- * the degrees below the horizon. For time after sunset use negative numbers.
400
- * @return The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
401
- * Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
402
- * not set, {@link Double#NaN} will be returned. See detailed explanation on top of the page.
403
- * @see AstronomicalCalendar#getUTCSeaLevelSunset
404
- */
405
- getUTCSunset0(zenith) {
406
- return this.getUTCSunset(this.getAdjustedDate(), this.geoLocation, zenith, true);
407
- }
408
- /**
409
- * A method that returns the sunset in UTC time without correction for elevation, time zone offset from GMT and
410
- * without using daylight savings time. Non-sunrise and sunset calculations such as dawn and dusk, depend on the
411
- * amount of visible light, something that is not affected by elevation. This method returns UTC sunset calculated
412
- * at sea level. This forms the base for dusk calculations that are calculated as a dip below the horizon after
413
- * sunset.
414
- *
415
- * @param zenith
416
- * the degrees below the horizon. For time before sunset use negative numbers.
417
- * @return The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
418
- * Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
419
- * not set, {@link Double#NaN} will be returned. See detailed explanation on top of the page.
420
- * @see AstronomicalCalendar#getUTCSunset
421
- * @see AstronomicalCalendar#getUTCSeaLevelSunrise
422
- */
423
- getUTCSeaLevelSunset(zenith) {
424
- return this.getUTCSunset(this.getAdjustedDate(), this.geoLocation, zenith, false);
425
- }
426
- /**
427
- * Adjusts the <code>Calendar</code> to deal with edge cases where the location crosses the antimeridian.
428
- *
429
- * @see GeoLocation#getAntimeridianAdjustment()
430
- * @return the adjusted Calendar
431
- */
432
- getAdjustedDate() {
433
- return this.date;
434
- }
435
- /**
436
- * Method to return the adjustment to the zenith required to account for the elevation. Since a person at a higher
437
- * elevation can see farther below the horizon, the calculation for sunrise / sunset is calculated below the horizon
438
- * used at sea level. This is only used for sunrise and sunset and not times before or after it such as
439
- * {@link AstronomicalCalendar#getBeginNauticalTwilight() nautical twilight} since those
440
- * calculations are based on the level of available light at the given dip below the horizon, something that is not
441
- * affected by elevation, the adjustment should only made if the zenith == 90&deg; {@link #adjustZenith adjusted}
442
- * for refraction and solar radius. The algorithm used is
443
- *
444
- * <pre>
445
- * elevationAdjustment = Math.toDegrees(Math.acos(earthRadiusInMeters / (earthRadiusInMeters + elevationMeters)));
446
- * </pre>
447
- *
448
- * The source of this algorithm is <a href="http://www.calendarists.com">Calendrical Calculations</a> by Edward M.
449
- * Reingold and Nachum Dershowitz. An alternate algorithm that produces an almost identical (but not accurate)
450
- * result found in Ma'aglay Tzedek by Moishe Kosower and other sources is:
451
- *
452
- * <pre>
453
- * elevationAdjustment = 0.0347 * Math.sqrt(elevationMeters);
454
- * </pre>
455
- *
456
- * @param elevation
457
- * elevation in Meters.
458
- * @return the adjusted zenith
459
- */
460
- getElevationAdjustment(elevation) {
461
- // double elevationAdjustment = 0.0347 * Math.sqrt(elevation);
462
- const elevationAdjustment = radiansToDegrees(Math.acos(earthRadius / (earthRadius + elevation / 1000)));
463
- return elevationAdjustment;
464
- }
465
- /**
466
- * Adjusts the zenith of astronomical sunrise and sunset to account for solar refraction, solar radius and
467
- * elevation. The value for Sun's zenith and true rise/set Zenith (used in this class and subclasses) is the angle
468
- * that the center of the Sun makes to a line perpendicular to the Earth's surface. If the Sun were a point and the
469
- * Earth were without an atmosphere, true sunset and sunrise would correspond to a 90&deg; zenith. Because the Sun
470
- * is not a point, and because the atmosphere refracts light, this 90&deg; zenith does not, in fact, correspond to
471
- * true sunset or sunrise, instead the centre of the Sun's disk must lie just below the horizon for the upper edge
472
- * to be obscured. This means that a zenith of just above 90&deg; must be used. The Sun subtends an angle of 16
473
- * minutes of arc (this can be changed via the {@link #setSolarRadius(double)} method , and atmospheric refraction
474
- * accounts for 34 minutes or so (this can be changed via the {@link #setRefraction(double)} method), giving a total
475
- * of 50 arcminutes. The total value for ZENITH is 90+(5/6) or 90.8333333&deg; for true sunrise/sunset. Since a
476
- * person at an elevation can see blow the horizon of a person at sea level, this will also adjust the zenith to
477
- * account for elevation if available. Note that this will only adjust the value if the zenith is exactly 90 degrees.
478
- * For values below and above this no correction is done. As an example, astronomical twilight is when the sun is
479
- * 18&deg; below the horizon or {@link AstronomicalCalendar#ASTRONOMICAL_ZENITH 108&deg;
480
- * below the zenith}. This is traditionally calculated with none of the above mentioned adjustments. The same goes
481
- * for various <em>tzais</em> and <em>alos</em> times such as the
482
- * {@link ZmanimCalendar#ZENITH_16_POINT_1 16.1&deg;} dip used in
483
- * {@link ComplexZmanimCalendar#getAlos16Point1Degrees()}.
484
- *
485
- * @param zenith
486
- * the azimuth below the vertical zenith of 90&deg;. For sunset typically the {@link #adjustZenith
487
- * zenith} used for the calculation uses geometric zenith of 90&deg; and {@link #adjustZenith adjusts}
488
- * this slightly to account for solar refraction and the sun's radius. Another example would be
489
- * {@link AstronomicalCalendar#getEndNauticalTwilight()} that passes
490
- * {@link AstronomicalCalendar#NAUTICAL_ZENITH} to this method.
491
- * @param elevation
492
- * elevation in Meters.
493
- * @return The zenith adjusted to include the {@link #getSolarRadius sun's radius}, {@link #getRefraction
494
- * refraction} and {@link #getElevationAdjustment elevation} adjustment. This will only be adjusted for
495
- * sunrise and sunset (if the zenith == 90&deg;)
496
- * @see #getElevationAdjustment(double)
497
- */
498
- adjustZenith(zenith, elevation) {
499
- let adjustedZenith = zenith;
500
- if (zenith === NOAACalculator.GEOMETRIC_ZENITH) {
501
- // only adjust if it is exactly sunrise or sunset
502
- adjustedZenith =
503
- zenith +
504
- (solarRadius + refraction + this.getElevationAdjustment(elevation));
505
- }
506
- return adjustedZenith;
507
- }
508
- /**
509
- * @see AstronomicalCalculator#getUTCSunrise(Calendar, GeoLocation, double, boolean)
510
- */
511
- getUTCSunrise(date, geoLocation, zenith, adjustForElevation) {
512
- const elevation = adjustForElevation
513
- ? geoLocation.getElevation()
514
- : 0;
515
- const adjustedZenith = this.adjustZenith(zenith, elevation);
516
- let sunrise = NOAACalculator.getSunriseUTC(NOAACalculator.getJulianDay(date), geoLocation.getLatitude(), -geoLocation.getLongitude(), adjustedZenith);
517
- sunrise = sunrise / 60;
518
- // ensure that the time is >= 0 and < 24
519
- while (sunrise < 0) {
520
- sunrise += 24;
521
- }
522
- while (sunrise >= 24) {
523
- sunrise -= 24;
524
- }
525
- return sunrise;
526
- }
527
- /**
528
- * @see AstronomicalCalculator#getUTCSunset(Calendar, GeoLocation, double, boolean)
529
- */
530
- getUTCSunset(date, geoLocation, zenith, adjustForElevation) {
531
- const elevation = adjustForElevation
532
- ? geoLocation.getElevation()
533
- : 0;
534
- const adjustedZenith = this.adjustZenith(zenith, elevation);
535
- let sunset = NOAACalculator.getSunsetUTC(NOAACalculator.getJulianDay(date), geoLocation.getLatitude(), -geoLocation.getLongitude(), adjustedZenith);
536
- sunset = sunset / 60;
537
- // ensure that the time is >= 0 and < 24
538
- while (sunset < 0) {
539
- sunset += 24;
540
- }
541
- while (sunset >= 24) {
542
- sunset -= 24;
543
- }
544
- return sunset;
545
- }
546
- /**
547
- * A utility method that will allow the calculation of a temporal (solar) hour based on the sunrise and sunset
548
- * passed as parameters to this method. An example of the use of this method would be the calculation of a
549
- * non-elevation adjusted temporal hour by passing in {@link #getSeaLevelSunrise() sea level sunrise} and
550
- * {@link #getSeaLevelSunset() sea level sunset} as parameters.
551
- *
552
- * @param startOfday
553
- * The start of the day.
554
- * @param endOfDay
555
- * The end of the day.
556
- *
557
- * @return the <code>long</code> millisecond length of the temporal hour. If the calculation can't be computed a
558
- * {@link Long#MIN_VALUE} will be returned. See detailed explanation on top of the page.
559
- *
560
- * @see #getTemporalHour()
561
- */
562
- getTemporalHour(startOfday = this.getSeaLevelSunrise(), endOfDay = this.getSeaLevelSunset()) {
563
- if (startOfday === null || endOfDay === null) {
564
- return Long_MIN_VALUE;
565
- }
566
- const delta = endOfDay.epochMilliseconds - startOfday.epochMilliseconds;
567
- return Math.floor(delta / 12);
568
- }
569
- /**
570
- * A method that returns sundial or solar noon. It occurs when the Sun is <a href
571
- * ="http://en.wikipedia.org/wiki/Transit_%28astronomy%29">transiting</a> the <a
572
- * href="http://en.wikipedia.org/wiki/Meridian_%28astronomy%29">celestial meridian</a>. In this class it is
573
- * calculated as halfway between the sunrise and sunset passed to this method. This time can be slightly off the
574
- * real transit time due to changes in declination (the lengthening or shortening day).
575
- *
576
- * @param startOfDay
577
- * the start of day for calculating the sun's transit. This can be sea level sunrise, visual sunrise (or
578
- * any arbitrary start of day) passed to this method.
579
- * @param endOfDay
580
- * the end of day for calculating the sun's transit. This can be sea level sunset, visual sunset (or any
581
- * arbitrary end of day) passed to this method.
582
- *
583
- * @return the <code>Date</code> representing Sun's transit. If the calculation can't be computed such as in the
584
- * Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
585
- * not set, null will be returned. See detailed explanation on top of the page.
586
- */
587
- getSunTransit(startOfDay = this.getSeaLevelSunrise(), endOfDay = this.getSeaLevelSunset()) {
588
- const temporalHour = this.getTemporalHour(startOfDay, endOfDay);
589
- return NOAACalculator.getTimeOffset(startOfDay, temporalHour * 6);
590
- }
591
- /**
592
- * A method that returns a <code>Date</code> from the time passed in as a parameter.
593
- *
594
- * @param time
595
- * The time to be set as the time for the <code>Date</code>. The time expected is in the format: 18.75
596
- * for 6:45:00 PM.
597
- * @param isSunrise true if the time is sunrise, and false if it is sunset
598
- * @return The Date.
599
- */
600
- getDateFromTime(time, isSunrise) {
601
- if (Number.isNaN(time)) {
602
- return null;
603
- }
604
- let calculatedTime = time;
605
- let cal = this.getAdjustedDate();
606
- // let cal = new Temporal.PlainDate(adj.year, adj.month, adj.day);
607
- const hours = Math.trunc(calculatedTime); // retain only the hours
608
- calculatedTime -= hours;
609
- const minutes = Math.trunc((calculatedTime *= 60)); // retain only the minutes
610
- calculatedTime -= minutes;
611
- const seconds = Math.trunc((calculatedTime *= 60)); // retain only the seconds
612
- calculatedTime -= seconds; // remaining milliseconds
613
- // Check if a date transition has occurred, or is about to occur - this indicates the date of the event is
614
- // actually not the target date, but the day prior or after
615
- const localTimeHours = Math.trunc(this.geoLocation.getLongitude() / 15);
616
- if (isSunrise && localTimeHours + hours > 18) {
617
- cal = cal.add({ days: -1 });
618
- // cal = cal.minus({days: 1});
619
- }
620
- else if (!isSunrise && localTimeHours + hours < 6) {
621
- cal = cal.add({ days: 1 });
622
- }
623
- return cal
624
- .toZonedDateTime({
625
- timeZone: 'UTC',
626
- plainTime: new Temporal.PlainTime(hours, minutes, seconds, Math.trunc(calculatedTime * 1000)),
627
- })
628
- .withTimeZone(this.geoLocation.getTimeZone());
629
- }
630
- /**
631
- * Return the <a href="http://en.wikipedia.org/wiki/Julian_day">Julian day</a> from a Java Calendar
632
- *
633
- * @param calendar
634
- * The Java Calendar
635
- * @return the Julian day corresponding to the date Note: Number is returned for start of day. Fractional days
636
- * should be added later.
637
- */
638
- static getJulianDay(date) {
639
- let { year, month } = date;
640
- const { day } = date;
641
- if (month <= 2) {
642
- year -= 1;
643
- month += 12;
644
- }
645
- const a = Math.trunc(year / 100);
646
- const b = Math.trunc(2 - a + a / 4);
647
- return (Math.floor(365.25 * (year + 4716)) +
648
- Math.floor(30.6001 * (month + 1)) +
649
- day +
650
- b -
651
- 1524.5);
652
- }
653
- /**
654
- * Convert <a href="http://en.wikipedia.org/wiki/Julian_day">Julian day</a> to centuries since J2000.0.
655
- *
656
- * @param julianDay
657
- * the Julian Day to convert
658
- * @return the centuries since 2000 Julian corresponding to the Julian Day
659
- */
660
- static getJulianCenturiesFromJulianDay(julianDay) {
661
- return ((julianDay - NOAACalculator.JULIAN_DAY_JAN_1_2000) /
662
- NOAACalculator.JULIAN_DAYS_PER_CENTURY);
663
- }
664
- /**
665
- * Convert centuries since J2000.0 to <a href="http://en.wikipedia.org/wiki/Julian_day">Julian day</a>.
666
- *
667
- * @param julianCenturies
668
- * the number of Julian centuries since J2000.0
669
- * @return the Julian Day corresponding to the Julian centuries passed in
670
- */
671
- static getJulianDayFromJulianCenturies(julianCenturies) {
672
- return (julianCenturies * NOAACalculator.JULIAN_DAYS_PER_CENTURY +
673
- NOAACalculator.JULIAN_DAY_JAN_1_2000);
674
- }
675
- /**
676
- * Returns the Geometric <a href="http://en.wikipedia.org/wiki/Mean_longitude">Mean Longitude</a> of the Sun.
677
- *
678
- * @param julianCenturies
679
- * the number of Julian centuries since J2000.0
680
- * @return the Geometric Mean Longitude of the Sun in degrees
681
- */
682
- static getSunGeometricMeanLongitude(julianCenturies) {
683
- let longitude = 280.46646 + julianCenturies * (36000.76983 + 0.0003032 * julianCenturies);
684
- while (longitude > 360) {
685
- longitude -= 360;
686
- }
687
- while (longitude < 0) {
688
- longitude += 360;
689
- }
690
- return longitude; // in degrees
691
- }
692
- /**
693
- * Returns the Geometric <a href="http://en.wikipedia.org/wiki/Mean_anomaly">Mean Anomaly</a> of the Sun.
694
- *
695
- * @param julianCenturies
696
- * the number of Julian centuries since J2000.0
697
- * @return the Geometric Mean Anomaly of the Sun in degrees
698
- */
699
- static getSunGeometricMeanAnomaly(julianCenturies) {
700
- return (357.52911 + julianCenturies * (35999.05029 - 0.0001537 * julianCenturies)); // in degrees
701
- }
702
- /**
703
- * Return the <a href="http://en.wikipedia.org/wiki/Eccentricity_%28orbit%29">eccentricity of earth's orbit</a>.
704
- *
705
- * @param julianCenturies
706
- * the number of Julian centuries since J2000.0
707
- * @return the unitless eccentricity
708
- */
709
- static getEarthOrbitEccentricity(julianCenturies) {
710
- return (0.016708634 -
711
- julianCenturies * (0.000042037 + 0.0000001267 * julianCenturies)); // unitless
712
- }
713
- /**
714
- * Returns the <a href="http://en.wikipedia.org/wiki/Equation_of_the_center">equation of center</a> for the sun.
715
- *
716
- * @param julianCenturies
717
- * the number of Julian centuries since J2000.0
718
- * @return the equation of center for the sun in degrees
719
- */
720
- static getSunEquationOfCenter(julianCenturies) {
721
- const m = NOAACalculator.getSunGeometricMeanAnomaly(julianCenturies);
722
- const mrad = degreesToRadians(m);
723
- const sinm = Math.sin(mrad);
724
- const sin2m = Math.sin(mrad + mrad);
725
- const sin3m = Math.sin(mrad + mrad + mrad);
726
- return (sinm *
727
- (1.914602 - julianCenturies * (0.004817 + 0.000014 * julianCenturies)) +
728
- sin2m * (0.019993 - 0.000101 * julianCenturies) +
729
- sin3m * 0.000289); // in degrees
730
- }
731
- /**
732
- * Return the true longitude of the sun
733
- *
734
- * @param julianCenturies
735
- * the number of Julian centuries since J2000.0
736
- * @return the sun's true longitude in degrees
737
- */
738
- static getSunTrueLongitude(julianCenturies) {
739
- const sunLongitude = NOAACalculator.getSunGeometricMeanLongitude(julianCenturies);
740
- const center = NOAACalculator.getSunEquationOfCenter(julianCenturies);
741
- return sunLongitude + center; // in degrees
742
- }
743
- // /**
744
- // * Returns the <a href="http://en.wikipedia.org/wiki/True_anomaly">true anamoly</a> of the sun.
745
- // *
746
- // * @param julianCenturies
747
- // * the number of Julian centuries since J2000.0
748
- // * @return the sun's true anamoly in degrees
749
- // */
750
- // private static double getSunTrueAnomaly(double julianCenturies) {
751
- // double meanAnomaly = getSunGeometricMeanAnomaly(julianCenturies);
752
- // double equationOfCenter = getSunEquationOfCenter(julianCenturies);
753
- //
754
- // return meanAnomaly + equationOfCenter; // in degrees
755
- // }
756
- /**
757
- * Return the apparent longitude of the sun
758
- *
759
- * @param julianCenturies
760
- * the number of Julian centuries since J2000.0
761
- * @return sun's apparent longitude in degrees
762
- */
763
- static getSunApparentLongitude(julianCenturies) {
764
- const sunTrueLongitude = NOAACalculator.getSunTrueLongitude(julianCenturies);
765
- const omega = 125.04 - 1934.136 * julianCenturies;
766
- const lambda = sunTrueLongitude - 0.00569 - 0.00478 * Math.sin(degreesToRadians(omega));
767
- return lambda; // in degrees
768
- }
769
- /**
770
- * Returns the mean <a href="http://en.wikipedia.org/wiki/Axial_tilt">obliquity of the ecliptic</a> (Axial tilt).
771
- *
772
- * @param julianCenturies
773
- * the number of Julian centuries since J2000.0
774
- * @return the mean obliquity in degrees
775
- */
776
- static getMeanObliquityOfEcliptic(julianCenturies) {
777
- const seconds = 21.448 -
778
- julianCenturies *
779
- (46.815 + julianCenturies * (0.00059 - julianCenturies * 0.001813));
780
- return 23 + (26 + seconds / 60) / 60; // in degrees
781
- }
782
- /**
783
- * Returns the corrected <a href="http://en.wikipedia.org/wiki/Axial_tilt">obliquity of the ecliptic</a> (Axial
784
- * tilt).
785
- *
786
- * @param julianCenturies
787
- * the number of Julian centuries since J2000.0
788
- * @return the corrected obliquity in degrees
789
- */
790
- static getObliquityCorrection(julianCenturies) {
791
- const obliquityOfEcliptic = NOAACalculator.getMeanObliquityOfEcliptic(julianCenturies);
792
- const omega = 125.04 - 1934.136 * julianCenturies;
793
- return obliquityOfEcliptic + 0.00256 * Math.cos(degreesToRadians(omega)); // in degrees
794
- }
795
- /**
796
- * Return the <a href="http://en.wikipedia.org/wiki/Declination">declination</a> of the sun.
797
- *
798
- * @param julianCenturies
799
- * the number of Julian centuries since J2000.0
800
- * @return
801
- * the sun's declination in degrees
802
- */
803
- static getSunDeclination(julianCenturies) {
804
- const obliquityCorrection = NOAACalculator.getObliquityCorrection(julianCenturies);
805
- const lambda = NOAACalculator.getSunApparentLongitude(julianCenturies);
806
- const sint = Math.sin(degreesToRadians(obliquityCorrection)) *
807
- Math.sin(degreesToRadians(lambda));
808
- const theta = radiansToDegrees(Math.asin(sint));
809
- return theta; // in degrees
810
- }
811
- /**
812
- * Return the <a href="http://en.wikipedia.org/wiki/Equation_of_time">Equation of Time</a> - the difference between
813
- * true solar time and mean solar time
814
- *
815
- * @param julianCenturies
816
- * the number of Julian centuries since J2000.0
817
- * @return equation of time in minutes of time
818
- */
819
- static getEquationOfTime(julianCenturies) {
820
- const epsilon = NOAACalculator.getObliquityCorrection(julianCenturies);
821
- const geomMeanLongSun = NOAACalculator.getSunGeometricMeanLongitude(julianCenturies);
822
- const eccentricityEarthOrbit = NOAACalculator.getEarthOrbitEccentricity(julianCenturies);
823
- const geomMeanAnomalySun = NOAACalculator.getSunGeometricMeanAnomaly(julianCenturies);
824
- let y = Math.tan(degreesToRadians(epsilon) / 2);
825
- y *= y;
826
- const sin2l0 = Math.sin(2 * degreesToRadians(geomMeanLongSun));
827
- const sinm = Math.sin(degreesToRadians(geomMeanAnomalySun));
828
- const cos2l0 = Math.cos(2 * degreesToRadians(geomMeanLongSun));
829
- const sin4l0 = Math.sin(4 * degreesToRadians(geomMeanLongSun));
830
- const sin2m = Math.sin(2 * degreesToRadians(geomMeanAnomalySun));
831
- const equationOfTime = y * sin2l0 -
832
- 2 * eccentricityEarthOrbit * sinm +
833
- 4 * eccentricityEarthOrbit * y * sinm * cos2l0 -
834
- 0.5 * y * y * sin4l0 -
835
- 1.25 * eccentricityEarthOrbit * eccentricityEarthOrbit * sin2m;
836
- return radiansToDegrees(equationOfTime) * 4; // in minutes of time
837
- }
838
- /**
839
- * Return the <a href="http://en.wikipedia.org/wiki/Hour_angle">hour angle</a> of the sun at sunrise for the
840
- * latitude.
841
- *
842
- * @param lat
843
- * , the latitude of observer in degrees
844
- * @param solarDec
845
- * the declination angle of sun in degrees
846
- * @param zenith
847
- * the zenith
848
- * @return hour angle of sunrise in radians
849
- */
850
- static getSunHourAngleAtSunrise(lat, solarDec, zenith) {
851
- const latRad = degreesToRadians(lat);
852
- const sdRad = degreesToRadians(solarDec);
853
- return Math.acos(Math.cos(degreesToRadians(zenith)) /
854
- (Math.cos(latRad) * Math.cos(sdRad)) -
855
- Math.tan(latRad) * Math.tan(sdRad)); // in radians
856
- }
857
- /**
858
- * Returns the <a href="http://en.wikipedia.org/wiki/Hour_angle">hour angle</a> of the sun at sunset for the
859
- * latitude. TODO: use - {@link #getSunHourAngleAtSunrise(double, double, double)} implementation to avoid
860
- * duplication of code.
861
- *
862
- * @param lat
863
- * the latitude of observer in degrees
864
- * @param solarDec
865
- * the declination angle of sun in degrees
866
- * @param zenith
867
- * the zenith
868
- * @return the hour angle of sunset in radians
869
- */
870
- static getSunHourAngleAtSunset(lat, solarDec, zenith) {
871
- const latRad = degreesToRadians(lat);
872
- const sdRad = degreesToRadians(solarDec);
873
- const hourAngle = Math.acos(Math.cos(degreesToRadians(zenith)) /
874
- (Math.cos(latRad) * Math.cos(sdRad)) -
875
- Math.tan(latRad) * Math.tan(sdRad));
876
- return -hourAngle; // in radians
877
- }
878
- /**
879
- * Return the <a href="http://en.wikipedia.org/wiki/Celestial_coordinate_system">Solar Elevation</a> for the
880
- * horizontal coordinate system at the given location at the given time. Can be negative if the sun is below the
881
- * horizon. Not corrected for altitude.
882
- *
883
- * @param cal
884
- * time of calculation
885
- * @param lat
886
- * latitude of location for calculation
887
- * @param lon
888
- * longitude of location for calculation
889
- * @return solar elevation in degrees - horizon is 0 degrees, civil twilight is -6 degrees
890
- */
891
- static getSolarElevation(date, lat, lon) {
892
- const julianDay = NOAACalculator.getJulianDay(date.toPlainDate());
893
- const julianCenturies = NOAACalculator.getJulianCenturiesFromJulianDay(julianDay);
894
- const equationOfTime = NOAACalculator.getEquationOfTime(julianCenturies);
895
- let longitude = date.hour + 12 + (date.minute + equationOfTime + date.second / 60) / 60;
896
- longitude = -((longitude * 360) / 24) % 360;
897
- const hourAngleRad = degreesToRadians(lon - longitude);
898
- const declination = NOAACalculator.getSunDeclination(julianCenturies);
899
- const decRad = degreesToRadians(declination);
900
- const latRad = degreesToRadians(lat);
901
- return radiansToDegrees(Math.asin(Math.sin(latRad) * Math.sin(decRad) +
902
- Math.cos(latRad) * Math.cos(decRad) * Math.cos(hourAngleRad)));
903
- }
904
- /**
905
- * Return the <a href="http://en.wikipedia.org/wiki/Celestial_coordinate_system">Solar Azimuth</a> for the
906
- * horizontal coordinate system at the given location at the given time. Not corrected for altitude. True south is 0
907
- * degrees.
908
- *
909
- * @param cal
910
- * time of calculation
911
- * @param latitude
912
- * latitude of location for calculation
913
- * @param lon
914
- * longitude of location for calculation
915
- * @return FIXME
916
- */
917
- static getSolarAzimuth(date, latitude, lon) {
918
- const julianDay = NOAACalculator.getJulianDay(date.toPlainDate());
919
- const julianCenturies = NOAACalculator.getJulianCenturiesFromJulianDay(julianDay);
920
- const equationOfTime = NOAACalculator.getEquationOfTime(julianCenturies);
921
- let longitude = date.hour + 12 + (date.minute + equationOfTime + date.second / 60) / 60;
922
- longitude = -((longitude * 360) / 24) % 360;
923
- const hourAngleRad = degreesToRadians(lon - longitude);
924
- const declination = NOAACalculator.getSunDeclination(julianCenturies);
925
- const decRad = degreesToRadians(declination);
926
- const latRad = degreesToRadians(latitude);
927
- return (radiansToDegrees(Math.atan(Math.sin(hourAngleRad) /
928
- (Math.cos(hourAngleRad) * Math.sin(latRad) -
929
- Math.tan(decRad) * Math.cos(latRad)))) + 180);
930
- }
931
- /**
932
- * Return the <a href="http://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
933
- * of sunrise for the given day at the given location on earth
934
- *
935
- * @param julianDay
936
- * the Julian day
937
- * @param latitude
938
- * the latitude of observer in degrees
939
- * @param longitude
940
- * the longitude of observer in degrees
941
- * @param zenith
942
- * the zenith
943
- * @return the time in minutes from zero UTC
944
- */
945
- static getSunriseUTC(julianDay, latitude, longitude, zenith) {
946
- const julianCenturies = NOAACalculator.getJulianCenturiesFromJulianDay(julianDay);
947
- // Find the time of solar noon at the location, and use that declination. This is better than start of the
948
- // Julian day
949
- const noonmin = NOAACalculator.getSolarNoonUTC(julianCenturies, longitude);
950
- const tnoon = NOAACalculator.getJulianCenturiesFromJulianDay(julianDay + noonmin / 1440);
951
- // First pass to approximate sunrise (using solar noon)
952
- let eqTime = NOAACalculator.getEquationOfTime(tnoon);
953
- let solarDec = NOAACalculator.getSunDeclination(tnoon);
954
- let hourAngle = NOAACalculator.getSunHourAngleAtSunrise(latitude, solarDec, zenith);
955
- let delta = longitude - radiansToDegrees(hourAngle);
956
- let timeDiff = 4 * delta; // in minutes of time
957
- let timeUTC = 720 + timeDiff - eqTime; // in minutes
958
- // Second pass includes fractional Julian Day in gamma calc
959
- const newt = NOAACalculator.getJulianCenturiesFromJulianDay(NOAACalculator.getJulianDayFromJulianCenturies(julianCenturies) +
960
- timeUTC / 1440);
961
- eqTime = NOAACalculator.getEquationOfTime(newt);
962
- solarDec = NOAACalculator.getSunDeclination(newt);
963
- hourAngle = NOAACalculator.getSunHourAngleAtSunrise(latitude, solarDec, zenith);
964
- delta = longitude - radiansToDegrees(hourAngle);
965
- timeDiff = 4 * delta;
966
- timeUTC = 720 + timeDiff - eqTime; // in minutes
967
- return timeUTC;
968
- }
969
- /**
970
- * Return the <a href="http://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
971
- * of <a href="http://en.wikipedia.org/wiki/Noon#Solar_noon">solar noon</a> for the given day at the given location
972
- * on earth.
973
- *
974
- * @param julianCenturies
975
- * the number of Julian centuries since J2000.0
976
- * @param longitude
977
- * the longitude of observer in degrees
978
- * @return the time in minutes from zero UTC
979
- */
980
- static getSolarNoonUTC(julianCenturies, longitude) {
981
- // First pass uses approximate solar noon to calculate eqtime
982
- const tnoon = NOAACalculator.getJulianCenturiesFromJulianDay(NOAACalculator.getJulianDayFromJulianCenturies(julianCenturies) +
983
- longitude / 360);
984
- let eqTime = NOAACalculator.getEquationOfTime(tnoon);
985
- const solNoonUTC = 720 + longitude * 4 - eqTime; // min
986
- const newt = NOAACalculator.getJulianCenturiesFromJulianDay(NOAACalculator.getJulianDayFromJulianCenturies(julianCenturies) -
987
- 0.5 +
988
- solNoonUTC / 1440);
989
- eqTime = NOAACalculator.getEquationOfTime(newt);
990
- return 720 + longitude * 4 - eqTime; // min
991
- }
992
- /**
993
- * Return the <a href="http://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
994
- * of sunset for the given day at the given location on earth
995
- *
996
- * @param julianDay
997
- * the Julian day
998
- * @param latitude
999
- * the latitude of observer in degrees
1000
- * @param longitude
1001
- * : longitude of observer in degrees
1002
- * @param zenith
1003
- * the zenith
1004
- * @return the time in minutes from zero Universal Coordinated Time (UTC)
1005
- */
1006
- static getSunsetUTC(julianDay, latitude, longitude, zenith) {
1007
- const julianCenturies = NOAACalculator.getJulianCenturiesFromJulianDay(julianDay);
1008
- // Find the time of solar noon at the location, and use that declination. This is better than start of the
1009
- // Julian day
1010
- const noonmin = NOAACalculator.getSolarNoonUTC(julianCenturies, longitude);
1011
- const tnoon = NOAACalculator.getJulianCenturiesFromJulianDay(julianDay + noonmin / 1440);
1012
- // First calculates sunrise and approx length of day
1013
- let eqTime = NOAACalculator.getEquationOfTime(tnoon);
1014
- let solarDec = NOAACalculator.getSunDeclination(tnoon);
1015
- let hourAngle = NOAACalculator.getSunHourAngleAtSunset(latitude, solarDec, zenith);
1016
- let delta = longitude - radiansToDegrees(hourAngle);
1017
- let timeDiff = 4 * delta;
1018
- let timeUTC = 720 + timeDiff - eqTime;
1019
- // Second pass includes fractional Julian Day in gamma calc
1020
- const newt = NOAACalculator.getJulianCenturiesFromJulianDay(NOAACalculator.getJulianDayFromJulianCenturies(julianCenturies) +
1021
- timeUTC / 1440);
1022
- eqTime = NOAACalculator.getEquationOfTime(newt);
1023
- solarDec = NOAACalculator.getSunDeclination(newt);
1024
- hourAngle = NOAACalculator.getSunHourAngleAtSunset(latitude, solarDec, zenith);
1025
- delta = longitude - radiansToDegrees(hourAngle);
1026
- timeDiff = 4 * delta;
1027
- timeUTC = 720 + timeDiff - eqTime; // in minutes
1028
- return timeUTC;
1029
- }
1030
- }
1031
- /**
1032
- * The zenith of astronomical sunrise and sunset. The sun is 90&deg; from the vertical 0&deg;
1033
- */
1034
- NOAACalculator.GEOMETRIC_ZENITH = 90;
1035
- /**
1036
- * Default value for Sun's zenith and true rise/set Zenith (used in this class and subclasses) is the angle that the
1037
- * center of the Sun makes to a line perpendicular to the Earth's surface. If the Sun were a point and the Earth
1038
- * were without an atmosphere, true sunset and sunrise would correspond to a 90&deg; zenith. Because the Sun is not
1039
- * a point, and because the atmosphere refracts light, this 90&deg; zenith does not, in fact, correspond to true
1040
- * sunset or sunrise, instead the center of the Sun's disk must lie just below the horizon for the upper edge to be
1041
- * obscured. This means that a zenith of just above 90&deg; must be used. The Sun subtends an angle of 16 minutes of
1042
- * arc (this can be changed via the {@link #setSunRadius(double)} method , and atmospheric refraction accounts for
1043
- * 34 minutes or so (this can be changed via the {@link #setRefraction(double)} method), giving a total of 50
1044
- * arcminutes. The total value for ZENITH is 90+(5/6) or 90.8333333&deg; for true sunrise/sunset.
1045
- */
1046
- // const ZENITH: number = GEOMETRIC_ZENITH + 5.0 / 6.0;
1047
- /** Sun's zenith at civil twilight (96&deg;). */
1048
- NOAACalculator.CIVIL_ZENITH = 96;
1049
- /** Sun's zenith at nautical twilight (102&deg;). */
1050
- NOAACalculator.NAUTICAL_ZENITH = 102;
1051
- /** Sun's zenith at astronomical twilight (108&deg;). */
1052
- NOAACalculator.ASTRONOMICAL_ZENITH = 108;
1053
- /**
1054
- * The <a href="http://en.wikipedia.org/wiki/Julian_day">Julian day</a> of January 1, 2000
1055
- */
1056
- NOAACalculator.JULIAN_DAY_JAN_1_2000 = 2451545;
1057
- /**
1058
- * Julian days per century
1059
- */
1060
- NOAACalculator.JULIAN_DAYS_PER_CENTURY = 36525;