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