@hebcal/noaa 0.8.9 → 0.8.10
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/README.md +108 -95
- package/dist/index.cjs +147 -117
- package/dist/index.d.ts +115 -126
- package/dist/index.js +147 -127
- package/package.json +4 -7
package/dist/index.cjs
CHANGED
|
@@ -18,31 +18,37 @@ function degreesToRadians(degrees) {
|
|
|
18
18
|
function radiansToDegrees(radians) {
|
|
19
19
|
return (radians * 180) / Math.PI;
|
|
20
20
|
}
|
|
21
|
-
const Long_MIN_VALUE = NaN;
|
|
22
21
|
/**
|
|
23
22
|
* A class that contains location information such as latitude and longitude required for astronomical calculations. The
|
|
24
|
-
* elevation field may not be used by some calculation engines and would be ignored if set.
|
|
25
|
-
* specific implementations of the {@link AstronomicalCalculator} to see if elevation is calculated as part of the
|
|
26
|
-
* algorithm.
|
|
23
|
+
* elevation field may not be used by some calculation engines and would be ignored if set.
|
|
27
24
|
*
|
|
28
25
|
* @author © Eliyahu Hershfeld 2004 - 2016
|
|
29
26
|
* @version 1.1
|
|
30
27
|
*/
|
|
31
28
|
class GeoLocation {
|
|
32
|
-
|
|
29
|
+
/**
|
|
30
|
+
* GeoLocation constructor with parameters for all required fields.
|
|
31
|
+
*
|
|
32
|
+
* @param {string} name
|
|
33
|
+
* The location name for display use such as "Lakewood, NJ"
|
|
34
|
+
* @param {number} latitude
|
|
35
|
+
* the latitude in a double format such as 40.095965 for Lakewood, NJ.
|
|
36
|
+
* <b>Note: </b> For latitudes south of the equator, a negative value should be used.
|
|
37
|
+
* @param {number} longitude
|
|
38
|
+
* double the longitude in a double format such as -74.222130 for Lakewood, NJ.
|
|
39
|
+
* <b>Note: </b> For longitudes west of the <a href="http://en.wikipedia.org/wiki/Prime_Meridian">Prime
|
|
40
|
+
* Meridian </a> (Greenwich), a negative value should be used.
|
|
41
|
+
* @param {number} elevation
|
|
42
|
+
* the elevation above sea level in Meters. Elevation is not used in most algorithms used for calculating
|
|
43
|
+
* sunrise and set.
|
|
44
|
+
* @param {string} timeZoneId
|
|
45
|
+
* the <code>TimeZone</code> for the location.
|
|
46
|
+
*/
|
|
47
|
+
constructor(name, latitude, longitude, elevation, timeZoneId) {
|
|
33
48
|
/**
|
|
34
49
|
* @private
|
|
35
|
-
* @see #getLocationName()
|
|
36
|
-
* @see #setLocationName(String)
|
|
37
50
|
*/
|
|
38
51
|
this.locationName = null;
|
|
39
|
-
let elevation = 0;
|
|
40
|
-
if (timeZoneId) {
|
|
41
|
-
elevation = elevationOrTimeZoneId;
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
timeZoneId = elevationOrTimeZoneId;
|
|
45
|
-
}
|
|
46
52
|
this.setLocationName(name);
|
|
47
53
|
this.setLatitude(latitude);
|
|
48
54
|
this.setLongitude(longitude);
|
|
@@ -61,9 +67,14 @@ class GeoLocation {
|
|
|
61
67
|
* Method to set the elevation in Meters <b>above </b> sea level.
|
|
62
68
|
*
|
|
63
69
|
* @param {number} elevation
|
|
64
|
-
* The elevation to set in Meters. An
|
|
70
|
+
* The elevation to set in Meters. An Error will be thrown if the value is a negative.
|
|
65
71
|
*/
|
|
66
72
|
setElevation(elevation) {
|
|
73
|
+
if (typeof elevation !== 'number')
|
|
74
|
+
throw new TypeError('Invalid elevation');
|
|
75
|
+
if (elevation < 0) {
|
|
76
|
+
throw new RangeError(`elevation ${elevation} must be zero or positive`);
|
|
77
|
+
}
|
|
67
78
|
this.elevation = elevation;
|
|
68
79
|
}
|
|
69
80
|
setLatitude(latitude) {
|
|
@@ -114,13 +125,7 @@ class GeoLocation {
|
|
|
114
125
|
return this.timeZoneId;
|
|
115
126
|
}
|
|
116
127
|
/**
|
|
117
|
-
* Method to set the TimeZone.
|
|
118
|
-
* {@link AstronomicalCalendar}, it is critical that
|
|
119
|
-
* {@link AstronomicalCalendar#getCalendar()}.
|
|
120
|
-
* {@link java.util.Calendar#setTimeZone(TimeZone) setTimeZone(TimeZone)} be called in order for the
|
|
121
|
-
* AstronomicalCalendar to output times in the expected offset. This situation will arise if the
|
|
122
|
-
* AstronomicalCalendar is ever {@link AstronomicalCalendar#clone() cloned}.
|
|
123
|
-
*
|
|
128
|
+
* Method to set the TimeZone.
|
|
124
129
|
* @param {string} timeZoneId
|
|
125
130
|
* The timeZone to set.
|
|
126
131
|
*/
|
|
@@ -163,14 +168,11 @@ const earthRadius = 6356.9; // in KM
|
|
|
163
168
|
class NOAACalculator {
|
|
164
169
|
/**
|
|
165
170
|
* A constructor that takes in <a href="http://en.wikipedia.org/wiki/Geolocation">geolocation</a> information as a
|
|
166
|
-
* parameter.
|
|
167
|
-
* calculations is the the {@link NOAACalculator}.
|
|
171
|
+
* parameter.
|
|
168
172
|
*
|
|
169
173
|
* @param {GeoLocation} geoLocation
|
|
170
174
|
* The location information used for calculating astronomical sun times.
|
|
171
175
|
* @param {Temporal.PlainDate} date
|
|
172
|
-
*
|
|
173
|
-
* @see #setAstronomicalCalculator(AstronomicalCalculator) for changing the calculator class.
|
|
174
176
|
*/
|
|
175
177
|
constructor(geoLocation, date) {
|
|
176
178
|
this.date = date;
|
|
@@ -178,28 +180,27 @@ class NOAACalculator {
|
|
|
178
180
|
}
|
|
179
181
|
/**
|
|
180
182
|
* The getSunrise method Returns a `Date` representing the
|
|
181
|
-
* {@link
|
|
182
|
-
* for the calculation uses {@link
|
|
183
|
-
* {@link
|
|
184
|
-
*
|
|
185
|
-
* and 16 archminutes for the sun's radius for a total of {@link
|
|
186
|
-
* See documentation for the specific implementation of the {@link AstronomicalCalculator} that you are using.
|
|
183
|
+
* {@link getElevationAdjustment elevation adjusted} sunrise time. The zenith used
|
|
184
|
+
* for the calculation uses {@link GEOMETRIC_ZENITH geometric zenith} of 90° plus
|
|
185
|
+
* {@link getElevationAdjustment}. This is adjusted
|
|
186
|
+
* to add approximately 50/60 of a degree to account for 34 archminutes of refraction
|
|
187
|
+
* and 16 archminutes for the sun's radius for a total of {@link adjustZenith 90.83333°}.
|
|
187
188
|
*
|
|
188
189
|
* @return {Temporal.ZonedDateTime | null} the `Date` representing the exact sunrise time. If the calculation can't be computed such as
|
|
189
190
|
* in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
|
|
190
191
|
* does not set, a null will be returned. See detailed explanation on top of the page.
|
|
191
|
-
* @see
|
|
192
|
-
* @see
|
|
193
|
-
* @see
|
|
192
|
+
* @see adjustZenith
|
|
193
|
+
* @see getSeaLevelSunrise()
|
|
194
|
+
* @see getUTCSunrise
|
|
194
195
|
*/
|
|
195
196
|
getSunrise() {
|
|
196
197
|
const sunrise = this.getUTCSunrise0(NOAACalculator.GEOMETRIC_ZENITH);
|
|
197
|
-
if (
|
|
198
|
+
if (isNaN(sunrise))
|
|
198
199
|
return null;
|
|
199
200
|
return this.getDateFromTime(sunrise, true);
|
|
200
201
|
}
|
|
201
202
|
/**
|
|
202
|
-
* A method that returns the sunrise without {@link
|
|
203
|
+
* A method that returns the sunrise without {@link getElevationAdjustment elevation
|
|
203
204
|
* adjustment}. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light,
|
|
204
205
|
* something that is not affected by elevation. This method returns sunrise calculated at sea level. This forms the
|
|
205
206
|
* base for dawn calculations that are calculated as a dip below the horizon before sunrise.
|
|
@@ -207,55 +208,55 @@ class NOAACalculator {
|
|
|
207
208
|
* @return {Temporal.ZonedDateTime | null} the `Date` representing the exact sea-level sunrise time. If the calculation can't be computed
|
|
208
209
|
* such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
|
|
209
210
|
* where it does not set, a null will be returned. See detailed explanation on top of the page.
|
|
210
|
-
* @see
|
|
211
|
-
* @see
|
|
212
|
-
* @see
|
|
211
|
+
* @see getSunrise
|
|
212
|
+
* @see getUTCSeaLevelSunrise
|
|
213
|
+
* @see getSeaLevelSunset()
|
|
213
214
|
*/
|
|
214
215
|
getSeaLevelSunrise() {
|
|
215
216
|
const sunrise = this.getUTCSeaLevelSunrise(NOAACalculator.GEOMETRIC_ZENITH);
|
|
216
|
-
if (
|
|
217
|
+
if (isNaN(sunrise))
|
|
217
218
|
return null;
|
|
218
219
|
return this.getDateFromTime(sunrise, true);
|
|
219
220
|
}
|
|
220
221
|
/**
|
|
221
|
-
* A method that returns the beginning of civil twilight (dawn) using a zenith of {@link
|
|
222
|
+
* A method that returns the beginning of civil twilight (dawn) using a zenith of {@link CIVIL_ZENITH 96°}.
|
|
222
223
|
*
|
|
223
224
|
* @return {Temporal.ZonedDateTime | null} The `Date` of the beginning of civil twilight using a zenith of 96°. If the calculation
|
|
224
225
|
* can't be computed, null will be returned. See detailed explanation on top of the page.
|
|
225
|
-
* @see
|
|
226
|
+
* @see CIVIL_ZENITH
|
|
226
227
|
*/
|
|
227
228
|
getBeginCivilTwilight() {
|
|
228
229
|
return this.getSunriseOffsetByDegrees(NOAACalculator.CIVIL_ZENITH);
|
|
229
230
|
}
|
|
230
231
|
/**
|
|
231
|
-
* A method that returns the beginning of nautical twilight using a zenith of {@link
|
|
232
|
+
* A method that returns the beginning of nautical twilight using a zenith of {@link NAUTICAL_ZENITH 102°}.
|
|
232
233
|
*
|
|
233
234
|
* @return {Temporal.ZonedDateTime | null} The `Date` of the beginning of nautical twilight using a zenith of 102°. If the
|
|
234
235
|
* calculation can't be computed null will be returned. See detailed explanation on top of the page.
|
|
235
|
-
* @see
|
|
236
|
+
* @see NAUTICAL_ZENITH
|
|
236
237
|
*/
|
|
237
238
|
getBeginNauticalTwilight() {
|
|
238
239
|
return this.getSunriseOffsetByDegrees(NOAACalculator.NAUTICAL_ZENITH);
|
|
239
240
|
}
|
|
240
241
|
/**
|
|
241
|
-
* A method that returns the beginning of astronomical twilight using a zenith of {@link
|
|
242
|
+
* A method that returns the beginning of astronomical twilight using a zenith of {@link ASTRONOMICAL_ZENITH
|
|
242
243
|
* 108°}.
|
|
243
244
|
*
|
|
244
245
|
* @return {Temporal.ZonedDateTime | null} The `Date` of the beginning of astronomical twilight using a zenith of 108°. If the
|
|
245
246
|
* calculation can't be computed, null will be returned. See detailed explanation on top of the page.
|
|
246
|
-
* @see
|
|
247
|
+
* @see ASTRONOMICAL_ZENITH
|
|
247
248
|
*/
|
|
248
249
|
getBeginAstronomicalTwilight() {
|
|
249
250
|
return this.getSunriseOffsetByDegrees(NOAACalculator.ASTRONOMICAL_ZENITH);
|
|
250
251
|
}
|
|
251
252
|
/**
|
|
252
253
|
* The getSunset method Returns a `Date` representing the
|
|
253
|
-
* {@link
|
|
254
|
-
* the calculation uses {@link
|
|
255
|
-
* {@link
|
|
256
|
-
*
|
|
257
|
-
* and 16 archminutes for the sun's radius for a total of {@link
|
|
258
|
-
*
|
|
254
|
+
* {@link getElevationAdjustment elevation adjusted} sunset time. The zenith used for
|
|
255
|
+
* the calculation uses {@link GEOMETRIC_ZENITH geometric zenith} of 90° plus
|
|
256
|
+
* {@link getElevationAdjustment}. This is adjusted
|
|
257
|
+
* to add approximately 50/60 of a degree to account for 34 archminutes of refraction
|
|
258
|
+
* and 16 archminutes for the sun's radius for a total of {@link adjustZenith 90.83333°}.
|
|
259
|
+
* Note:
|
|
259
260
|
* In certain cases the calculates sunset will occur before sunrise. This will typically happen when a timezone
|
|
260
261
|
* other than the local timezone is used (calculating Los Angeles sunset using a GMT timezone for example). In this
|
|
261
262
|
* case the sunset date will be incremented to the following date.
|
|
@@ -263,18 +264,18 @@ class NOAACalculator {
|
|
|
263
264
|
* @return {Temporal.ZonedDateTime | null} The `Date` representing the exact sunset time. If the calculation can't be computed such as in
|
|
264
265
|
* the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
|
|
265
266
|
* does not set, a null will be returned. See detailed explanation on top of the page.
|
|
266
|
-
* @see
|
|
267
|
-
* @see
|
|
268
|
-
* @see
|
|
267
|
+
* @see adjustZenith
|
|
268
|
+
* @see getSeaLevelSunset()
|
|
269
|
+
* @see getUTCSunset
|
|
269
270
|
*/
|
|
270
271
|
getSunset() {
|
|
271
272
|
const sunset = this.getUTCSunset0(NOAACalculator.GEOMETRIC_ZENITH);
|
|
272
|
-
if (
|
|
273
|
+
if (isNaN(sunset))
|
|
273
274
|
return null;
|
|
274
275
|
return this.getDateFromTime(sunset, false);
|
|
275
276
|
}
|
|
276
277
|
/**
|
|
277
|
-
* A method that returns the sunset without {@link
|
|
278
|
+
* A method that returns the sunset without {@link getElevationAdjustment elevation
|
|
278
279
|
* adjustment}. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light,
|
|
279
280
|
* something that is not affected by elevation. This method returns sunset calculated at sea level. This forms the
|
|
280
281
|
* base for dusk calculations that are calculated as a dip below the horizon after sunset.
|
|
@@ -282,43 +283,43 @@ class NOAACalculator {
|
|
|
282
283
|
* @return {Temporal.ZonedDateTime | null} The `Date` representing the exact sea-level sunset time. If the calculation can't be computed
|
|
283
284
|
* such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
|
|
284
285
|
* where it does not set, a null will be returned. See detailed explanation on top of the page.
|
|
285
|
-
* @see
|
|
286
|
-
* @see
|
|
286
|
+
* @see getSunset
|
|
287
|
+
* @see getUTCSeaLevelSunset
|
|
287
288
|
*/
|
|
288
289
|
getSeaLevelSunset() {
|
|
289
290
|
const sunset = this.getUTCSeaLevelSunset(NOAACalculator.GEOMETRIC_ZENITH);
|
|
290
|
-
if (
|
|
291
|
+
if (isNaN(sunset))
|
|
291
292
|
return null;
|
|
292
293
|
return this.getDateFromTime(sunset, false);
|
|
293
294
|
}
|
|
294
295
|
/**
|
|
295
|
-
* A method that returns the end of civil twilight using a zenith of {@link
|
|
296
|
+
* A method that returns the end of civil twilight using a zenith of {@link CIVIL_ZENITH 96°}.
|
|
296
297
|
*
|
|
297
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of civil twilight using a zenith of {@link
|
|
298
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of civil twilight using a zenith of {@link CIVIL_ZENITH 96°}. If
|
|
298
299
|
* the calculation can't be computed, null will be returned. See detailed explanation on top of the page.
|
|
299
|
-
* @see
|
|
300
|
+
* @see CIVIL_ZENITH
|
|
300
301
|
*/
|
|
301
302
|
getEndCivilTwilight() {
|
|
302
303
|
return this.getSunsetOffsetByDegrees(NOAACalculator.CIVIL_ZENITH);
|
|
303
304
|
}
|
|
304
305
|
/**
|
|
305
|
-
* A method that returns the end of nautical twilight using a zenith of {@link
|
|
306
|
+
* A method that returns the end of nautical twilight using a zenith of {@link NAUTICAL_ZENITH 102°}.
|
|
306
307
|
*
|
|
307
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of nautical twilight using a zenith of {@link
|
|
308
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of nautical twilight using a zenith of {@link NAUTICAL_ZENITH 102°}
|
|
308
309
|
* . If the calculation can't be computed, null will be returned. See detailed explanation on top of the
|
|
309
310
|
* page.
|
|
310
|
-
* @see
|
|
311
|
+
* @see NAUTICAL_ZENITH
|
|
311
312
|
*/
|
|
312
313
|
getEndNauticalTwilight() {
|
|
313
314
|
return this.getSunsetOffsetByDegrees(NOAACalculator.NAUTICAL_ZENITH);
|
|
314
315
|
}
|
|
315
316
|
/**
|
|
316
|
-
* A method that returns the end of astronomical twilight using a zenith of {@link
|
|
317
|
+
* A method that returns the end of astronomical twilight using a zenith of {@link ASTRONOMICAL_ZENITH 108°}.
|
|
317
318
|
*
|
|
318
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of astronomical twilight using a zenith of {@link
|
|
319
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of astronomical twilight using a zenith of {@link ASTRONOMICAL_ZENITH
|
|
319
320
|
* 108°}. If the calculation can't be computed, null will be returned. See detailed explanation on top
|
|
320
321
|
* of the page.
|
|
321
|
-
* @see
|
|
322
|
+
* @see ASTRONOMICAL_ZENITH
|
|
322
323
|
*/
|
|
323
324
|
getEndAstronomicalTwilight() {
|
|
324
325
|
return this.getSunsetOffsetByDegrees(NOAACalculator.ASTRONOMICAL_ZENITH);
|
|
@@ -336,49 +337,49 @@ class NOAACalculator {
|
|
|
336
337
|
* @return {Temporal.ZonedDateTime | null} the `Date` with the offset in milliseconds added to it
|
|
337
338
|
*/
|
|
338
339
|
static getTimeOffset(time, offset) {
|
|
339
|
-
if (time === null ||
|
|
340
|
+
if (time === null || isNaN(offset)) {
|
|
340
341
|
return null;
|
|
341
342
|
}
|
|
342
343
|
return time.add({ milliseconds: offset });
|
|
343
344
|
}
|
|
344
345
|
/**
|
|
345
346
|
* A utility method that returns the time of an offset by degrees below or above the horizon of
|
|
346
|
-
* {@link
|
|
347
|
-
* before sunrise, an offset of 14 + {@link
|
|
347
|
+
* {@link getSunrise() sunrise}. Note that the degree offset is from the vertical, so for a calculation of 14°
|
|
348
|
+
* before sunrise, an offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
|
|
348
349
|
*
|
|
349
350
|
* @param {number} offsetZenith
|
|
350
|
-
* the degrees before {@link
|
|
351
|
+
* the degrees before {@link getSunrise} to use in the calculation. For time after sunrise use
|
|
351
352
|
* negative numbers. Note that the degree offset is from the vertical, so for a calculation of 14°
|
|
352
|
-
* before sunrise, an offset of 14 + {@link
|
|
353
|
+
* before sunrise, an offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a
|
|
353
354
|
* parameter.
|
|
354
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the offset after (or before) {@link
|
|
355
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the offset after (or before) {@link getSunrise}. If the calculation
|
|
355
356
|
* can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does
|
|
356
357
|
* not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the
|
|
357
358
|
* page.
|
|
358
359
|
*/
|
|
359
360
|
getSunriseOffsetByDegrees(offsetZenith) {
|
|
360
361
|
const dawn = this.getUTCSunrise0(offsetZenith);
|
|
361
|
-
if (
|
|
362
|
+
if (isNaN(dawn))
|
|
362
363
|
return null;
|
|
363
364
|
return this.getDateFromTime(dawn, true);
|
|
364
365
|
}
|
|
365
366
|
/**
|
|
366
|
-
* A utility method that returns the time of an offset by degrees below or above the horizon of {@link
|
|
367
|
+
* A utility method that returns the time of an offset by degrees below or above the horizon of {@link getSunset()
|
|
367
368
|
* sunset}. Note that the degree offset is from the vertical, so for a calculation of 14° after sunset, an
|
|
368
|
-
* offset of 14 + {@link
|
|
369
|
+
* offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
|
|
369
370
|
*
|
|
370
371
|
* @param {number} offsetZenith
|
|
371
|
-
* the degrees after {@link
|
|
372
|
+
* the degrees after {@link getSunset} to use in the calculation. For time before sunset use negative
|
|
372
373
|
* numbers. Note that the degree offset is from the vertical, so for a calculation of 14° after
|
|
373
|
-
* sunset, an offset of 14 + {@link
|
|
374
|
-
* @return {Temporal.ZonedDateTime | null} The `Date`of the offset after (or before) {@link
|
|
374
|
+
* sunset, an offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
|
|
375
|
+
* @return {Temporal.ZonedDateTime | null} The `Date`of the offset after (or before) {@link getSunset}. If the calculation can't
|
|
375
376
|
* be computed such as in the Arctic Circle where there is at least one day a year where the sun does not
|
|
376
377
|
* rise, and one where it does not set, a null will be returned. See detailed explanation on top of the
|
|
377
378
|
* page.
|
|
378
379
|
*/
|
|
379
380
|
getSunsetOffsetByDegrees(offsetZenith) {
|
|
380
381
|
const sunset = this.getUTCSunset0(offsetZenith);
|
|
381
|
-
if (
|
|
382
|
+
if (isNaN(sunset))
|
|
382
383
|
return null;
|
|
383
384
|
return this.getDateFromTime(sunset, false);
|
|
384
385
|
}
|
|
@@ -390,7 +391,7 @@ class NOAACalculator {
|
|
|
390
391
|
* the degrees below the horizon. For time after sunrise use negative numbers.
|
|
391
392
|
* @return {number} The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
|
|
392
393
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
393
|
-
* not set,
|
|
394
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
394
395
|
*/
|
|
395
396
|
getUTCSunrise0(zenith) {
|
|
396
397
|
return this.getUTCSunrise(this.getAdjustedDate(), this.geoLocation, zenith, true);
|
|
@@ -405,9 +406,9 @@ class NOAACalculator {
|
|
|
405
406
|
* the degrees below the horizon. For time after sunrise use negative numbers.
|
|
406
407
|
* @return {number} The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
|
|
407
408
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
408
|
-
* not set,
|
|
409
|
-
* @see
|
|
410
|
-
* @see
|
|
409
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
410
|
+
* @see getUTCSunrise
|
|
411
|
+
* @see getUTCSeaLevelSunset
|
|
411
412
|
*/
|
|
412
413
|
getUTCSeaLevelSunrise(zenith) {
|
|
413
414
|
return this.getUTCSunrise(this.getAdjustedDate(), this.geoLocation, zenith, false);
|
|
@@ -420,8 +421,8 @@ class NOAACalculator {
|
|
|
420
421
|
* the degrees below the horizon. For time after sunset use negative numbers.
|
|
421
422
|
* @return {number} The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
|
|
422
423
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
423
|
-
* not set,
|
|
424
|
-
* @see
|
|
424
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
425
|
+
* @see getUTCSeaLevelSunset
|
|
425
426
|
*/
|
|
426
427
|
getUTCSunset0(zenith) {
|
|
427
428
|
return this.getUTCSunset(this.getAdjustedDate(), this.geoLocation, zenith, true);
|
|
@@ -437,9 +438,9 @@ class NOAACalculator {
|
|
|
437
438
|
* the degrees below the horizon. For time before sunset use negative numbers.
|
|
438
439
|
* @return {number} The time in the format: 18.75 for 18:45:00 UTC/GMT. If the calculation can't be computed such as in the
|
|
439
440
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
440
|
-
* not set,
|
|
441
|
-
* @see
|
|
442
|
-
* @see
|
|
441
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
442
|
+
* @see getUTCSunset
|
|
443
|
+
* @see getUTCSeaLevelSunrise
|
|
443
444
|
*/
|
|
444
445
|
getUTCSeaLevelSunset(zenith) {
|
|
445
446
|
return this.getUTCSunset(this.getAdjustedDate(), this.geoLocation, zenith, false);
|
|
@@ -457,9 +458,9 @@ class NOAACalculator {
|
|
|
457
458
|
* Method to return the adjustment to the zenith required to account for the elevation. Since a person at a higher
|
|
458
459
|
* elevation can see farther below the horizon, the calculation for sunrise / sunset is calculated below the horizon
|
|
459
460
|
* used at sea level. This is only used for sunrise and sunset and not times before or after it such as
|
|
460
|
-
* {@link
|
|
461
|
+
* {@link getBeginNauticalTwilight() nautical twilight} since those
|
|
461
462
|
* calculations are based on the level of available light at the given dip below the horizon, something that is not
|
|
462
|
-
* affected by elevation, the adjustment should only made if the zenith == 90° {@link
|
|
463
|
+
* affected by elevation, the adjustment should only made if the zenith == 90° {@link adjustZenith adjusted}
|
|
463
464
|
* for refraction and solar radius. The algorithm used is
|
|
464
465
|
*
|
|
465
466
|
* <pre>
|
|
@@ -491,30 +492,30 @@ class NOAACalculator {
|
|
|
491
492
|
* is not a point, and because the atmosphere refracts light, this 90° zenith does not, in fact, correspond to
|
|
492
493
|
* true sunset or sunrise, instead the centre of the Sun's disk must lie just below the horizon for the upper edge
|
|
493
494
|
* to be obscured. This means that a zenith of just above 90° must be used. The Sun subtends an angle of 16
|
|
494
|
-
* minutes of arc
|
|
495
|
-
* accounts for 34 minutes or so
|
|
495
|
+
* minutes of arc, and atmospheric refraction
|
|
496
|
+
* accounts for 34 minutes or so, giving a total
|
|
496
497
|
* of 50 arcminutes. The total value for ZENITH is 90+(5/6) or 90.8333333° for true sunrise/sunset. Since a
|
|
497
498
|
* person at an elevation can see blow the horizon of a person at sea level, this will also adjust the zenith to
|
|
498
499
|
* account for elevation if available. Note that this will only adjust the value if the zenith is exactly 90 degrees.
|
|
499
500
|
* For values below and above this no correction is done. As an example, astronomical twilight is when the sun is
|
|
500
|
-
* 18° below the horizon or {@link
|
|
501
|
+
* 18° below the horizon or {@link ASTRONOMICAL_ZENITH 108°
|
|
501
502
|
* below the zenith}. This is traditionally calculated with none of the above mentioned adjustments. The same goes
|
|
502
503
|
* for various <em>tzais</em> and <em>alos</em> times such as the
|
|
503
504
|
* {@link ZmanimCalendar#ZENITH_16_POINT_1 16.1°} dip used in
|
|
504
|
-
* {@link ComplexZmanimCalendar#getAlos16Point1Degrees
|
|
505
|
+
* {@link ComplexZmanimCalendar#getAlos16Point1Degrees}.
|
|
505
506
|
*
|
|
506
507
|
* @param {number} zenith
|
|
507
|
-
* the azimuth below the vertical zenith of 90°. For sunset typically the {@link
|
|
508
|
-
* zenith} used for the calculation uses geometric zenith of 90° and {@link
|
|
508
|
+
* the azimuth below the vertical zenith of 90°. For sunset typically the {@link adjustZenith
|
|
509
|
+
* zenith} used for the calculation uses geometric zenith of 90° and {@link adjustZenith adjusts}
|
|
509
510
|
* this slightly to account for solar refraction and the sun's radius. Another example would be
|
|
510
|
-
* {@link
|
|
511
|
-
* {@link
|
|
511
|
+
* {@link getEndNauticalTwilight} that passes
|
|
512
|
+
* {@link NAUTICAL_ZENITH} to this method.
|
|
512
513
|
* @param {number} elevation
|
|
513
514
|
* elevation in Meters.
|
|
514
|
-
* @return {number} The zenith adjusted to include the
|
|
515
|
-
*
|
|
515
|
+
* @return {number} The zenith adjusted to include the sun's radius, refracton
|
|
516
|
+
* and {@link getElevationAdjustment elevation} adjustment. This will only be adjusted for
|
|
516
517
|
* sunrise and sunset (if the zenith == 90°)
|
|
517
|
-
* @see
|
|
518
|
+
* @see getElevationAdjustment
|
|
518
519
|
*/
|
|
519
520
|
adjustZenith(zenith, elevation) {
|
|
520
521
|
let adjustedZenith = zenith;
|
|
@@ -527,7 +528,22 @@ class NOAACalculator {
|
|
|
527
528
|
return adjustedZenith;
|
|
528
529
|
}
|
|
529
530
|
/**
|
|
530
|
-
*
|
|
531
|
+
* A method that calculates UTC sunrise as well as any time based on an angle above or below sunrise.
|
|
532
|
+
* @param date
|
|
533
|
+
* Used to calculate day of year.
|
|
534
|
+
* @param geoLocation
|
|
535
|
+
* The location information used for astronomical calculating sun times.
|
|
536
|
+
* @param zenith
|
|
537
|
+
* the azimuth below the vertical zenith of 90 degrees. for sunrise typically the {@link adjustZenith
|
|
538
|
+
* zenith} used for the calculation uses geometric zenith of 90° and {@link adjustZenith adjusts}
|
|
539
|
+
* this slightly to account for solar refraction and the sun's radius. Another example would be
|
|
540
|
+
* {@link getBeginNauticalTwilight} that passes
|
|
541
|
+
* {@link NAUTICAL_ZENITH} to this method.
|
|
542
|
+
* @param adjustForElevation
|
|
543
|
+
* Should the time be adjusted for elevation
|
|
544
|
+
* @return The UTC time of sunrise in 24 hour format. 5:45:00 AM will return 5.75.0. If an error was encountered in
|
|
545
|
+
* the calculation (expected behavior for some locations such as near the poles,
|
|
546
|
+
* `NaN` will be returned.
|
|
531
547
|
*/
|
|
532
548
|
getUTCSunrise(date, geoLocation, zenith, adjustForElevation) {
|
|
533
549
|
const elevation = adjustForElevation
|
|
@@ -546,7 +562,22 @@ class NOAACalculator {
|
|
|
546
562
|
return sunrise;
|
|
547
563
|
}
|
|
548
564
|
/**
|
|
549
|
-
*
|
|
565
|
+
* A method that calculates UTC sunset as well as any time based on an angle above or below sunset.
|
|
566
|
+
* @param date
|
|
567
|
+
* Used to calculate day of year.
|
|
568
|
+
* @param geoLocation
|
|
569
|
+
* The location information used for astronomical calculating sun times.
|
|
570
|
+
* @param zenith
|
|
571
|
+
* the azimuth below the vertical zenith of 90°. For sunset typically the {@link adjustZenith
|
|
572
|
+
* zenith} used for the calculation uses geometric zenith of 90° and {@link adjustZenith adjusts}
|
|
573
|
+
* this slightly to account for solar refraction and the sun's radius. Another example would be
|
|
574
|
+
* {@link getEndNauticalTwilight} that passes
|
|
575
|
+
* {@link NAUTICAL_ZENITH} to this method.
|
|
576
|
+
* @param adjustForElevation
|
|
577
|
+
* Should the time be adjusted for elevation
|
|
578
|
+
* @return The UTC time of sunset in 24 hour format. 5:45:00 AM will return 5.75.0. If an error was encountered in
|
|
579
|
+
* the calculation (expected behavior for some locations such as near the poles,
|
|
580
|
+
* `NaN` will be returned.
|
|
550
581
|
*/
|
|
551
582
|
getUTCSunset(date, geoLocation, zenith, adjustForElevation) {
|
|
552
583
|
const elevation = adjustForElevation
|
|
@@ -567,8 +598,8 @@ class NOAACalculator {
|
|
|
567
598
|
/**
|
|
568
599
|
* A utility method that will allow the calculation of a temporal (solar) hour based on the sunrise and sunset
|
|
569
600
|
* passed as parameters to this method. An example of the use of this method would be the calculation of a
|
|
570
|
-
* non-elevation adjusted temporal hour by passing in {@link
|
|
571
|
-
* {@link
|
|
601
|
+
* non-elevation adjusted temporal hour by passing in {@link getSeaLevelSunrise() sea level sunrise} and
|
|
602
|
+
* {@link getSeaLevelSunset() sea level sunset} as parameters.
|
|
572
603
|
*
|
|
573
604
|
* @param {Temporal.ZonedDateTime | null} startOfDay
|
|
574
605
|
* The start of the day.
|
|
@@ -576,13 +607,13 @@ class NOAACalculator {
|
|
|
576
607
|
* The end of the day.
|
|
577
608
|
*
|
|
578
609
|
* @return {number} the <code>long</code> millisecond length of the temporal hour. If the calculation can't be computed a
|
|
579
|
-
*
|
|
610
|
+
* `NaN` will be returned. See detailed explanation on top of the page.
|
|
580
611
|
*
|
|
581
|
-
* @see
|
|
612
|
+
* @see getTemporalHour()
|
|
582
613
|
*/
|
|
583
614
|
getTemporalHour(startOfDay = this.getSeaLevelSunrise(), endOfDay = this.getSeaLevelSunset()) {
|
|
584
615
|
if (startOfDay === null || endOfDay === null) {
|
|
585
|
-
return
|
|
616
|
+
return NaN;
|
|
586
617
|
}
|
|
587
618
|
const delta = endOfDay.epochMilliseconds - startOfDay.epochMilliseconds;
|
|
588
619
|
return Math.floor(delta / 12);
|
|
@@ -619,7 +650,7 @@ class NOAACalculator {
|
|
|
619
650
|
* @return {Temporal.ZonedDateTime | null} The Date.
|
|
620
651
|
*/
|
|
621
652
|
getDateFromTime(time, isSunrise) {
|
|
622
|
-
if (
|
|
653
|
+
if (isNaN(time)) {
|
|
623
654
|
return null;
|
|
624
655
|
}
|
|
625
656
|
let calculatedTime = time;
|
|
@@ -864,8 +895,7 @@ class NOAACalculator {
|
|
|
864
895
|
}
|
|
865
896
|
/**
|
|
866
897
|
* Returns the <a href="http://en.wikipedia.org/wiki/Hour_angle">hour angle</a> of the sun at sunset for the
|
|
867
|
-
* latitude.
|
|
868
|
-
* duplication of code.
|
|
898
|
+
* latitude.
|
|
869
899
|
* @private
|
|
870
900
|
* @param {number} lat
|
|
871
901
|
* the latitude of observer in degrees
|
|
@@ -1049,8 +1079,8 @@ NOAACalculator.GEOMETRIC_ZENITH = 90;
|
|
|
1049
1079
|
* a point, and because the atmosphere refracts light, this 90° zenith does not, in fact, correspond to true
|
|
1050
1080
|
* sunset or sunrise, instead the center of the Sun's disk must lie just below the horizon for the upper edge to be
|
|
1051
1081
|
* obscured. This means that a zenith of just above 90° must be used. The Sun subtends an angle of 16 minutes of
|
|
1052
|
-
* arc
|
|
1053
|
-
* 34 minutes or so
|
|
1082
|
+
* arc, and atmospheric refraction accounts for
|
|
1083
|
+
* 34 minutes or so, giving a total of 50
|
|
1054
1084
|
* arcminutes. The total value for ZENITH is 90+(5/6) or 90.8333333° for true sunrise/sunset.
|
|
1055
1085
|
*/
|
|
1056
1086
|
// const ZENITH: number = GEOMETRIC_ZENITH + 5.0 / 6.0;
|