@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.js
CHANGED
|
@@ -15,25 +15,33 @@ function degreesToRadians(degrees) {
|
|
|
15
15
|
function radiansToDegrees(radians) {
|
|
16
16
|
return (radians * 180) / Math.PI;
|
|
17
17
|
}
|
|
18
|
-
const Long_MIN_VALUE = NaN;
|
|
19
18
|
/**
|
|
20
19
|
* A class that contains location information such as latitude and longitude required for astronomical calculations. The
|
|
21
|
-
* elevation field may not be used by some calculation engines and would be ignored if set.
|
|
22
|
-
* specific implementations of the {@link AstronomicalCalculator} to see if elevation is calculated as part of the
|
|
23
|
-
* algorithm.
|
|
20
|
+
* elevation field may not be used by some calculation engines and would be ignored if set.
|
|
24
21
|
*
|
|
25
22
|
* @author © Eliyahu Hershfeld 2004 - 2016
|
|
26
23
|
* @version 1.1
|
|
27
24
|
*/
|
|
28
25
|
export class GeoLocation {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
/**
|
|
27
|
+
* GeoLocation constructor with parameters for all required fields.
|
|
28
|
+
*
|
|
29
|
+
* @param {string} name
|
|
30
|
+
* The location name for display use such as "Lakewood, NJ"
|
|
31
|
+
* @param {number} latitude
|
|
32
|
+
* the latitude in a double format such as 40.095965 for Lakewood, NJ.
|
|
33
|
+
* <b>Note: </b> For latitudes south of the equator, a negative value should be used.
|
|
34
|
+
* @param {number} longitude
|
|
35
|
+
* double the longitude in a double format such as -74.222130 for Lakewood, NJ.
|
|
36
|
+
* <b>Note: </b> For longitudes west of the <a href="http://en.wikipedia.org/wiki/Prime_Meridian">Prime
|
|
37
|
+
* Meridian </a> (Greenwich), a negative value should be used.
|
|
38
|
+
* @param {number} elevation
|
|
39
|
+
* the elevation above sea level in Meters. Elevation is not used in most algorithms used for calculating
|
|
40
|
+
* sunrise and set.
|
|
41
|
+
* @param {string} timeZoneId
|
|
42
|
+
* the <code>TimeZone</code> for the location.
|
|
43
|
+
*/
|
|
44
|
+
constructor(name, latitude, longitude, elevation, timeZoneId) {
|
|
37
45
|
this.setLocationName(name);
|
|
38
46
|
this.setLatitude(latitude);
|
|
39
47
|
this.setLongitude(longitude);
|
|
@@ -42,34 +50,22 @@ export class GeoLocation {
|
|
|
42
50
|
}
|
|
43
51
|
/**
|
|
44
52
|
* @private
|
|
45
|
-
* @see #getLatitude()
|
|
46
|
-
* @see #setLatitude(double)
|
|
47
|
-
* @see #setLatitude(int, int, double, String)
|
|
48
53
|
*/
|
|
49
54
|
latitude;
|
|
50
55
|
/**
|
|
51
56
|
* @private
|
|
52
|
-
* @see #getLongitude()
|
|
53
|
-
* @see #setLongitude(double)
|
|
54
|
-
* @see #setLongitude(int, int, double, String)
|
|
55
57
|
*/
|
|
56
58
|
longitude;
|
|
57
59
|
/**
|
|
58
60
|
* @private
|
|
59
|
-
* @see #getLocationName()
|
|
60
|
-
* @see #setLocationName(String)
|
|
61
61
|
*/
|
|
62
62
|
locationName = null;
|
|
63
63
|
/**
|
|
64
64
|
* @private
|
|
65
|
-
* @see #getTimeZone()
|
|
66
|
-
* @see #setTimeZone(TimeZone)
|
|
67
65
|
*/
|
|
68
66
|
timeZoneId;
|
|
69
67
|
/**
|
|
70
68
|
* @private
|
|
71
|
-
* @see #getElevation()
|
|
72
|
-
* @see #setElevation(double)
|
|
73
69
|
*/
|
|
74
70
|
elevation;
|
|
75
71
|
/**
|
|
@@ -84,9 +80,14 @@ export class GeoLocation {
|
|
|
84
80
|
* Method to set the elevation in Meters <b>above </b> sea level.
|
|
85
81
|
*
|
|
86
82
|
* @param {number} elevation
|
|
87
|
-
* The elevation to set in Meters. An
|
|
83
|
+
* The elevation to set in Meters. An Error will be thrown if the value is a negative.
|
|
88
84
|
*/
|
|
89
85
|
setElevation(elevation) {
|
|
86
|
+
if (typeof elevation !== 'number')
|
|
87
|
+
throw new TypeError('Invalid elevation');
|
|
88
|
+
if (elevation < 0) {
|
|
89
|
+
throw new RangeError(`elevation ${elevation} must be zero or positive`);
|
|
90
|
+
}
|
|
90
91
|
this.elevation = elevation;
|
|
91
92
|
}
|
|
92
93
|
setLatitude(latitude) {
|
|
@@ -137,13 +138,7 @@ export class GeoLocation {
|
|
|
137
138
|
return this.timeZoneId;
|
|
138
139
|
}
|
|
139
140
|
/**
|
|
140
|
-
* Method to set the TimeZone.
|
|
141
|
-
* {@link AstronomicalCalendar}, it is critical that
|
|
142
|
-
* {@link AstronomicalCalendar#getCalendar()}.
|
|
143
|
-
* {@link java.util.Calendar#setTimeZone(TimeZone) setTimeZone(TimeZone)} be called in order for the
|
|
144
|
-
* AstronomicalCalendar to output times in the expected offset. This situation will arise if the
|
|
145
|
-
* AstronomicalCalendar is ever {@link AstronomicalCalendar#clone() cloned}.
|
|
146
|
-
*
|
|
141
|
+
* Method to set the TimeZone.
|
|
147
142
|
* @param {string} timeZoneId
|
|
148
143
|
* The timeZone to set.
|
|
149
144
|
*/
|
|
@@ -185,14 +180,11 @@ const earthRadius = 6356.9; // in KM
|
|
|
185
180
|
export class NOAACalculator {
|
|
186
181
|
/**
|
|
187
182
|
* A constructor that takes in <a href="http://en.wikipedia.org/wiki/Geolocation">geolocation</a> information as a
|
|
188
|
-
* parameter.
|
|
189
|
-
* calculations is the the {@link NOAACalculator}.
|
|
183
|
+
* parameter.
|
|
190
184
|
*
|
|
191
185
|
* @param {GeoLocation} geoLocation
|
|
192
186
|
* The location information used for calculating astronomical sun times.
|
|
193
187
|
* @param {Temporal.PlainDate} date
|
|
194
|
-
*
|
|
195
|
-
* @see #setAstronomicalCalculator(AstronomicalCalculator) for changing the calculator class.
|
|
196
188
|
*/
|
|
197
189
|
constructor(geoLocation, date) {
|
|
198
190
|
this.date = date;
|
|
@@ -210,8 +202,8 @@ export class NOAACalculator {
|
|
|
210
202
|
* a point, and because the atmosphere refracts light, this 90° zenith does not, in fact, correspond to true
|
|
211
203
|
* sunset or sunrise, instead the center of the Sun's disk must lie just below the horizon for the upper edge to be
|
|
212
204
|
* obscured. This means that a zenith of just above 90° must be used. The Sun subtends an angle of 16 minutes of
|
|
213
|
-
* arc
|
|
214
|
-
* 34 minutes or so
|
|
205
|
+
* arc, and atmospheric refraction accounts for
|
|
206
|
+
* 34 minutes or so, giving a total of 50
|
|
215
207
|
* arcminutes. The total value for ZENITH is 90+(5/6) or 90.8333333° for true sunrise/sunset.
|
|
216
208
|
*/
|
|
217
209
|
// const ZENITH: number = GEOMETRIC_ZENITH + 5.0 / 6.0;
|
|
@@ -233,28 +225,27 @@ export class NOAACalculator {
|
|
|
233
225
|
geoLocation;
|
|
234
226
|
/**
|
|
235
227
|
* The getSunrise method Returns a `Date` representing the
|
|
236
|
-
* {@link
|
|
237
|
-
* for the calculation uses {@link
|
|
238
|
-
* {@link
|
|
239
|
-
*
|
|
240
|
-
* and 16 archminutes for the sun's radius for a total of {@link
|
|
241
|
-
* See documentation for the specific implementation of the {@link AstronomicalCalculator} that you are using.
|
|
228
|
+
* {@link getElevationAdjustment elevation adjusted} sunrise time. The zenith used
|
|
229
|
+
* for the calculation uses {@link GEOMETRIC_ZENITH geometric zenith} of 90° plus
|
|
230
|
+
* {@link getElevationAdjustment}. This is adjusted
|
|
231
|
+
* to add approximately 50/60 of a degree to account for 34 archminutes of refraction
|
|
232
|
+
* and 16 archminutes for the sun's radius for a total of {@link adjustZenith 90.83333°}.
|
|
242
233
|
*
|
|
243
234
|
* @return {Temporal.ZonedDateTime | null} the `Date` representing the exact sunrise time. If the calculation can't be computed such as
|
|
244
235
|
* in the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
|
|
245
236
|
* does not set, a null will be returned. See detailed explanation on top of the page.
|
|
246
|
-
* @see
|
|
247
|
-
* @see
|
|
248
|
-
* @see
|
|
237
|
+
* @see adjustZenith
|
|
238
|
+
* @see getSeaLevelSunrise()
|
|
239
|
+
* @see getUTCSunrise
|
|
249
240
|
*/
|
|
250
241
|
getSunrise() {
|
|
251
242
|
const sunrise = this.getUTCSunrise0(NOAACalculator.GEOMETRIC_ZENITH);
|
|
252
|
-
if (
|
|
243
|
+
if (isNaN(sunrise))
|
|
253
244
|
return null;
|
|
254
245
|
return this.getDateFromTime(sunrise, true);
|
|
255
246
|
}
|
|
256
247
|
/**
|
|
257
|
-
* A method that returns the sunrise without {@link
|
|
248
|
+
* A method that returns the sunrise without {@link getElevationAdjustment elevation
|
|
258
249
|
* adjustment}. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light,
|
|
259
250
|
* something that is not affected by elevation. This method returns sunrise calculated at sea level. This forms the
|
|
260
251
|
* base for dawn calculations that are calculated as a dip below the horizon before sunrise.
|
|
@@ -262,55 +253,55 @@ export class NOAACalculator {
|
|
|
262
253
|
* @return {Temporal.ZonedDateTime | null} the `Date` representing the exact sea-level sunrise time. If the calculation can't be computed
|
|
263
254
|
* such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
|
|
264
255
|
* where it does not set, a null will be returned. See detailed explanation on top of the page.
|
|
265
|
-
* @see
|
|
266
|
-
* @see
|
|
267
|
-
* @see
|
|
256
|
+
* @see getSunrise
|
|
257
|
+
* @see getUTCSeaLevelSunrise
|
|
258
|
+
* @see getSeaLevelSunset()
|
|
268
259
|
*/
|
|
269
260
|
getSeaLevelSunrise() {
|
|
270
261
|
const sunrise = this.getUTCSeaLevelSunrise(NOAACalculator.GEOMETRIC_ZENITH);
|
|
271
|
-
if (
|
|
262
|
+
if (isNaN(sunrise))
|
|
272
263
|
return null;
|
|
273
264
|
return this.getDateFromTime(sunrise, true);
|
|
274
265
|
}
|
|
275
266
|
/**
|
|
276
|
-
* A method that returns the beginning of civil twilight (dawn) using a zenith of {@link
|
|
267
|
+
* A method that returns the beginning of civil twilight (dawn) using a zenith of {@link CIVIL_ZENITH 96°}.
|
|
277
268
|
*
|
|
278
269
|
* @return {Temporal.ZonedDateTime | null} The `Date` of the beginning of civil twilight using a zenith of 96°. If the calculation
|
|
279
270
|
* can't be computed, null will be returned. See detailed explanation on top of the page.
|
|
280
|
-
* @see
|
|
271
|
+
* @see CIVIL_ZENITH
|
|
281
272
|
*/
|
|
282
273
|
getBeginCivilTwilight() {
|
|
283
274
|
return this.getSunriseOffsetByDegrees(NOAACalculator.CIVIL_ZENITH);
|
|
284
275
|
}
|
|
285
276
|
/**
|
|
286
|
-
* A method that returns the beginning of nautical twilight using a zenith of {@link
|
|
277
|
+
* A method that returns the beginning of nautical twilight using a zenith of {@link NAUTICAL_ZENITH 102°}.
|
|
287
278
|
*
|
|
288
279
|
* @return {Temporal.ZonedDateTime | null} The `Date` of the beginning of nautical twilight using a zenith of 102°. If the
|
|
289
280
|
* calculation can't be computed null will be returned. See detailed explanation on top of the page.
|
|
290
|
-
* @see
|
|
281
|
+
* @see NAUTICAL_ZENITH
|
|
291
282
|
*/
|
|
292
283
|
getBeginNauticalTwilight() {
|
|
293
284
|
return this.getSunriseOffsetByDegrees(NOAACalculator.NAUTICAL_ZENITH);
|
|
294
285
|
}
|
|
295
286
|
/**
|
|
296
|
-
* A method that returns the beginning of astronomical twilight using a zenith of {@link
|
|
287
|
+
* A method that returns the beginning of astronomical twilight using a zenith of {@link ASTRONOMICAL_ZENITH
|
|
297
288
|
* 108°}.
|
|
298
289
|
*
|
|
299
290
|
* @return {Temporal.ZonedDateTime | null} The `Date` of the beginning of astronomical twilight using a zenith of 108°. If the
|
|
300
291
|
* calculation can't be computed, null will be returned. See detailed explanation on top of the page.
|
|
301
|
-
* @see
|
|
292
|
+
* @see ASTRONOMICAL_ZENITH
|
|
302
293
|
*/
|
|
303
294
|
getBeginAstronomicalTwilight() {
|
|
304
295
|
return this.getSunriseOffsetByDegrees(NOAACalculator.ASTRONOMICAL_ZENITH);
|
|
305
296
|
}
|
|
306
297
|
/**
|
|
307
298
|
* The getSunset method Returns a `Date` representing the
|
|
308
|
-
* {@link
|
|
309
|
-
* the calculation uses {@link
|
|
310
|
-
* {@link
|
|
311
|
-
*
|
|
312
|
-
* and 16 archminutes for the sun's radius for a total of {@link
|
|
313
|
-
*
|
|
299
|
+
* {@link getElevationAdjustment elevation adjusted} sunset time. The zenith used for
|
|
300
|
+
* the calculation uses {@link GEOMETRIC_ZENITH geometric zenith} of 90° plus
|
|
301
|
+
* {@link getElevationAdjustment}. This is adjusted
|
|
302
|
+
* to add approximately 50/60 of a degree to account for 34 archminutes of refraction
|
|
303
|
+
* and 16 archminutes for the sun's radius for a total of {@link adjustZenith 90.83333°}.
|
|
304
|
+
* Note:
|
|
314
305
|
* In certain cases the calculates sunset will occur before sunrise. This will typically happen when a timezone
|
|
315
306
|
* other than the local timezone is used (calculating Los Angeles sunset using a GMT timezone for example). In this
|
|
316
307
|
* case the sunset date will be incremented to the following date.
|
|
@@ -318,18 +309,18 @@ export class NOAACalculator {
|
|
|
318
309
|
* @return {Temporal.ZonedDateTime | null} The `Date` representing the exact sunset time. If the calculation can't be computed such as in
|
|
319
310
|
* the Arctic Circle where there is at least one day a year where the sun does not rise, and one where it
|
|
320
311
|
* does not set, a null will be returned. See detailed explanation on top of the page.
|
|
321
|
-
* @see
|
|
322
|
-
* @see
|
|
323
|
-
* @see
|
|
312
|
+
* @see adjustZenith
|
|
313
|
+
* @see getSeaLevelSunset()
|
|
314
|
+
* @see getUTCSunset
|
|
324
315
|
*/
|
|
325
316
|
getSunset() {
|
|
326
317
|
const sunset = this.getUTCSunset0(NOAACalculator.GEOMETRIC_ZENITH);
|
|
327
|
-
if (
|
|
318
|
+
if (isNaN(sunset))
|
|
328
319
|
return null;
|
|
329
320
|
return this.getDateFromTime(sunset, false);
|
|
330
321
|
}
|
|
331
322
|
/**
|
|
332
|
-
* A method that returns the sunset without {@link
|
|
323
|
+
* A method that returns the sunset without {@link getElevationAdjustment elevation
|
|
333
324
|
* adjustment}. Non-sunrise and sunset calculations such as dawn and dusk, depend on the amount of visible light,
|
|
334
325
|
* something that is not affected by elevation. This method returns sunset calculated at sea level. This forms the
|
|
335
326
|
* base for dusk calculations that are calculated as a dip below the horizon after sunset.
|
|
@@ -337,43 +328,43 @@ export class NOAACalculator {
|
|
|
337
328
|
* @return {Temporal.ZonedDateTime | null} The `Date` representing the exact sea-level sunset time. If the calculation can't be computed
|
|
338
329
|
* such as in the Arctic Circle where there is at least one day a year where the sun does not rise, and one
|
|
339
330
|
* where it does not set, a null will be returned. See detailed explanation on top of the page.
|
|
340
|
-
* @see
|
|
341
|
-
* @see
|
|
331
|
+
* @see getSunset
|
|
332
|
+
* @see getUTCSeaLevelSunset
|
|
342
333
|
*/
|
|
343
334
|
getSeaLevelSunset() {
|
|
344
335
|
const sunset = this.getUTCSeaLevelSunset(NOAACalculator.GEOMETRIC_ZENITH);
|
|
345
|
-
if (
|
|
336
|
+
if (isNaN(sunset))
|
|
346
337
|
return null;
|
|
347
338
|
return this.getDateFromTime(sunset, false);
|
|
348
339
|
}
|
|
349
340
|
/**
|
|
350
|
-
* A method that returns the end of civil twilight using a zenith of {@link
|
|
341
|
+
* A method that returns the end of civil twilight using a zenith of {@link CIVIL_ZENITH 96°}.
|
|
351
342
|
*
|
|
352
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of civil twilight using a zenith of {@link
|
|
343
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of civil twilight using a zenith of {@link CIVIL_ZENITH 96°}. If
|
|
353
344
|
* the calculation can't be computed, null will be returned. See detailed explanation on top of the page.
|
|
354
|
-
* @see
|
|
345
|
+
* @see CIVIL_ZENITH
|
|
355
346
|
*/
|
|
356
347
|
getEndCivilTwilight() {
|
|
357
348
|
return this.getSunsetOffsetByDegrees(NOAACalculator.CIVIL_ZENITH);
|
|
358
349
|
}
|
|
359
350
|
/**
|
|
360
|
-
* A method that returns the end of nautical twilight using a zenith of {@link
|
|
351
|
+
* A method that returns the end of nautical twilight using a zenith of {@link NAUTICAL_ZENITH 102°}.
|
|
361
352
|
*
|
|
362
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of nautical twilight using a zenith of {@link
|
|
353
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of nautical twilight using a zenith of {@link NAUTICAL_ZENITH 102°}
|
|
363
354
|
* . If the calculation can't be computed, null will be returned. See detailed explanation on top of the
|
|
364
355
|
* page.
|
|
365
|
-
* @see
|
|
356
|
+
* @see NAUTICAL_ZENITH
|
|
366
357
|
*/
|
|
367
358
|
getEndNauticalTwilight() {
|
|
368
359
|
return this.getSunsetOffsetByDegrees(NOAACalculator.NAUTICAL_ZENITH);
|
|
369
360
|
}
|
|
370
361
|
/**
|
|
371
|
-
* A method that returns the end of astronomical twilight using a zenith of {@link
|
|
362
|
+
* A method that returns the end of astronomical twilight using a zenith of {@link ASTRONOMICAL_ZENITH 108°}.
|
|
372
363
|
*
|
|
373
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of astronomical twilight using a zenith of {@link
|
|
364
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the end of astronomical twilight using a zenith of {@link ASTRONOMICAL_ZENITH
|
|
374
365
|
* 108°}. If the calculation can't be computed, null will be returned. See detailed explanation on top
|
|
375
366
|
* of the page.
|
|
376
|
-
* @see
|
|
367
|
+
* @see ASTRONOMICAL_ZENITH
|
|
377
368
|
*/
|
|
378
369
|
getEndAstronomicalTwilight() {
|
|
379
370
|
return this.getSunsetOffsetByDegrees(NOAACalculator.ASTRONOMICAL_ZENITH);
|
|
@@ -391,49 +382,49 @@ export class NOAACalculator {
|
|
|
391
382
|
* @return {Temporal.ZonedDateTime | null} the `Date` with the offset in milliseconds added to it
|
|
392
383
|
*/
|
|
393
384
|
static getTimeOffset(time, offset) {
|
|
394
|
-
if (time === null ||
|
|
385
|
+
if (time === null || isNaN(offset)) {
|
|
395
386
|
return null;
|
|
396
387
|
}
|
|
397
388
|
return time.add({ milliseconds: offset });
|
|
398
389
|
}
|
|
399
390
|
/**
|
|
400
391
|
* A utility method that returns the time of an offset by degrees below or above the horizon of
|
|
401
|
-
* {@link
|
|
402
|
-
* before sunrise, an offset of 14 + {@link
|
|
392
|
+
* {@link getSunrise() sunrise}. Note that the degree offset is from the vertical, so for a calculation of 14°
|
|
393
|
+
* before sunrise, an offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
|
|
403
394
|
*
|
|
404
395
|
* @param {number} offsetZenith
|
|
405
|
-
* the degrees before {@link
|
|
396
|
+
* the degrees before {@link getSunrise} to use in the calculation. For time after sunrise use
|
|
406
397
|
* negative numbers. Note that the degree offset is from the vertical, so for a calculation of 14°
|
|
407
|
-
* before sunrise, an offset of 14 + {@link
|
|
398
|
+
* before sunrise, an offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a
|
|
408
399
|
* parameter.
|
|
409
|
-
* @return {Temporal.ZonedDateTime | null} The `Date` of the offset after (or before) {@link
|
|
400
|
+
* @return {Temporal.ZonedDateTime | null} The `Date` of the offset after (or before) {@link getSunrise}. If the calculation
|
|
410
401
|
* can't be computed such as in the Arctic Circle where there is at least one day a year where the sun does
|
|
411
402
|
* not rise, and one where it does not set, a null will be returned. See detailed explanation on top of the
|
|
412
403
|
* page.
|
|
413
404
|
*/
|
|
414
405
|
getSunriseOffsetByDegrees(offsetZenith) {
|
|
415
406
|
const dawn = this.getUTCSunrise0(offsetZenith);
|
|
416
|
-
if (
|
|
407
|
+
if (isNaN(dawn))
|
|
417
408
|
return null;
|
|
418
409
|
return this.getDateFromTime(dawn, true);
|
|
419
410
|
}
|
|
420
411
|
/**
|
|
421
|
-
* A utility method that returns the time of an offset by degrees below or above the horizon of {@link
|
|
412
|
+
* A utility method that returns the time of an offset by degrees below or above the horizon of {@link getSunset()
|
|
422
413
|
* sunset}. Note that the degree offset is from the vertical, so for a calculation of 14° after sunset, an
|
|
423
|
-
* offset of 14 + {@link
|
|
414
|
+
* offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
|
|
424
415
|
*
|
|
425
416
|
* @param {number} offsetZenith
|
|
426
|
-
* the degrees after {@link
|
|
417
|
+
* the degrees after {@link getSunset} to use in the calculation. For time before sunset use negative
|
|
427
418
|
* numbers. Note that the degree offset is from the vertical, so for a calculation of 14° after
|
|
428
|
-
* sunset, an offset of 14 + {@link
|
|
429
|
-
* @return {Temporal.ZonedDateTime | null} The `Date`of the offset after (or before) {@link
|
|
419
|
+
* sunset, an offset of 14 + {@link GEOMETRIC_ZENITH} = 104 would have to be passed as a parameter.
|
|
420
|
+
* @return {Temporal.ZonedDateTime | null} The `Date`of the offset after (or before) {@link getSunset}. If the calculation can't
|
|
430
421
|
* be computed such as in the Arctic Circle where there is at least one day a year where the sun does not
|
|
431
422
|
* rise, and one where it does not set, a null will be returned. See detailed explanation on top of the
|
|
432
423
|
* page.
|
|
433
424
|
*/
|
|
434
425
|
getSunsetOffsetByDegrees(offsetZenith) {
|
|
435
426
|
const sunset = this.getUTCSunset0(offsetZenith);
|
|
436
|
-
if (
|
|
427
|
+
if (isNaN(sunset))
|
|
437
428
|
return null;
|
|
438
429
|
return this.getDateFromTime(sunset, false);
|
|
439
430
|
}
|
|
@@ -445,7 +436,7 @@ export class NOAACalculator {
|
|
|
445
436
|
* the degrees below the horizon. For time after sunrise use negative numbers.
|
|
446
437
|
* @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
|
|
447
438
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
448
|
-
* not set,
|
|
439
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
449
440
|
*/
|
|
450
441
|
getUTCSunrise0(zenith) {
|
|
451
442
|
return this.getUTCSunrise(this.getAdjustedDate(), this.geoLocation, zenith, true);
|
|
@@ -460,9 +451,9 @@ export class NOAACalculator {
|
|
|
460
451
|
* the degrees below the horizon. For time after sunrise use negative numbers.
|
|
461
452
|
* @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
|
|
462
453
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
463
|
-
* not set,
|
|
464
|
-
* @see
|
|
465
|
-
* @see
|
|
454
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
455
|
+
* @see getUTCSunrise
|
|
456
|
+
* @see getUTCSeaLevelSunset
|
|
466
457
|
*/
|
|
467
458
|
getUTCSeaLevelSunrise(zenith) {
|
|
468
459
|
return this.getUTCSunrise(this.getAdjustedDate(), this.geoLocation, zenith, false);
|
|
@@ -475,8 +466,8 @@ export class NOAACalculator {
|
|
|
475
466
|
* the degrees below the horizon. For time after sunset use negative numbers.
|
|
476
467
|
* @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
|
|
477
468
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
478
|
-
* not set,
|
|
479
|
-
* @see
|
|
469
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
470
|
+
* @see getUTCSeaLevelSunset
|
|
480
471
|
*/
|
|
481
472
|
getUTCSunset0(zenith) {
|
|
482
473
|
return this.getUTCSunset(this.getAdjustedDate(), this.geoLocation, zenith, true);
|
|
@@ -492,9 +483,9 @@ export class NOAACalculator {
|
|
|
492
483
|
* the degrees below the horizon. For time before sunset use negative numbers.
|
|
493
484
|
* @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
|
|
494
485
|
* Arctic Circle where there is at least one day a year where the sun does not rise, and one where it does
|
|
495
|
-
* not set,
|
|
496
|
-
* @see
|
|
497
|
-
* @see
|
|
486
|
+
* not set, `NaN` will be returned. See detailed explanation on top of the page.
|
|
487
|
+
* @see getUTCSunset
|
|
488
|
+
* @see getUTCSeaLevelSunrise
|
|
498
489
|
*/
|
|
499
490
|
getUTCSeaLevelSunset(zenith) {
|
|
500
491
|
return this.getUTCSunset(this.getAdjustedDate(), this.geoLocation, zenith, false);
|
|
@@ -512,9 +503,9 @@ export class NOAACalculator {
|
|
|
512
503
|
* Method to return the adjustment to the zenith required to account for the elevation. Since a person at a higher
|
|
513
504
|
* elevation can see farther below the horizon, the calculation for sunrise / sunset is calculated below the horizon
|
|
514
505
|
* used at sea level. This is only used for sunrise and sunset and not times before or after it such as
|
|
515
|
-
* {@link
|
|
506
|
+
* {@link getBeginNauticalTwilight() nautical twilight} since those
|
|
516
507
|
* calculations are based on the level of available light at the given dip below the horizon, something that is not
|
|
517
|
-
* affected by elevation, the adjustment should only made if the zenith == 90° {@link
|
|
508
|
+
* affected by elevation, the adjustment should only made if the zenith == 90° {@link adjustZenith adjusted}
|
|
518
509
|
* for refraction and solar radius. The algorithm used is
|
|
519
510
|
*
|
|
520
511
|
* <pre>
|
|
@@ -546,30 +537,30 @@ export class NOAACalculator {
|
|
|
546
537
|
* is not a point, and because the atmosphere refracts light, this 90° zenith does not, in fact, correspond to
|
|
547
538
|
* true sunset or sunrise, instead the centre of the Sun's disk must lie just below the horizon for the upper edge
|
|
548
539
|
* to be obscured. This means that a zenith of just above 90° must be used. The Sun subtends an angle of 16
|
|
549
|
-
* minutes of arc
|
|
550
|
-
* accounts for 34 minutes or so
|
|
540
|
+
* minutes of arc, and atmospheric refraction
|
|
541
|
+
* accounts for 34 minutes or so, giving a total
|
|
551
542
|
* of 50 arcminutes. The total value for ZENITH is 90+(5/6) or 90.8333333° for true sunrise/sunset. Since a
|
|
552
543
|
* person at an elevation can see blow the horizon of a person at sea level, this will also adjust the zenith to
|
|
553
544
|
* account for elevation if available. Note that this will only adjust the value if the zenith is exactly 90 degrees.
|
|
554
545
|
* For values below and above this no correction is done. As an example, astronomical twilight is when the sun is
|
|
555
|
-
* 18° below the horizon or {@link
|
|
546
|
+
* 18° below the horizon or {@link ASTRONOMICAL_ZENITH 108°
|
|
556
547
|
* below the zenith}. This is traditionally calculated with none of the above mentioned adjustments. The same goes
|
|
557
548
|
* for various <em>tzais</em> and <em>alos</em> times such as the
|
|
558
549
|
* {@link ZmanimCalendar#ZENITH_16_POINT_1 16.1°} dip used in
|
|
559
|
-
* {@link ComplexZmanimCalendar#getAlos16Point1Degrees
|
|
550
|
+
* {@link ComplexZmanimCalendar#getAlos16Point1Degrees}.
|
|
560
551
|
*
|
|
561
552
|
* @param {number} zenith
|
|
562
|
-
* the azimuth below the vertical zenith of 90°. For sunset typically the {@link
|
|
563
|
-
* zenith} used for the calculation uses geometric zenith of 90° and {@link
|
|
553
|
+
* the azimuth below the vertical zenith of 90°. For sunset typically the {@link adjustZenith
|
|
554
|
+
* zenith} used for the calculation uses geometric zenith of 90° and {@link adjustZenith adjusts}
|
|
564
555
|
* this slightly to account for solar refraction and the sun's radius. Another example would be
|
|
565
|
-
* {@link
|
|
566
|
-
* {@link
|
|
556
|
+
* {@link getEndNauticalTwilight} that passes
|
|
557
|
+
* {@link NAUTICAL_ZENITH} to this method.
|
|
567
558
|
* @param {number} elevation
|
|
568
559
|
* elevation in Meters.
|
|
569
|
-
* @return {number} The zenith adjusted to include the
|
|
570
|
-
*
|
|
560
|
+
* @return {number} The zenith adjusted to include the sun's radius, refracton
|
|
561
|
+
* and {@link getElevationAdjustment elevation} adjustment. This will only be adjusted for
|
|
571
562
|
* sunrise and sunset (if the zenith == 90°)
|
|
572
|
-
* @see
|
|
563
|
+
* @see getElevationAdjustment
|
|
573
564
|
*/
|
|
574
565
|
adjustZenith(zenith, elevation) {
|
|
575
566
|
let adjustedZenith = zenith;
|
|
@@ -592,7 +583,22 @@ export class NOAACalculator {
|
|
|
592
583
|
*/
|
|
593
584
|
static JULIAN_DAYS_PER_CENTURY = 36525;
|
|
594
585
|
/**
|
|
595
|
-
*
|
|
586
|
+
* A method that calculates UTC sunrise as well as any time based on an angle above or below sunrise.
|
|
587
|
+
* @param date
|
|
588
|
+
* Used to calculate day of year.
|
|
589
|
+
* @param geoLocation
|
|
590
|
+
* The location information used for astronomical calculating sun times.
|
|
591
|
+
* @param zenith
|
|
592
|
+
* the azimuth below the vertical zenith of 90 degrees. for sunrise typically the {@link adjustZenith
|
|
593
|
+
* zenith} used for the calculation uses geometric zenith of 90° and {@link adjustZenith adjusts}
|
|
594
|
+
* this slightly to account for solar refraction and the sun's radius. Another example would be
|
|
595
|
+
* {@link getBeginNauticalTwilight} that passes
|
|
596
|
+
* {@link NAUTICAL_ZENITH} to this method.
|
|
597
|
+
* @param adjustForElevation
|
|
598
|
+
* Should the time be adjusted for elevation
|
|
599
|
+
* @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
|
|
600
|
+
* the calculation (expected behavior for some locations such as near the poles,
|
|
601
|
+
* `NaN` will be returned.
|
|
596
602
|
*/
|
|
597
603
|
getUTCSunrise(date, geoLocation, zenith, adjustForElevation) {
|
|
598
604
|
const elevation = adjustForElevation
|
|
@@ -611,7 +617,22 @@ export class NOAACalculator {
|
|
|
611
617
|
return sunrise;
|
|
612
618
|
}
|
|
613
619
|
/**
|
|
614
|
-
*
|
|
620
|
+
* A method that calculates UTC sunset as well as any time based on an angle above or below sunset.
|
|
621
|
+
* @param date
|
|
622
|
+
* Used to calculate day of year.
|
|
623
|
+
* @param geoLocation
|
|
624
|
+
* The location information used for astronomical calculating sun times.
|
|
625
|
+
* @param zenith
|
|
626
|
+
* the azimuth below the vertical zenith of 90°. For sunset typically the {@link adjustZenith
|
|
627
|
+
* zenith} used for the calculation uses geometric zenith of 90° and {@link adjustZenith adjusts}
|
|
628
|
+
* this slightly to account for solar refraction and the sun's radius. Another example would be
|
|
629
|
+
* {@link getEndNauticalTwilight} that passes
|
|
630
|
+
* {@link NAUTICAL_ZENITH} to this method.
|
|
631
|
+
* @param adjustForElevation
|
|
632
|
+
* Should the time be adjusted for elevation
|
|
633
|
+
* @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
|
|
634
|
+
* the calculation (expected behavior for some locations such as near the poles,
|
|
635
|
+
* `NaN` will be returned.
|
|
615
636
|
*/
|
|
616
637
|
getUTCSunset(date, geoLocation, zenith, adjustForElevation) {
|
|
617
638
|
const elevation = adjustForElevation
|
|
@@ -632,8 +653,8 @@ export class NOAACalculator {
|
|
|
632
653
|
/**
|
|
633
654
|
* A utility method that will allow the calculation of a temporal (solar) hour based on the sunrise and sunset
|
|
634
655
|
* passed as parameters to this method. An example of the use of this method would be the calculation of a
|
|
635
|
-
* non-elevation adjusted temporal hour by passing in {@link
|
|
636
|
-
* {@link
|
|
656
|
+
* non-elevation adjusted temporal hour by passing in {@link getSeaLevelSunrise() sea level sunrise} and
|
|
657
|
+
* {@link getSeaLevelSunset() sea level sunset} as parameters.
|
|
637
658
|
*
|
|
638
659
|
* @param {Temporal.ZonedDateTime | null} startOfDay
|
|
639
660
|
* The start of the day.
|
|
@@ -641,13 +662,13 @@ export class NOAACalculator {
|
|
|
641
662
|
* The end of the day.
|
|
642
663
|
*
|
|
643
664
|
* @return {number} the <code>long</code> millisecond length of the temporal hour. If the calculation can't be computed a
|
|
644
|
-
*
|
|
665
|
+
* `NaN` will be returned. See detailed explanation on top of the page.
|
|
645
666
|
*
|
|
646
|
-
* @see
|
|
667
|
+
* @see getTemporalHour()
|
|
647
668
|
*/
|
|
648
669
|
getTemporalHour(startOfDay = this.getSeaLevelSunrise(), endOfDay = this.getSeaLevelSunset()) {
|
|
649
670
|
if (startOfDay === null || endOfDay === null) {
|
|
650
|
-
return
|
|
671
|
+
return NaN;
|
|
651
672
|
}
|
|
652
673
|
const delta = endOfDay.epochMilliseconds - startOfDay.epochMilliseconds;
|
|
653
674
|
return Math.floor(delta / 12);
|
|
@@ -684,7 +705,7 @@ export class NOAACalculator {
|
|
|
684
705
|
* @return {Temporal.ZonedDateTime | null} The Date.
|
|
685
706
|
*/
|
|
686
707
|
getDateFromTime(time, isSunrise) {
|
|
687
|
-
if (
|
|
708
|
+
if (isNaN(time)) {
|
|
688
709
|
return null;
|
|
689
710
|
}
|
|
690
711
|
let calculatedTime = time;
|
|
@@ -929,8 +950,7 @@ export class NOAACalculator {
|
|
|
929
950
|
}
|
|
930
951
|
/**
|
|
931
952
|
* Returns the <a href="http://en.wikipedia.org/wiki/Hour_angle">hour angle</a> of the sun at sunset for the
|
|
932
|
-
* latitude.
|
|
933
|
-
* duplication of code.
|
|
953
|
+
* latitude.
|
|
934
954
|
* @private
|
|
935
955
|
* @param {number} lat
|
|
936
956
|
* the latitude of observer in degrees
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hebcal/noaa",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.10",
|
|
4
4
|
"description": "sunrise and sunset via NOAA algorithm with elevation, based on KosherJava",
|
|
5
5
|
"author": "Michael J. Radwin (https://github.com/mjradwin)",
|
|
6
6
|
"contributors": [
|
|
@@ -23,17 +23,14 @@
|
|
|
23
23
|
"types": "./dist/index.d.ts"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"test": "echo \"
|
|
26
|
+
"test": "echo \"Nothing to test -- no test specified\" && exit 0",
|
|
27
27
|
"build": "npm run build:cjs && mv dist/index.js dist/index.cjs && npm run build:es6",
|
|
28
28
|
"build:cjs": "tsc -p ./tsconfig-cjs.json",
|
|
29
29
|
"build:es6": "tsc",
|
|
30
|
-
"lint": "gts lint",
|
|
31
30
|
"clean": "gts clean",
|
|
32
|
-
"compile": "tsc",
|
|
33
31
|
"fix": "gts fix",
|
|
34
|
-
"prepare": "npm run
|
|
35
|
-
"pretest": "npm run
|
|
36
|
-
"posttest": "npm run lint"
|
|
32
|
+
"prepare": "npm run build",
|
|
33
|
+
"pretest": "npm run build"
|
|
37
34
|
},
|
|
38
35
|
"keywords": [
|
|
39
36
|
"zmanim",
|