jcal-zmanim 1.0.4
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/LICENSE +674 -0
- package/README.md +2 -0
- package/build/AppUtils.d.ts +109 -0
- package/build/AppUtils.js +394 -0
- package/build/GeneralUtils.d.ts +43 -0
- package/build/GeneralUtils.js +93 -0
- package/build/JCal/Dafyomi.d.ts +27 -0
- package/build/JCal/Dafyomi.js +131 -0
- package/build/JCal/Location.d.ts +33 -0
- package/build/JCal/Location.js +80 -0
- package/build/JCal/Molad.d.ts +39 -0
- package/build/JCal/Molad.js +95 -0
- package/build/JCal/PirkeiAvos.d.ts +13 -0
- package/build/JCal/PirkeiAvos.js +172 -0
- package/build/JCal/Sedra.d.ts +63 -0
- package/build/JCal/Sedra.js +186 -0
- package/build/JCal/Utils.d.ts +225 -0
- package/build/JCal/Utils.js +666 -0
- package/build/JCal/Zmanim.d.ts +95 -0
- package/build/JCal/Zmanim.js +224 -0
- package/build/JCal/jDate.d.ts +203 -0
- package/build/JCal/jDate.js +647 -0
- package/build/Locations.d.ts +7 -0
- package/build/Locations.js +1308 -0
- package/build/Notifications.d.ts +14 -0
- package/build/Notifications.js +1040 -0
- package/build/Settings.d.ts +25 -0
- package/build/Settings.js +75 -0
- package/build/ZmanTypes.d.ts +34 -0
- package/build/ZmanTypes.js +184 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +59 -0
- package/package.json +33 -0
- package/src/AppUtils.ts +500 -0
- package/src/GeneralUtils.ts +84 -0
- package/src/JCal/Dafyomi.ts +139 -0
- package/src/JCal/Location.ts +100 -0
- package/src/JCal/Molad.ts +105 -0
- package/src/JCal/PirkeiAvos.ts +180 -0
- package/src/JCal/Sedra.ts +215 -0
- package/src/JCal/Utils.ts +732 -0
- package/src/JCal/Zmanim.ts +270 -0
- package/src/JCal/jDate.ts +714 -0
- package/src/Locations.ts +1303 -0
- package/src/Notifications.ts +1243 -0
- package/src/Settings.ts +103 -0
- package/src/ZmanTypes.ts +184 -0
- package/src/index.ts +31 -0
- package/src/jcal-zmanim.d.ts +4 -0
- package/tsconfig.json +109 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
|
|
2
|
+
import Utils from './Utils.js';
|
|
3
|
+
import jDate from './jDate.js';
|
|
4
|
+
import { isValidDate } from '../GeneralUtils.js';
|
|
5
|
+
import Location from './Location.js';
|
|
6
|
+
import { SunTimes, Time } from '../jcal-zmanim.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Computes the daily Zmanim for any single date at any location.
|
|
10
|
+
* The astronomical and mathematical calculations were directly adapted from the excellent
|
|
11
|
+
* Jewish calendar calculation in C# Copyright © by Ulrich and Ziporah Greve (2005)
|
|
12
|
+
*/
|
|
13
|
+
export default class Zmanim {
|
|
14
|
+
/**
|
|
15
|
+
* Gets sunrise and sunset time for given date and Location.
|
|
16
|
+
* Accepts a javascript Date object, a string for creating a javascript date object or a jDate object.
|
|
17
|
+
* Location object is required.
|
|
18
|
+
* @returns {SunTimes}
|
|
19
|
+
* @param {Date | jDate} date A Javascript Date or Jewish Date for which to calculate the sun times.
|
|
20
|
+
* @param {Location} location Where on the globe to calculate the sun times for.
|
|
21
|
+
* @param {Boolean} considerElevation
|
|
22
|
+
*/
|
|
23
|
+
static getSunTimes(date: Date | jDate, location: Location, considerElevation = true): SunTimes {
|
|
24
|
+
if (date instanceof jDate) {
|
|
25
|
+
date = date.getDate();
|
|
26
|
+
}
|
|
27
|
+
else if (date instanceof String) {
|
|
28
|
+
date = new Date(date);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (!isValidDate(date)) {
|
|
32
|
+
throw 'Zmanim.getSunTimes: supplied date parameter cannot be converted to a Date';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let sunrise, sunset,
|
|
36
|
+
zenithDeg = 90, zenithMin = 50, lonHour = 0, longitude = 0, latitude = 0,
|
|
37
|
+
cosLat = 0, sinLat = 0, cosZen = 0, sinDec = 0, cosDec = 0,
|
|
38
|
+
xmRise = 0, xmSet = 0, xlRise = 0, xlSet = 0, aRise = 0, aSet = 0, ahrRise = 0, ahrSet = 0,
|
|
39
|
+
hRise = 0, hSet = 0, tRise = 0, tSet = 0, utRise = 0, utSet = 0;
|
|
40
|
+
|
|
41
|
+
const day = Zmanim.dayOfYear(date),
|
|
42
|
+
earthRadius = 6356900,
|
|
43
|
+
zenithAtElevation = Zmanim.degToDec(zenithDeg, zenithMin) +
|
|
44
|
+
Zmanim.radToDeg(Math.acos(earthRadius / (earthRadius +
|
|
45
|
+
(considerElevation ? location.Elevation : 0))));
|
|
46
|
+
|
|
47
|
+
zenithDeg = Math.floor(zenithAtElevation);
|
|
48
|
+
zenithMin = (zenithAtElevation - zenithDeg) * 60;
|
|
49
|
+
cosZen = Math.cos(0.01745 * Zmanim.degToDec(zenithDeg, zenithMin));
|
|
50
|
+
longitude = location.Longitude;
|
|
51
|
+
lonHour = longitude / 15;
|
|
52
|
+
latitude = location.Latitude;
|
|
53
|
+
cosLat = Math.cos(0.01745 * latitude);
|
|
54
|
+
sinLat = Math.sin(0.01745 * latitude);
|
|
55
|
+
tRise = day + (6 + lonHour) / 24;
|
|
56
|
+
tSet = day + (18 + lonHour) / 24;
|
|
57
|
+
xmRise = Zmanim.M(tRise);
|
|
58
|
+
xlRise = Zmanim.L(xmRise);
|
|
59
|
+
xmSet = Zmanim.M(tSet);
|
|
60
|
+
xlSet = Zmanim.L(xmSet);
|
|
61
|
+
aRise = 57.29578 * Math.atan(0.91746 * Math.tan(0.01745 * xlRise));
|
|
62
|
+
aSet = 57.29578 * Math.atan(0.91746 * Math.tan(0.01745 * xlSet));
|
|
63
|
+
if (Math.abs(aRise + 360 - xlRise) > 90) {
|
|
64
|
+
aRise += 180;
|
|
65
|
+
}
|
|
66
|
+
if (aRise > 360) {
|
|
67
|
+
aRise -= 360;
|
|
68
|
+
}
|
|
69
|
+
if (Math.abs(aSet + 360 - xlSet) > 90) {
|
|
70
|
+
aSet += 180;
|
|
71
|
+
}
|
|
72
|
+
if (aSet > 360) {
|
|
73
|
+
aSet -= 360;
|
|
74
|
+
}
|
|
75
|
+
ahrRise = aRise / 15;
|
|
76
|
+
sinDec = 0.39782 * Math.sin(0.01745 * xlRise);
|
|
77
|
+
cosDec = Math.sqrt(1 - sinDec * sinDec);
|
|
78
|
+
hRise = (cosZen - sinDec * sinLat) / (cosDec * cosLat);
|
|
79
|
+
ahrSet = aSet / 15;
|
|
80
|
+
sinDec = 0.39782 * Math.sin(0.01745 * xlSet);
|
|
81
|
+
cosDec = Math.sqrt(1 - sinDec * sinDec);
|
|
82
|
+
hSet = (cosZen - sinDec * sinLat) / (cosDec * cosLat);
|
|
83
|
+
if (Math.abs(hRise) <= 1) {
|
|
84
|
+
hRise = 57.29578 * Math.acos(hRise);
|
|
85
|
+
utRise = ((360 - hRise) / 15) + ahrRise + Zmanim.adj(tRise) + lonHour;
|
|
86
|
+
sunrise = Zmanim.timeAdj(utRise + location.UTCOffset, date, location);
|
|
87
|
+
if (sunrise.hour > 12) {
|
|
88
|
+
sunrise.hour -= 12;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (Math.abs(hSet) <= 1) {
|
|
93
|
+
hSet = 57.29578 * Math.acos(hSet);
|
|
94
|
+
utSet = (hRise / 15) + ahrSet + Zmanim.adj(tSet) + lonHour;
|
|
95
|
+
sunset = Zmanim.timeAdj(utSet + location.UTCOffset, date, location);
|
|
96
|
+
if (sunset.hour > 0 && sunset.hour < 12) {
|
|
97
|
+
sunset.hour += 12;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return { sunrise: sunrise, sunset: sunset };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @param {jDate | Date} date
|
|
106
|
+
* @param {Location} location
|
|
107
|
+
*/
|
|
108
|
+
static getChatzos(date: jDate | Date, location: Location) {
|
|
109
|
+
return Zmanim.getChatzosFromSuntimes(
|
|
110
|
+
Zmanim.getSunTimes(date, location, false));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @param {SunTimes} sunTimes
|
|
115
|
+
*/
|
|
116
|
+
static getChatzosFromSuntimes(sunTimes: SunTimes): Time {
|
|
117
|
+
const rise = sunTimes.sunrise,
|
|
118
|
+
set = sunTimes.sunset;
|
|
119
|
+
|
|
120
|
+
if (rise === undefined || isNaN(rise.hour) || set === undefined || isNaN(set.hour)) {
|
|
121
|
+
return { hour: NaN, minute: NaN };
|
|
122
|
+
}
|
|
123
|
+
const chatz = Utils.toInt((Utils.totalSeconds(set) - Utils.totalSeconds(rise)) / 2);
|
|
124
|
+
return Utils.addSeconds(rise, chatz);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @param {jDate | Date} date
|
|
129
|
+
* @param {Location} location
|
|
130
|
+
* @param {any} offset
|
|
131
|
+
*/
|
|
132
|
+
static getShaaZmanis(date: jDate | Date, location: Location, offset: number): number {
|
|
133
|
+
return Zmanim.getShaaZmanisFromSunTimes(
|
|
134
|
+
Zmanim.getSunTimes(date, location, false),
|
|
135
|
+
offset);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @param {{ sunrise: any; sunset: any; }} sunTimes
|
|
140
|
+
* @param {number} [offset]
|
|
141
|
+
*/
|
|
142
|
+
static getShaaZmanisFromSunTimes(sunTimes: SunTimes, offset?: number): number {
|
|
143
|
+
if (!sunTimes || !sunTimes.sunrise || !sunTimes.sunset) {
|
|
144
|
+
return 0;
|
|
145
|
+
}
|
|
146
|
+
let rise = sunTimes.sunrise,
|
|
147
|
+
set = sunTimes.sunset;
|
|
148
|
+
|
|
149
|
+
if (!rise || isNaN(rise.hour) || !set || isNaN(set.hour)) {
|
|
150
|
+
return NaN;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (offset) {
|
|
154
|
+
rise = Utils.addMinutes(rise, -offset) as Time;
|
|
155
|
+
set = Utils.addMinutes(set, offset) as Time;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return (Utils.totalSeconds(set) - Utils.totalSeconds(rise)) / 720;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* @param {{ sunrise: any; sunset: any; }} sunTimes
|
|
163
|
+
* @param {boolean} israel
|
|
164
|
+
*/
|
|
165
|
+
static getShaaZmanisMga(sunTimes: SunTimes, israel: boolean) {
|
|
166
|
+
const minutes = israel ? 90 : 72;
|
|
167
|
+
let rise = sunTimes.sunrise && Utils.addMinutes(sunTimes.sunrise, -minutes),
|
|
168
|
+
set = sunTimes.sunset && Utils.addMinutes(sunTimes.sunset, minutes);
|
|
169
|
+
|
|
170
|
+
if (!rise || isNaN(rise.hour) || !set || isNaN(set.hour)) {
|
|
171
|
+
return NaN;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return (Utils.totalSeconds(set) - Utils.totalSeconds(rise)) / 720;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @param {jDate | Date} date
|
|
179
|
+
* @param {Location} location
|
|
180
|
+
*/
|
|
181
|
+
static getCandleLighting(date: Date | jDate, location: Location) {
|
|
182
|
+
return Zmanim.getCandleLightingFromSunTimes(
|
|
183
|
+
Zmanim.getSunTimes(date, location),
|
|
184
|
+
location);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @param {SunTimes} sunTimes
|
|
189
|
+
* @param {any} location
|
|
190
|
+
*/
|
|
191
|
+
static getCandleLightingFromSunTimes(sunTimes: SunTimes, location: Location) {
|
|
192
|
+
return sunTimes.sunset && Zmanim.getCandleLightingFromSunset(sunTimes.sunset, location);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {Time} sunset
|
|
198
|
+
* @param {Location} location
|
|
199
|
+
*/
|
|
200
|
+
static getCandleLightingFromSunset(sunset: Time, location: Location) {
|
|
201
|
+
return Utils.addMinutes(sunset, -(location.CandleLighting || 0));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @param {Date} date
|
|
206
|
+
*/
|
|
207
|
+
static dayOfYear(date: Date) {
|
|
208
|
+
const month = date.getMonth(),
|
|
209
|
+
isLeap = () => Utils.isSecularLeapYear(date.getFullYear()),
|
|
210
|
+
yearDay = [0, 1, 32, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335];
|
|
211
|
+
return yearDay[month + 1] + date.getDate() + ((month > 1 && isLeap()) ? 1 : 0);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @param {number} deg
|
|
216
|
+
* @param {number} min
|
|
217
|
+
*/
|
|
218
|
+
static degToDec(deg: number, min: number) {
|
|
219
|
+
return (deg + min / 60);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* @param {number} x
|
|
224
|
+
*/
|
|
225
|
+
static M(x: number) {
|
|
226
|
+
return (0.9856 * x - 3.251);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @param {number} x
|
|
231
|
+
*/
|
|
232
|
+
static L(x: number) {
|
|
233
|
+
return (x + 1.916 * Math.sin(0.01745 * x) + 0.02 * Math.sin(2 * 0.01745 * x) + 282.565);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* @param {number} x
|
|
238
|
+
*/
|
|
239
|
+
static adj(x: number) {
|
|
240
|
+
return (-0.06571 * x - 6.62);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @param {number} rad
|
|
245
|
+
*/
|
|
246
|
+
static radToDeg(rad: number) {
|
|
247
|
+
return 57.29578 * rad;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @param {number} time
|
|
252
|
+
* @param {Date} date
|
|
253
|
+
* @param {Location} location
|
|
254
|
+
*/
|
|
255
|
+
static timeAdj(time: number, date: Date, location: Location) {
|
|
256
|
+
if (time < 0) {
|
|
257
|
+
time += 24;
|
|
258
|
+
}
|
|
259
|
+
let hour = Utils.toInt(time);
|
|
260
|
+
const minFloat = (time - hour) * 60 + 0.5,
|
|
261
|
+
min = Utils.toInt(minFloat),
|
|
262
|
+
sec = Math.round(60.0 * (minFloat - min));
|
|
263
|
+
|
|
264
|
+
if (Utils.isDST(location, date)) {
|
|
265
|
+
hour++;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return Utils.fixTime({ hour: hour, minute: min, second: sec });
|
|
269
|
+
}
|
|
270
|
+
}
|