@hebcal/core 6.5.0 → 6.5.2
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/bundle.js +5983 -5473
- package/dist/bundle.js.map +1 -1
- package/dist/bundle.min.js +17 -17
- package/dist/bundle.min.js.map +1 -1
- package/dist/esm/CalOptions.d.ts +7 -4
- package/dist/esm/DailyLearning.d.ts +44 -7
- package/dist/esm/DailyLearning.js +45 -8
- package/dist/esm/DailyLearning.js.map +1 -1
- package/dist/esm/HebrewDateEvent.js +1 -1
- package/dist/esm/HolidayEvent.d.ts +34 -1
- package/dist/esm/HolidayEvent.js +35 -2
- package/dist/esm/HolidayEvent.js.map +1 -1
- package/dist/esm/MevarchimChodeshEvent.js +1 -1
- package/dist/esm/ParshaEvent.js +1 -1
- package/dist/esm/TimedEvent.d.ts +32 -3
- package/dist/esm/TimedEvent.js +33 -4
- package/dist/esm/TimedEvent.js.map +1 -1
- package/dist/esm/YomKippurKatanEvent.js +1 -1
- package/dist/esm/ashkenazi.po.d.ts +1 -0
- package/dist/esm/ashkenazi.po.js +2 -2
- package/dist/esm/ashkenazi.po.js.map +1 -1
- package/dist/esm/calendar.d.ts +1 -0
- package/dist/esm/calendar.js +12 -2
- package/dist/esm/calendar.js.map +1 -1
- package/dist/esm/candles.d.ts +14 -1
- package/dist/esm/candles.js +15 -2
- package/dist/esm/candles.js.map +1 -1
- package/dist/esm/cities.json.js +5 -0
- package/dist/esm/cities.json.js.map +1 -0
- package/dist/esm/event.d.ts +58 -13
- package/dist/esm/event.js +59 -14
- package/dist/esm/event.js.map +1 -1
- package/dist/esm/getStartAndEnd.js +10 -2
- package/dist/esm/getStartAndEnd.js.map +1 -1
- package/dist/esm/hallel.js +20 -28
- package/dist/esm/hallel.js.map +1 -1
- package/dist/esm/he-x-NoNikud.po.js +1 -1
- package/dist/esm/he.po.d.ts +1 -0
- package/dist/esm/he.po.js +2 -2
- package/dist/esm/he.po.js.map +1 -1
- package/dist/esm/hebcal.d.ts +97 -19
- package/dist/esm/hebcal.js +102 -21
- package/dist/esm/hebcal.js.map +1 -1
- package/dist/esm/holidays.d.ts +21 -2
- package/dist/esm/holidays.js +39 -3
- package/dist/esm/holidays.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/isAssurBemlacha.d.ts +24 -4
- package/dist/esm/isAssurBemlacha.js +25 -5
- package/dist/esm/isAssurBemlacha.js.map +1 -1
- package/dist/esm/isAveilut.d.ts +14 -3
- package/dist/esm/isAveilut.js +15 -4
- package/dist/esm/isAveilut.js.map +1 -1
- package/dist/esm/isFastDay.d.ts +13 -1
- package/dist/esm/isFastDay.js +14 -2
- package/dist/esm/isFastDay.js.map +1 -1
- package/dist/esm/locale.js +1 -1
- package/dist/esm/location.d.ts +96 -8
- package/dist/esm/location.js +112 -88
- package/dist/esm/location.js.map +1 -1
- package/dist/esm/modern.js +1 -1
- package/dist/esm/molad.d.ts +39 -7
- package/dist/esm/molad.js +40 -8
- package/dist/esm/molad.js.map +1 -1
- package/dist/esm/moladBase.js +1 -1
- package/dist/esm/moladDate.js +1 -1
- package/dist/esm/omer.d.ts +32 -4
- package/dist/esm/omer.js +33 -5
- package/dist/esm/omer.js.map +1 -1
- package/dist/esm/parshaName.js +1 -1
- package/dist/esm/parshaYear.d.ts +12 -1
- package/dist/esm/parshaYear.js +13 -2
- package/dist/esm/parshaYear.js.map +1 -1
- package/dist/esm/pkgVersion.d.ts +1 -1
- package/dist/esm/pkgVersion.js +2 -2
- package/dist/esm/pkgVersion.js.map +1 -1
- package/dist/esm/reformatTimeStr.js +1 -1
- package/dist/esm/sedra.d.ts +94 -14
- package/dist/esm/sedra.js +95 -15
- package/dist/esm/sedra.js.map +1 -1
- package/dist/esm/sefira.json.js +1 -1
- package/dist/esm/staticHolidays.d.ts +2 -0
- package/dist/esm/staticHolidays.js +3 -1
- package/dist/esm/staticHolidays.js.map +1 -1
- package/dist/esm/tachanun.js +1 -1
- package/dist/esm/temporal-shim.js +1 -1
- package/dist/esm/zmanim.js +1 -1
- package/dist/src/CalOptions.d.ts +7 -4
- package/dist/src/DailyLearning.d.ts +44 -7
- package/dist/src/DailyLearning.js +44 -7
- package/dist/src/HolidayEvent.d.ts +34 -1
- package/dist/src/HolidayEvent.js +34 -1
- package/dist/src/TimedEvent.d.ts +32 -3
- package/dist/src/TimedEvent.js +32 -3
- package/dist/src/ashkenazi.po.d.ts +1 -0
- package/dist/src/ashkenazi.po.js +1 -1
- package/dist/src/calendar.d.ts +1 -0
- package/dist/src/calendar.js +11 -1
- package/dist/src/candles.d.ts +14 -1
- package/dist/src/candles.js +14 -1
- package/dist/src/cities.json +67 -0
- package/dist/src/event.d.ts +58 -13
- package/dist/src/event.js +58 -13
- package/dist/src/getStartAndEnd.js +9 -1
- package/dist/src/hallel.js +19 -27
- package/dist/src/he.po.d.ts +1 -0
- package/dist/src/he.po.js +1 -1
- package/dist/src/hebcal.d.ts +97 -19
- package/dist/src/hebcal.js +101 -20
- package/dist/src/holidays.d.ts +21 -2
- package/dist/src/holidays.js +38 -2
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/isAssurBemlacha.d.ts +24 -4
- package/dist/src/isAssurBemlacha.js +24 -4
- package/dist/src/isAveilut.d.ts +14 -3
- package/dist/src/isAveilut.js +14 -3
- package/dist/src/isFastDay.d.ts +13 -1
- package/dist/src/isFastDay.js +13 -1
- package/dist/src/location.d.ts +96 -8
- package/dist/src/location.js +111 -87
- package/dist/src/molad.d.ts +39 -7
- package/dist/src/molad.js +39 -7
- package/dist/src/omer.d.ts +32 -4
- package/dist/src/omer.js +32 -4
- package/dist/src/parshaYear.d.ts +12 -1
- package/dist/src/parshaYear.js +12 -1
- package/dist/src/pkgVersion.d.ts +1 -1
- package/dist/src/pkgVersion.js +1 -1
- package/dist/src/sedra.d.ts +94 -14
- package/dist/src/sedra.js +94 -14
- package/dist/src/staticHolidays.d.ts +2 -0
- package/dist/src/staticHolidays.js +2 -0
- package/package.json +6 -6
package/dist/esm/location.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
/*! @hebcal/core v6.5.
|
|
1
|
+
/*! @hebcal/core v6.5.2, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
2
2
|
import { GeoLocation } from '@hebcal/noaa';
|
|
3
|
+
import citiesJson from './cities.json.js';
|
|
4
|
+
import QuickLRU from 'quick-lru';
|
|
3
5
|
|
|
4
6
|
/*
|
|
5
7
|
Hebcal - A Jewish Calendar Generator
|
|
@@ -21,80 +23,6 @@ import { GeoLocation } from '@hebcal/noaa';
|
|
|
21
23
|
You should have received a copy of the GNU General Public License
|
|
22
24
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
23
25
|
*/
|
|
24
|
-
const classicCities0 = [
|
|
25
|
-
['Ashdod', 'IL', 31.79213, 34.64966, 'Asia/Jerusalem', 27],
|
|
26
|
-
['Atlanta', 'US', 33.749, -84.38798, 'America/New_York', 336],
|
|
27
|
-
['Austin', 'US', 30.26715, -97.74306, 'America/Chicago', 165],
|
|
28
|
-
['Baghdad', 'IQ', 33.34058, 44.40088, 'Asia/Baghdad', 41],
|
|
29
|
-
['Beer Sheva', 'IL', 31.25181, 34.7913, 'Asia/Jerusalem', 285],
|
|
30
|
-
['Berlin', 'DE', 52.52437, 13.41053, 'Europe/Berlin', 43],
|
|
31
|
-
['Baltimore', 'US', 39.29038, -76.61219, 'America/New_York', 35],
|
|
32
|
-
['Bogota', 'CO', 4.60971, -74.08175, 'America/Bogota', 2582],
|
|
33
|
-
['Boston', 'US', 42.35843, -71.05977, 'America/New_York', 38],
|
|
34
|
-
['Budapest', 'HU', 47.49801, 19.03991, 'Europe/Budapest', 104],
|
|
35
|
-
[
|
|
36
|
-
'Buenos Aires',
|
|
37
|
-
'AR',
|
|
38
|
-
-34.61315,
|
|
39
|
-
-58.37723,
|
|
40
|
-
'America/Argentina/Buenos_Aires',
|
|
41
|
-
31,
|
|
42
|
-
],
|
|
43
|
-
['Buffalo', 'US', 42.88645, -78.87837, 'America/New_York', 191],
|
|
44
|
-
['Chicago', 'US', 41.85003, -87.65005, 'America/Chicago', 180],
|
|
45
|
-
['Cincinnati', 'US', 39.162, -84.45689, 'America/New_York', 267],
|
|
46
|
-
['Cleveland', 'US', 41.4995, -81.69541, 'America/New_York', 204],
|
|
47
|
-
['Dallas', 'US', 32.78306, -96.80667, 'America/Chicago', 139],
|
|
48
|
-
['Denver', 'US', 39.73915, -104.9847, 'America/Denver', 1636],
|
|
49
|
-
['Detroit', 'US', 42.33143, -83.04575, 'America/Detroit', 192],
|
|
50
|
-
['Eilat', 'IL', 29.55805, 34.94821, 'Asia/Jerusalem', 63],
|
|
51
|
-
['Gibraltar', 'GI', 36.14474, -5.35257, 'Europe/Gibraltar', 11],
|
|
52
|
-
['Haifa', 'IL', 32.81841, 34.9885, 'Asia/Jerusalem', 40],
|
|
53
|
-
['Hawaii', 'US', 21.30694, -157.85833, 'Pacific/Honolulu', 18],
|
|
54
|
-
['Helsinki', 'FI', 60.16952, 24.93545, 'Europe/Helsinki', 26],
|
|
55
|
-
['Houston', 'US', 29.76328, -95.36327, 'America/Chicago', 30],
|
|
56
|
-
['Jerusalem', 'IL', 31.76904, 35.21633, 'Asia/Jerusalem', 786],
|
|
57
|
-
['Johannesburg', 'ZA', -26.20227, 28.04363, 'Africa/Johannesburg', 1767],
|
|
58
|
-
['Kiev', 'UA', 50.45466, 30.5238, 'Europe/Kiev', 187],
|
|
59
|
-
['La Paz', 'BO', -16.5, -68.15, 'America/La_Paz', 3782],
|
|
60
|
-
['Livingston', 'US', 40.79593, -74.31487, 'America/New_York', 98],
|
|
61
|
-
['Las Vegas', 'US', 36.17497, -115.13722, 'America/Los_Angeles', 613],
|
|
62
|
-
['London', 'GB', 51.50853, -0.12574, 'Europe/London', 25],
|
|
63
|
-
['Los Angeles', 'US', 34.05223, -118.24368, 'America/Los_Angeles', 96],
|
|
64
|
-
['Marseilles', 'FR', 43.29695, 5.38107, 'Europe/Paris', 28],
|
|
65
|
-
['Miami', 'US', 25.77427, -80.19366, 'America/New_York', 25],
|
|
66
|
-
['Minneapolis', 'US', 44.97997, -93.26384, 'America/Chicago', 262],
|
|
67
|
-
['Melbourne', 'AU', -37.814, 144.96332, 'Australia/Melbourne', 25],
|
|
68
|
-
['Mexico City', 'MX', 19.42847, -99.12766, 'America/Mexico_City', 2240],
|
|
69
|
-
['Montreal', 'CA', 45.50884, -73.58781, 'America/Toronto', 216],
|
|
70
|
-
['Moscow', 'RU', 55.75222, 37.61556, 'Europe/Moscow', 144],
|
|
71
|
-
['New York', 'US', 40.71427, -74.00597, 'America/New_York', 57],
|
|
72
|
-
['Omaha', 'US', 41.25861, -95.93779, 'America/Chicago', 315],
|
|
73
|
-
['Ottawa', 'CA', 45.41117, -75.69812, 'America/Toronto', 71],
|
|
74
|
-
['Panama City', 'PA', 8.9936, -79.51973, 'America/Panama', 17],
|
|
75
|
-
['Paris', 'FR', 48.85341, 2.3488, 'Europe/Paris', 42],
|
|
76
|
-
['Pawtucket', 'US', 41.87871, -71.38256, 'America/New_York', 0], // -11
|
|
77
|
-
['Petach Tikvah', 'IL', 32.08707, 34.88747, 'Asia/Jerusalem', 54],
|
|
78
|
-
['Philadelphia', 'US', 39.95233, -75.16379, 'America/New_York', 8],
|
|
79
|
-
['Phoenix', 'US', 33.44838, -112.07404, 'America/Phoenix', 366],
|
|
80
|
-
['Pittsburgh', 'US', 40.44062, -79.99589, 'America/New_York', 239],
|
|
81
|
-
['Providence', 'US', 41.82399, -71.41283, 'America/New_York', 0], // -15
|
|
82
|
-
['Portland', 'US', 45.52345, -122.67621, 'America/Los_Angeles', 15],
|
|
83
|
-
['Saint Louis', 'US', 38.62727, -90.19789, 'America/Chicago', 149],
|
|
84
|
-
['Saint Petersburg', 'RU', 59.93863, 30.31413, 'Europe/Moscow', 11],
|
|
85
|
-
['San Diego', 'US', 32.71533, -117.15726, 'America/Los_Angeles', 20],
|
|
86
|
-
['San Francisco', 'US', 37.77493, -122.41942, 'America/Los_Angeles', 28],
|
|
87
|
-
['Sao Paulo', 'BR', -23.5475, -46.63611, 'America/Sao_Paulo', 769],
|
|
88
|
-
['Seattle', 'US', 47.60621, -122.33207, 'America/Los_Angeles', 56],
|
|
89
|
-
['Sydney', 'AU', -33.86785, 151.20732, 'Australia/Sydney', 58],
|
|
90
|
-
['Tel Aviv', 'IL', 32.08088, 34.78057, 'Asia/Jerusalem', 15],
|
|
91
|
-
['Tiberias', 'IL', 32.79221, 35.53124, 'Asia/Jerusalem', 0], // -140
|
|
92
|
-
['Toronto', 'CA', 43.70011, -79.4163, 'America/Toronto', 175],
|
|
93
|
-
['Vancouver', 'CA', 49.24966, -123.11934, 'America/Vancouver', 70],
|
|
94
|
-
['White Plains', 'US', 41.03399, -73.76291, 'America/New_York', 82],
|
|
95
|
-
['Washington DC', 'US', 38.89511, -77.03637, 'America/New_York', 6],
|
|
96
|
-
['Worcester', 'US', 42.26259, -71.80229, 'America/New_York', 164],
|
|
97
|
-
];
|
|
98
26
|
const classicCities = new Map();
|
|
99
27
|
// Zip-Codes.com TimeZone IDs
|
|
100
28
|
const ZIPCODES_TZ_MAP = {
|
|
@@ -113,7 +41,9 @@ const ZIPCODES_TZ_MAP = {
|
|
|
113
41
|
'16': 'Pacific/Chuuk', // Micronesia (GMT +11:00)
|
|
114
42
|
};
|
|
115
43
|
/** @private */
|
|
116
|
-
const timeFormatCache = new
|
|
44
|
+
const timeFormatCache = new QuickLRU({
|
|
45
|
+
maxSize: 120,
|
|
46
|
+
});
|
|
117
47
|
/**
|
|
118
48
|
* Gets a 24-hour time formatter (e.g. 07:41 or 20:03) from cache
|
|
119
49
|
* or makes a new one if needed
|
|
@@ -132,7 +62,38 @@ function getFormatter(tzid) {
|
|
|
132
62
|
timeFormatCache.set(tzid, f);
|
|
133
63
|
return f;
|
|
134
64
|
}
|
|
135
|
-
|
|
65
|
+
function initClassicCities() {
|
|
66
|
+
for (const entry of citiesJson) {
|
|
67
|
+
const [cityName, cc, lat, lng, tzid, elev] = entry.split('|');
|
|
68
|
+
const location = new Location(+lat, +lng, cc === 'IL', tzid, cityName, cc, undefined, +elev);
|
|
69
|
+
Location.addLocation(cityName, location);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Class representing a geographic location for use with candle-lighting,
|
|
74
|
+
* havdalah, and zmanim calculations.
|
|
75
|
+
*
|
|
76
|
+
* Extends {@link GeoLocation} from `@hebcal/noaa` with Jewish-calendar
|
|
77
|
+
* specific data: an Israel/Diaspora flag, ISO country code, and an optional
|
|
78
|
+
* geographic identifier. Also provides {@link Location.lookup} for ~60
|
|
79
|
+
* built-in "classic" Hebcal cities.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* import {Location} from '@hebcal/core';
|
|
83
|
+
*
|
|
84
|
+
* // Create a location for a custom address
|
|
85
|
+
* const loc = new Location(
|
|
86
|
+
* 41.85003, // latitude
|
|
87
|
+
* -87.65005, // longitude
|
|
88
|
+
* false, // not in Israel
|
|
89
|
+
* 'America/Chicago',
|
|
90
|
+
* 'Chicago, Illinois, USA',
|
|
91
|
+
* 'US'
|
|
92
|
+
* );
|
|
93
|
+
*
|
|
94
|
+
* // Or look up a built-in classic city
|
|
95
|
+
* const tlv = Location.lookup('Tel Aviv');
|
|
96
|
+
*/
|
|
136
97
|
class Location extends GeoLocation {
|
|
137
98
|
il;
|
|
138
99
|
cc;
|
|
@@ -175,14 +136,31 @@ class Location extends GeoLocation {
|
|
|
175
136
|
this.cc = countryCode;
|
|
176
137
|
this.geoid = geoid;
|
|
177
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Returns `true` if this location is in Israel (uses the Israeli holiday
|
|
141
|
+
* and Torah-reading schedule), `false` for the Diaspora.
|
|
142
|
+
*/
|
|
178
143
|
getIsrael() {
|
|
179
144
|
return this.il;
|
|
180
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Returns the full descriptive location name passed to the constructor,
|
|
148
|
+
* or `null` if no name was provided.
|
|
149
|
+
* @example
|
|
150
|
+
* Location.lookup('San Francisco')?.getName(); // 'San Francisco, California, USA'
|
|
151
|
+
*/
|
|
181
152
|
getName() {
|
|
182
153
|
return this.getLocationName();
|
|
183
154
|
}
|
|
184
155
|
/**
|
|
185
|
-
* Returns the location name
|
|
156
|
+
* Returns the location name truncated at the first comma. Useful for
|
|
157
|
+
* compact display where only the city name is desired.
|
|
158
|
+
*
|
|
159
|
+
* Special-cased so that US locations of the form `"Washington, DC"` or
|
|
160
|
+
* `"Washington, D.C., ..."` keep the `DC` / `D.C.` suffix attached.
|
|
161
|
+
* @example
|
|
162
|
+
* Location.lookup('San Francisco')?.getShortName(); // 'San Francisco'
|
|
163
|
+
* Location.lookup('Washington DC')?.getShortName(); // 'Washington, DC'
|
|
186
164
|
*/
|
|
187
165
|
getShortName() {
|
|
188
166
|
const name = this.getLocationName();
|
|
@@ -201,18 +179,37 @@ class Location extends GeoLocation {
|
|
|
201
179
|
}
|
|
202
180
|
return name.substring(0, comma);
|
|
203
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Returns the ISO 3166 alpha-2 country code (e.g. `"US"`, `"IL"`, `"FR"`)
|
|
184
|
+
* passed to the constructor, or `undefined` if none was provided.
|
|
185
|
+
*/
|
|
204
186
|
getCountryCode() {
|
|
205
187
|
return this.cc;
|
|
206
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* Returns the Olson timezone identifier (e.g. `"America/Chicago"`).
|
|
191
|
+
* Alias for `getTimeZone()` from the parent `GeoLocation` class.
|
|
192
|
+
*/
|
|
207
193
|
getTzid() {
|
|
208
194
|
return this.getTimeZone();
|
|
209
195
|
}
|
|
210
196
|
/**
|
|
211
|
-
*
|
|
197
|
+
* Returns a cached 24-hour `Intl.DateTimeFormat` (e.g. `07:41` or `20:03`)
|
|
198
|
+
* configured for this location's timezone. Formatters are memoized by
|
|
199
|
+
* timezone so repeated calls do not allocate.
|
|
200
|
+
* @example
|
|
201
|
+
* const loc = Location.lookup('Tel Aviv')!;
|
|
202
|
+
* const fmt = loc.getTimeFormatter();
|
|
203
|
+
* fmt.format(new Date()); // e.g. '18:42'
|
|
212
204
|
*/
|
|
213
205
|
getTimeFormatter() {
|
|
214
206
|
return getFormatter(this.getTimeZone());
|
|
215
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Returns the optional geographic identifier passed to the constructor
|
|
210
|
+
* (typically a GeoNames numeric ID or a US Zip Code string), or
|
|
211
|
+
* `undefined` if none was provided.
|
|
212
|
+
*/
|
|
216
213
|
getGeoId() {
|
|
217
214
|
return this.geoid;
|
|
218
215
|
}
|
|
@@ -232,16 +229,38 @@ class Location extends GeoLocation {
|
|
|
232
229
|
* 'San Diego', 'San Francisco', 'Sao Paulo', 'Seattle', 'Sydney',
|
|
233
230
|
* 'Tel Aviv', 'Tiberias', 'Toronto', 'Vancouver', 'White Plains',
|
|
234
231
|
* 'Washington DC', 'Worcester'
|
|
235
|
-
*
|
|
232
|
+
*
|
|
233
|
+
* Lookups are case-insensitive. Returns `undefined` if the name is not
|
|
234
|
+
* recognized. The list can be extended with {@link Location.addLocation}.
|
|
235
|
+
* @example
|
|
236
|
+
* const loc = Location.lookup('San Francisco');
|
|
237
|
+
* console.log(loc?.getTzid()); // 'America/Los_Angeles'
|
|
238
|
+
* @param name case-insensitive classic city name
|
|
236
239
|
*/
|
|
237
240
|
static lookup(name) {
|
|
241
|
+
if (classicCities.size === 0) {
|
|
242
|
+
initClassicCities();
|
|
243
|
+
}
|
|
238
244
|
return classicCities.get(name.toLowerCase());
|
|
239
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Returns a JSON-serialized representation of this Location.
|
|
248
|
+
* Useful for debugging and structured logging.
|
|
249
|
+
*/
|
|
240
250
|
toString() {
|
|
241
251
|
return JSON.stringify(this);
|
|
242
252
|
}
|
|
243
253
|
/**
|
|
244
|
-
* Converts legacy Hebcal timezone
|
|
254
|
+
* Converts a legacy Hebcal-style timezone (a numeric GMT offset plus a
|
|
255
|
+
* coarse DST region) to a standard IANA/Olson timezone ID.
|
|
256
|
+
*
|
|
257
|
+
* This exists to migrate data from older Hebcal versions that stored
|
|
258
|
+
* timezones as GMT offset + DST scheme rather than as a full tzid.
|
|
259
|
+
* @example
|
|
260
|
+
* Location.legacyTzToTzid(2, 'israel'); // 'Asia/Jerusalem'
|
|
261
|
+
* Location.legacyTzToTzid(0, 'eu'); // 'Europe/London'
|
|
262
|
+
* Location.legacyTzToTzid(0, 'none'); // 'UTC'
|
|
263
|
+
* Location.legacyTzToTzid(-5, 'none'); // 'Etc/GMT-5'
|
|
245
264
|
* @param tz integer, GMT offset in hours
|
|
246
265
|
* @param dst 'none', 'eu', 'usa', or 'israel'
|
|
247
266
|
*/
|
|
@@ -299,9 +318,18 @@ class Location extends GeoLocation {
|
|
|
299
318
|
}
|
|
300
319
|
}
|
|
301
320
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
*
|
|
321
|
+
* Registers a new named location with the built-in `Location.lookup()`
|
|
322
|
+
* registry. Names are stored case-insensitively. Returns `false` if a
|
|
323
|
+
* location with the same (lower-cased) name is already registered, and
|
|
324
|
+
* `true` if successfully added.
|
|
325
|
+
*
|
|
326
|
+
* Use this to extend the built-in set of ~60 classic Hebcal cities with
|
|
327
|
+
* your own custom locations.
|
|
328
|
+
* @example
|
|
329
|
+
* const tlv = new Location(32.0853, 34.7818, true,
|
|
330
|
+
* 'Asia/Tel_Aviv', 'My Office, Tel Aviv', 'IL');
|
|
331
|
+
* Location.addLocation('My Office', tlv); // true
|
|
332
|
+
* Location.lookup('my office')?.getTzid(); // 'Asia/Tel_Aviv'
|
|
305
333
|
*/
|
|
306
334
|
static addLocation(cityName, location) {
|
|
307
335
|
const name = cityName.toLowerCase();
|
|
@@ -312,10 +340,6 @@ class Location extends GeoLocation {
|
|
|
312
340
|
return true;
|
|
313
341
|
}
|
|
314
342
|
}
|
|
315
|
-
for (const city of classicCities0) {
|
|
316
|
-
const location = new Location(city[2], city[3], city[1] === 'IL', city[4], city[0], city[1], undefined, city[5]);
|
|
317
|
-
Location.addLocation(city[0], location);
|
|
318
|
-
}
|
|
319
343
|
|
|
320
344
|
export { Location };
|
|
321
345
|
//# sourceMappingURL=location.js.map
|
package/dist/esm/location.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"location.js","sources":["../../../src/location.ts"],"sourcesContent":["/*\n Hebcal - A Jewish Calendar Generator\n Copyright (c) 1994-2020 Danny Sadinoff\n Portions copyright Eyal Schachter and Michael J. Radwin\n\n https://github.com/hebcal/hebcal-es6\n\n This program is free software; you can redistribute it and/or\n modify it under the terms of the GNU General Public License\n as published by the Free Software Foundation; either version 2\n of the License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport {GeoLocation} from '@hebcal/noaa';\n\nconst classicCities0: [string, string, number, number, string, number][] = [\n ['Ashdod', 'IL', 31.79213, 34.64966, 'Asia/Jerusalem', 27],\n ['Atlanta', 'US', 33.749, -84.38798, 'America/New_York', 336],\n ['Austin', 'US', 30.26715, -97.74306, 'America/Chicago', 165],\n ['Baghdad', 'IQ', 33.34058, 44.40088, 'Asia/Baghdad', 41],\n ['Beer Sheva', 'IL', 31.25181, 34.7913, 'Asia/Jerusalem', 285],\n ['Berlin', 'DE', 52.52437, 13.41053, 'Europe/Berlin', 43],\n ['Baltimore', 'US', 39.29038, -76.61219, 'America/New_York', 35],\n ['Bogota', 'CO', 4.60971, -74.08175, 'America/Bogota', 2582],\n ['Boston', 'US', 42.35843, -71.05977, 'America/New_York', 38],\n ['Budapest', 'HU', 47.49801, 19.03991, 'Europe/Budapest', 104],\n [\n 'Buenos Aires',\n 'AR',\n -34.61315,\n -58.37723,\n 'America/Argentina/Buenos_Aires',\n 31,\n ],\n ['Buffalo', 'US', 42.88645, -78.87837, 'America/New_York', 191],\n ['Chicago', 'US', 41.85003, -87.65005, 'America/Chicago', 180],\n ['Cincinnati', 'US', 39.162, -84.45689, 'America/New_York', 267],\n ['Cleveland', 'US', 41.4995, -81.69541, 'America/New_York', 204],\n ['Dallas', 'US', 32.78306, -96.80667, 'America/Chicago', 139],\n ['Denver', 'US', 39.73915, -104.9847, 'America/Denver', 1636],\n ['Detroit', 'US', 42.33143, -83.04575, 'America/Detroit', 192],\n ['Eilat', 'IL', 29.55805, 34.94821, 'Asia/Jerusalem', 63],\n ['Gibraltar', 'GI', 36.14474, -5.35257, 'Europe/Gibraltar', 11],\n ['Haifa', 'IL', 32.81841, 34.9885, 'Asia/Jerusalem', 40],\n ['Hawaii', 'US', 21.30694, -157.85833, 'Pacific/Honolulu', 18],\n ['Helsinki', 'FI', 60.16952, 24.93545, 'Europe/Helsinki', 26],\n ['Houston', 'US', 29.76328, -95.36327, 'America/Chicago', 30],\n ['Jerusalem', 'IL', 31.76904, 35.21633, 'Asia/Jerusalem', 786],\n ['Johannesburg', 'ZA', -26.20227, 28.04363, 'Africa/Johannesburg', 1767],\n ['Kiev', 'UA', 50.45466, 30.5238, 'Europe/Kiev', 187],\n ['La Paz', 'BO', -16.5, -68.15, 'America/La_Paz', 3782],\n ['Livingston', 'US', 40.79593, -74.31487, 'America/New_York', 98],\n ['Las Vegas', 'US', 36.17497, -115.13722, 'America/Los_Angeles', 613],\n ['London', 'GB', 51.50853, -0.12574, 'Europe/London', 25],\n ['Los Angeles', 'US', 34.05223, -118.24368, 'America/Los_Angeles', 96],\n ['Marseilles', 'FR', 43.29695, 5.38107, 'Europe/Paris', 28],\n ['Miami', 'US', 25.77427, -80.19366, 'America/New_York', 25],\n ['Minneapolis', 'US', 44.97997, -93.26384, 'America/Chicago', 262],\n ['Melbourne', 'AU', -37.814, 144.96332, 'Australia/Melbourne', 25],\n ['Mexico City', 'MX', 19.42847, -99.12766, 'America/Mexico_City', 2240],\n ['Montreal', 'CA', 45.50884, -73.58781, 'America/Toronto', 216],\n ['Moscow', 'RU', 55.75222, 37.61556, 'Europe/Moscow', 144],\n ['New York', 'US', 40.71427, -74.00597, 'America/New_York', 57],\n ['Omaha', 'US', 41.25861, -95.93779, 'America/Chicago', 315],\n ['Ottawa', 'CA', 45.41117, -75.69812, 'America/Toronto', 71],\n ['Panama City', 'PA', 8.9936, -79.51973, 'America/Panama', 17],\n ['Paris', 'FR', 48.85341, 2.3488, 'Europe/Paris', 42],\n ['Pawtucket', 'US', 41.87871, -71.38256, 'America/New_York', 0], // -11\n ['Petach Tikvah', 'IL', 32.08707, 34.88747, 'Asia/Jerusalem', 54],\n ['Philadelphia', 'US', 39.95233, -75.16379, 'America/New_York', 8],\n ['Phoenix', 'US', 33.44838, -112.07404, 'America/Phoenix', 366],\n ['Pittsburgh', 'US', 40.44062, -79.99589, 'America/New_York', 239],\n ['Providence', 'US', 41.82399, -71.41283, 'America/New_York', 0], // -15\n ['Portland', 'US', 45.52345, -122.67621, 'America/Los_Angeles', 15],\n ['Saint Louis', 'US', 38.62727, -90.19789, 'America/Chicago', 149],\n ['Saint Petersburg', 'RU', 59.93863, 30.31413, 'Europe/Moscow', 11],\n ['San Diego', 'US', 32.71533, -117.15726, 'America/Los_Angeles', 20],\n ['San Francisco', 'US', 37.77493, -122.41942, 'America/Los_Angeles', 28],\n ['Sao Paulo', 'BR', -23.5475, -46.63611, 'America/Sao_Paulo', 769],\n ['Seattle', 'US', 47.60621, -122.33207, 'America/Los_Angeles', 56],\n ['Sydney', 'AU', -33.86785, 151.20732, 'Australia/Sydney', 58],\n ['Tel Aviv', 'IL', 32.08088, 34.78057, 'Asia/Jerusalem', 15],\n ['Tiberias', 'IL', 32.79221, 35.53124, 'Asia/Jerusalem', 0], // -140\n ['Toronto', 'CA', 43.70011, -79.4163, 'America/Toronto', 175],\n ['Vancouver', 'CA', 49.24966, -123.11934, 'America/Vancouver', 70],\n ['White Plains', 'US', 41.03399, -73.76291, 'America/New_York', 82],\n ['Washington DC', 'US', 38.89511, -77.03637, 'America/New_York', 6],\n ['Worcester', 'US', 42.26259, -71.80229, 'America/New_York', 164],\n];\nconst classicCities = new Map<string, Location>();\n\n// Zip-Codes.com TimeZone IDs\nconst ZIPCODES_TZ_MAP: Record<string, string> = {\n '0': 'UTC',\n '4': 'America/Puerto_Rico', // Atlantic (GMT -04:00)\n '5': 'America/New_York', // Eastern (GMT -05:00)\n '6': 'America/Chicago', // Central (GMT -06:00)\n '7': 'America/Denver', // Mountain (GMT -07:00)\n '8': 'America/Los_Angeles', // Pacific (GMT -08:00)\n '9': 'America/Anchorage', // Alaska (GMT -09:00)\n '10': 'Pacific/Honolulu', // Hawaii-Aleutian Islands (GMT -10:00)\n '11': 'Pacific/Pago_Pago', // American Samoa (GMT -11:00)\n '13': 'Pacific/Funafuti', // Marshall Islands (GMT +12:00)\n '14': 'Pacific/Guam', // Guam (GMT +10:00)\n '15': 'Pacific/Palau', // Palau (GMT +9:00)\n '16': 'Pacific/Chuuk', // Micronesia (GMT +11:00)\n} as const;\n\n/** @private */\nconst timeFormatCache = new Map<string, Intl.DateTimeFormat>();\n\n/**\n * Gets a 24-hour time formatter (e.g. 07:41 or 20:03) from cache\n * or makes a new one if needed\n * @private\n */\nfunction getFormatter(tzid: string): Intl.DateTimeFormat {\n const fmt = timeFormatCache.get(tzid);\n if (fmt) return fmt;\n const f = new Intl.DateTimeFormat('en-US', {\n timeZone: tzid,\n hour: 'numeric',\n minute: 'numeric',\n hour12: false,\n });\n timeFormatCache.set(tzid, f);\n return f;\n}\n\n/** Class representing Location */\nexport class Location extends GeoLocation {\n private readonly il: boolean;\n private readonly cc?: string;\n private readonly geoid?: string | number;\n admin1?: string;\n stateName?: string;\n geo?: 'zip' | 'geoname';\n zip?: string;\n population?: number;\n asciiname?: string;\n\n /**\n * Initialize a Location instance\n * @param latitude - Latitude as a decimal, valid range -90 thru +90 (e.g. 41.85003)\n * @param longitude - Longitude as a decimal, valid range -180 thru +180 (e.g. -87.65005)\n * @param il - in Israel (true) or Diaspora (false)\n * @param tzid - Olson timezone ID, e.g. \"America/Chicago\"\n * @param [cityName] - optional descriptive city name\n * @param [countryCode] - ISO 3166 alpha-2 country code (e.g. \"FR\")\n * @param [geoid] - optional string or numeric geographic ID\n * @param [elevation] - in meters (default `0`)\n */\n constructor(\n latitude: number,\n longitude: number,\n il: boolean,\n tzid: string,\n cityName?: string,\n countryCode?: string,\n geoid?: string | number,\n elevation?: number\n ) {\n const lat = typeof latitude === 'number' ? latitude : parseFloat(latitude);\n if (isNaN(lat) || lat < -90 || lat > 90) {\n throw new RangeError(`Latitude ${latitude} out of range [-90,90]`);\n }\n const long =\n typeof longitude === 'number' ? longitude : parseFloat(longitude);\n if (isNaN(long) || long < -180 || long > 180) {\n throw new RangeError(`Longitude ${longitude} out of range [-180,180]`);\n }\n if (!tzid) {\n throw new RangeError('Invalid timezone');\n }\n const elev = typeof elevation === 'number' && elevation > 0 ? elevation : 0;\n if (cityName && typeof cityName !== 'string') {\n cityName = String(cityName);\n }\n super(cityName || null, lat, long, elev, tzid);\n this.il = Boolean(il);\n this.cc = countryCode;\n this.geoid = geoid;\n }\n\n getIsrael(): boolean {\n return this.il;\n }\n\n getName(): string | null {\n return this.getLocationName();\n }\n\n /**\n * Returns the location name, up to the first comma\n */\n getShortName(): string | null {\n const name = this.getLocationName();\n if (!name) return name;\n const comma = name.indexOf(', ');\n if (comma === -1) return name;\n if (this.cc === 'US' && name[comma + 2] === 'D') {\n if (name[comma + 3] === 'C') {\n return name.substring(0, comma + 4);\n } else if (name[comma + 3] === '.' && name[comma + 4] === 'C') {\n return name.substring(0, comma + 6);\n }\n }\n return name.substring(0, comma);\n }\n\n getCountryCode(): string | undefined {\n return this.cc;\n }\n\n getTzid(): string {\n return this.getTimeZone();\n }\n\n /**\n * Gets a 24-hour time formatter (e.g. 07:41 or 20:03) for this location\n */\n getTimeFormatter(): Intl.DateTimeFormat {\n return getFormatter(this.getTimeZone());\n }\n\n getGeoId(): string | number | undefined {\n return this.geoid;\n }\n\n /**\n * Creates a location object from one of 60 \"classic\" Hebcal city names.\n * The following city names are supported:\n * 'Ashdod', 'Atlanta', 'Austin', 'Baghdad', 'Beer Sheva',\n * 'Berlin', 'Baltimore', 'Bogota', 'Boston', 'Budapest',\n * 'Buenos Aires', 'Buffalo', 'Chicago', 'Cincinnati', 'Cleveland',\n * 'Dallas', 'Denver', 'Detroit', 'Eilat', 'Gibraltar', 'Haifa',\n * 'Hawaii', 'Helsinki', 'Houston', 'Jerusalem', 'Johannesburg',\n * 'Kiev', 'La Paz', 'Livingston', 'Las Vegas', 'London', 'Los Angeles',\n * 'Marseilles', 'Miami', 'Minneapolis', 'Melbourne', 'Mexico City',\n * 'Montreal', 'Moscow', 'New York', 'Omaha', 'Ottawa', 'Panama City',\n * 'Paris', 'Pawtucket', 'Petach Tikvah', 'Philadelphia', 'Phoenix',\n * 'Pittsburgh', 'Providence', 'Portland', 'Saint Louis', 'Saint Petersburg',\n * 'San Diego', 'San Francisco', 'Sao Paulo', 'Seattle', 'Sydney',\n * 'Tel Aviv', 'Tiberias', 'Toronto', 'Vancouver', 'White Plains',\n * 'Washington DC', 'Worcester'\n * @param name\n */\n static lookup(name: string): Location | undefined {\n return classicCities.get(name.toLowerCase());\n }\n\n toString(): string {\n return JSON.stringify(this);\n }\n\n /**\n * Converts legacy Hebcal timezone to a standard Olson tzid.\n * @param tz integer, GMT offset in hours\n * @param dst 'none', 'eu', 'usa', or 'israel'\n */\n static legacyTzToTzid(tz: number, dst: string): string | undefined {\n tz = +tz;\n if (dst === 'none') {\n if (tz === 0) {\n return 'UTC';\n } else {\n const plus = tz > 0 ? '+' : '';\n return `Etc/GMT${plus}${tz}`;\n }\n } else if (tz === 2 && dst === 'israel') {\n return 'Asia/Jerusalem';\n } else if (dst === 'eu') {\n switch (tz) {\n case -2:\n return 'Atlantic/Cape_Verde';\n case -1:\n return 'Atlantic/Azores';\n case 0:\n return 'Europe/London';\n case 1:\n return 'Europe/Paris';\n case 2:\n return 'Europe/Athens';\n default:\n break;\n }\n } else if (dst === 'usa') {\n return ZIPCODES_TZ_MAP[String(tz * -1)];\n }\n return undefined;\n }\n\n /**\n * Converts timezone info from Zip-Codes.com to a standard Olson tzid.\n * @example\n * Location.getUsaTzid('AZ', 7, 'Y') // 'America/Denver'\n * @param state two-letter all-caps US state abbreviation like 'CA'\n * @param tz positive number, 5=America/New_York, 8=America/Los_Angeles\n * @param dst single char 'Y' or 'N'\n */\n static getUsaTzid(state: string, tz: number, dst: string): string {\n tz = +tz;\n if (tz === 10 && state === 'AK') {\n return 'America/Adak';\n } else if (tz === 7 && state === 'AZ') {\n return dst === 'Y' ? 'America/Denver' : 'America/Phoenix';\n } else {\n return ZIPCODES_TZ_MAP[tz];\n }\n }\n\n /**\n * Adds a location name for `Location.lookup()` only if the name isn't\n * already being used. Returns `false` if the name is already taken\n * and `true` if successfully added.\n */\n static addLocation(cityName: string, location: Location): boolean {\n const name = cityName.toLowerCase();\n if (classicCities.has(name)) {\n return false;\n }\n classicCities.set(name, location);\n return true;\n }\n}\n\nfor (const city of classicCities0) {\n const location = new Location(\n city[2],\n city[3],\n city[1] === 'IL',\n city[4],\n city[0],\n city[1],\n undefined,\n city[5]\n );\n Location.addLocation(city[0], location);\n}\n"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;AAmBG;AAGH,MAAM,cAAc,GAAuD;IACzE,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,EAAE,CAAC;AAC1D,IAAA,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,CAAC;AAC7D,IAAA,CAAC,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS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I,CAAC,EAAE;AAC3B,YAAA,OAAO,KAAK;QACd;AACA,QAAA,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;AACjC,QAAA,OAAO,IAAI;IACb;AACD;AAED,KAAK,MAAM,IAAI,IAAI,cAAc,EAAE;IACjC,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAC3B,IAAI,CAAC,CAAC,CAAC,EACP,IAAI,CAAC,CAAC,CAAC,EACP,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,EAChB,IAAI,CAAC,CAAC,CAAC,EACP,IAAI,CAAC,CAAC,CAAC,EACP,IAAI,CAAC,CAAC,CAAC,EACP,SAAS,EACT,IAAI,CAAC,CAAC,CAAC,CACR;IACD,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC;AACzC;;;;"}
|
|
1
|
+
{"version":3,"file":"location.js","sources":["../../../src/location.ts"],"sourcesContent":["/*\n Hebcal - A Jewish Calendar Generator\n Copyright (c) 1994-2020 Danny Sadinoff\n Portions copyright Eyal Schachter and Michael J. Radwin\n\n https://github.com/hebcal/hebcal-es6\n\n This program is free software; you can redistribute it and/or\n modify it under the terms of the GNU General Public License\n as published by the Free Software Foundation; either version 2\n of the License, or (at your option) any later version.\n\n This program is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU General Public License for more details.\n\n You should have received a copy of the GNU General Public License\n along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\nimport {GeoLocation} from '@hebcal/noaa';\nimport citiesJson from './cities.json';\nimport QuickLRU from 'quick-lru';\n\nconst classicCities = new Map<string, Location>();\n\n// Zip-Codes.com TimeZone IDs\nconst ZIPCODES_TZ_MAP: Record<string, string> = {\n '0': 'UTC',\n '4': 'America/Puerto_Rico', // Atlantic (GMT -04:00)\n '5': 'America/New_York', // Eastern (GMT -05:00)\n '6': 'America/Chicago', // Central (GMT -06:00)\n '7': 'America/Denver', // Mountain (GMT -07:00)\n '8': 'America/Los_Angeles', // Pacific (GMT -08:00)\n '9': 'America/Anchorage', // Alaska (GMT -09:00)\n '10': 'Pacific/Honolulu', // Hawaii-Aleutian Islands (GMT -10:00)\n '11': 'Pacific/Pago_Pago', // American Samoa (GMT -11:00)\n '13': 'Pacific/Funafuti', // Marshall Islands (GMT +12:00)\n '14': 'Pacific/Guam', // Guam (GMT +10:00)\n '15': 'Pacific/Palau', // Palau (GMT +9:00)\n '16': 'Pacific/Chuuk', // Micronesia (GMT +11:00)\n} as const;\n\n/** @private */\nconst timeFormatCache = new QuickLRU<string, Intl.DateTimeFormat>({\n maxSize: 120,\n});\n\n/**\n * Gets a 24-hour time formatter (e.g. 07:41 or 20:03) from cache\n * or makes a new one if needed\n * @private\n */\nfunction getFormatter(tzid: string): Intl.DateTimeFormat {\n const fmt = timeFormatCache.get(tzid);\n if (fmt) return fmt;\n const f = new Intl.DateTimeFormat('en-US', {\n timeZone: tzid,\n hour: 'numeric',\n minute: 'numeric',\n hour12: false,\n });\n timeFormatCache.set(tzid, f);\n return f;\n}\n\nfunction initClassicCities() {\n for (const entry of citiesJson) {\n const [cityName, cc, lat, lng, tzid, elev] = entry.split('|');\n const location = new Location(\n +lat,\n +lng,\n cc === 'IL',\n tzid,\n cityName,\n cc,\n undefined,\n +elev\n );\n Location.addLocation(cityName, location);\n }\n}\n\n/**\n * Class representing a geographic location for use with candle-lighting,\n * havdalah, and zmanim calculations.\n *\n * Extends {@link GeoLocation} from `@hebcal/noaa` with Jewish-calendar\n * specific data: an Israel/Diaspora flag, ISO country code, and an optional\n * geographic identifier. Also provides {@link Location.lookup} for ~60\n * built-in \"classic\" Hebcal cities.\n *\n * @example\n * import {Location} from '@hebcal/core';\n *\n * // Create a location for a custom address\n * const loc = new Location(\n * 41.85003, // latitude\n * -87.65005, // longitude\n * false, // not in Israel\n * 'America/Chicago',\n * 'Chicago, Illinois, USA',\n * 'US'\n * );\n *\n * // Or look up a built-in classic city\n * const tlv = Location.lookup('Tel Aviv');\n */\nexport class Location extends GeoLocation {\n private readonly il: boolean;\n private readonly cc?: string;\n private readonly geoid?: string | number;\n admin1?: string;\n stateName?: string;\n geo?: 'zip' | 'geoname';\n zip?: string;\n population?: number;\n asciiname?: string;\n\n /**\n * Initialize a Location instance\n * @param latitude - Latitude as a decimal, valid range -90 thru +90 (e.g. 41.85003)\n * @param longitude - Longitude as a decimal, valid range -180 thru +180 (e.g. -87.65005)\n * @param il - in Israel (true) or Diaspora (false)\n * @param tzid - Olson timezone ID, e.g. \"America/Chicago\"\n * @param [cityName] - optional descriptive city name\n * @param [countryCode] - ISO 3166 alpha-2 country code (e.g. \"FR\")\n * @param [geoid] - optional string or numeric geographic ID\n * @param [elevation] - in meters (default `0`)\n */\n constructor(\n latitude: number,\n longitude: number,\n il: boolean,\n tzid: string,\n cityName?: string,\n countryCode?: string,\n geoid?: string | number,\n elevation?: number\n ) {\n const lat = typeof latitude === 'number' ? latitude : parseFloat(latitude);\n if (isNaN(lat) || lat < -90 || lat > 90) {\n throw new RangeError(`Latitude ${latitude} out of range [-90,90]`);\n }\n const long =\n typeof longitude === 'number' ? longitude : parseFloat(longitude);\n if (isNaN(long) || long < -180 || long > 180) {\n throw new RangeError(`Longitude ${longitude} out of range [-180,180]`);\n }\n if (!tzid) {\n throw new RangeError('Invalid timezone');\n }\n const elev = typeof elevation === 'number' && elevation > 0 ? elevation : 0;\n if (cityName && typeof cityName !== 'string') {\n cityName = String(cityName);\n }\n super(cityName || null, lat, long, elev, tzid);\n this.il = Boolean(il);\n this.cc = countryCode;\n this.geoid = geoid;\n }\n\n /**\n * Returns `true` if this location is in Israel (uses the Israeli holiday\n * and Torah-reading schedule), `false` for the Diaspora.\n */\n getIsrael(): boolean {\n return this.il;\n }\n\n /**\n * Returns the full descriptive location name passed to the constructor,\n * or `null` if no name was provided.\n * @example\n * Location.lookup('San Francisco')?.getName(); // 'San Francisco, California, USA'\n */\n getName(): string | null {\n return this.getLocationName();\n }\n\n /**\n * Returns the location name truncated at the first comma. Useful for\n * compact display where only the city name is desired.\n *\n * Special-cased so that US locations of the form `\"Washington, DC\"` or\n * `\"Washington, D.C., ...\"` keep the `DC` / `D.C.` suffix attached.\n * @example\n * Location.lookup('San Francisco')?.getShortName(); // 'San Francisco'\n * Location.lookup('Washington DC')?.getShortName(); // 'Washington, DC'\n */\n getShortName(): string | null {\n const name = this.getLocationName();\n if (!name) return name;\n const comma = name.indexOf(', ');\n if (comma === -1) return name;\n if (this.cc === 'US' && name[comma + 2] === 'D') {\n if (name[comma + 3] === 'C') {\n return name.substring(0, comma + 4);\n } else if (name[comma + 3] === '.' && name[comma + 4] === 'C') {\n return name.substring(0, comma + 6);\n }\n }\n return name.substring(0, comma);\n }\n\n /**\n * Returns the ISO 3166 alpha-2 country code (e.g. `\"US\"`, `\"IL\"`, `\"FR\"`)\n * passed to the constructor, or `undefined` if none was provided.\n */\n getCountryCode(): string | undefined {\n return this.cc;\n }\n\n /**\n * Returns the Olson timezone identifier (e.g. `\"America/Chicago\"`).\n * Alias for `getTimeZone()` from the parent `GeoLocation` class.\n */\n getTzid(): string {\n return this.getTimeZone();\n }\n\n /**\n * Returns a cached 24-hour `Intl.DateTimeFormat` (e.g. `07:41` or `20:03`)\n * configured for this location's timezone. Formatters are memoized by\n * timezone so repeated calls do not allocate.\n * @example\n * const loc = Location.lookup('Tel Aviv')!;\n * const fmt = loc.getTimeFormatter();\n * fmt.format(new Date()); // e.g. '18:42'\n */\n getTimeFormatter(): Intl.DateTimeFormat {\n return getFormatter(this.getTimeZone());\n }\n\n /**\n * Returns the optional geographic identifier passed to the constructor\n * (typically a GeoNames numeric ID or a US Zip Code string), or\n * `undefined` if none was provided.\n */\n getGeoId(): string | number | undefined {\n return this.geoid;\n }\n\n /**\n * Creates a location object from one of 60 \"classic\" Hebcal city names.\n * The following city names are supported:\n * 'Ashdod', 'Atlanta', 'Austin', 'Baghdad', 'Beer Sheva',\n * 'Berlin', 'Baltimore', 'Bogota', 'Boston', 'Budapest',\n * 'Buenos Aires', 'Buffalo', 'Chicago', 'Cincinnati', 'Cleveland',\n * 'Dallas', 'Denver', 'Detroit', 'Eilat', 'Gibraltar', 'Haifa',\n * 'Hawaii', 'Helsinki', 'Houston', 'Jerusalem', 'Johannesburg',\n * 'Kiev', 'La Paz', 'Livingston', 'Las Vegas', 'London', 'Los Angeles',\n * 'Marseilles', 'Miami', 'Minneapolis', 'Melbourne', 'Mexico City',\n * 'Montreal', 'Moscow', 'New York', 'Omaha', 'Ottawa', 'Panama City',\n * 'Paris', 'Pawtucket', 'Petach Tikvah', 'Philadelphia', 'Phoenix',\n * 'Pittsburgh', 'Providence', 'Portland', 'Saint Louis', 'Saint Petersburg',\n * 'San Diego', 'San Francisco', 'Sao Paulo', 'Seattle', 'Sydney',\n * 'Tel Aviv', 'Tiberias', 'Toronto', 'Vancouver', 'White Plains',\n * 'Washington DC', 'Worcester'\n *\n * Lookups are case-insensitive. Returns `undefined` if the name is not\n * recognized. The list can be extended with {@link Location.addLocation}.\n * @example\n * const loc = Location.lookup('San Francisco');\n * console.log(loc?.getTzid()); // 'America/Los_Angeles'\n * @param name case-insensitive classic city name\n */\n static lookup(name: string): Location | undefined {\n if (classicCities.size === 0) {\n initClassicCities();\n }\n return classicCities.get(name.toLowerCase());\n }\n\n /**\n * Returns a JSON-serialized representation of this Location.\n * Useful for debugging and structured logging.\n */\n toString(): string {\n return JSON.stringify(this);\n }\n\n /**\n * Converts a legacy Hebcal-style timezone (a numeric GMT offset plus a\n * coarse DST region) to a standard IANA/Olson timezone ID.\n *\n * This exists to migrate data from older Hebcal versions that stored\n * timezones as GMT offset + DST scheme rather than as a full tzid.\n * @example\n * Location.legacyTzToTzid(2, 'israel'); // 'Asia/Jerusalem'\n * Location.legacyTzToTzid(0, 'eu'); // 'Europe/London'\n * Location.legacyTzToTzid(0, 'none'); // 'UTC'\n * Location.legacyTzToTzid(-5, 'none'); // 'Etc/GMT-5'\n * @param tz integer, GMT offset in hours\n * @param dst 'none', 'eu', 'usa', or 'israel'\n */\n static legacyTzToTzid(tz: number, dst: string): string | undefined {\n tz = +tz;\n if (dst === 'none') {\n if (tz === 0) {\n return 'UTC';\n } else {\n const plus = tz > 0 ? '+' : '';\n return `Etc/GMT${plus}${tz}`;\n }\n } else if (tz === 2 && dst === 'israel') {\n return 'Asia/Jerusalem';\n } else if (dst === 'eu') {\n switch (tz) {\n case -2:\n return 'Atlantic/Cape_Verde';\n case -1:\n return 'Atlantic/Azores';\n case 0:\n return 'Europe/London';\n case 1:\n return 'Europe/Paris';\n case 2:\n return 'Europe/Athens';\n default:\n break;\n }\n } else if (dst === 'usa') {\n return ZIPCODES_TZ_MAP[String(tz * -1)];\n }\n return undefined;\n }\n\n /**\n * Converts timezone info from Zip-Codes.com to a standard Olson tzid.\n * @example\n * Location.getUsaTzid('AZ', 7, 'Y') // 'America/Denver'\n * @param state two-letter all-caps US state abbreviation like 'CA'\n * @param tz positive number, 5=America/New_York, 8=America/Los_Angeles\n * @param dst single char 'Y' or 'N'\n */\n static getUsaTzid(state: string, tz: number, dst: string): string {\n tz = +tz;\n if (tz === 10 && state === 'AK') {\n return 'America/Adak';\n } else if (tz === 7 && state === 'AZ') {\n return dst === 'Y' ? 'America/Denver' : 'America/Phoenix';\n } else {\n return ZIPCODES_TZ_MAP[tz];\n }\n }\n\n /**\n * Registers a new named location with the built-in `Location.lookup()`\n * registry. Names are stored case-insensitively. Returns `false` if a\n * location with the same (lower-cased) name is already registered, and\n * `true` if successfully added.\n *\n * Use this to extend the built-in set of ~60 classic Hebcal cities with\n * your own custom locations.\n * @example\n * const tlv = new Location(32.0853, 34.7818, true,\n * 'Asia/Tel_Aviv', 'My Office, Tel Aviv', 'IL');\n * Location.addLocation('My Office', tlv); // true\n * Location.lookup('my office')?.getTzid(); // 'Asia/Tel_Aviv'\n */\n static addLocation(cityName: string, location: Location): boolean {\n const name = cityName.toLowerCase();\n if (classicCities.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K;QACd;AACA,QAAA,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC;AACjC,QAAA,OAAO,IAAI;IACb;AACD;;;;"}
|
package/dist/esm/modern.js
CHANGED
package/dist/esm/molad.d.ts
CHANGED
|
@@ -4,7 +4,20 @@ import { CalOptions } from './CalOptions';
|
|
|
4
4
|
import { HDate } from '@hebcal/hdate';
|
|
5
5
|
import './locale';
|
|
6
6
|
/**
|
|
7
|
-
* Represents a molad
|
|
7
|
+
* Represents a *molad* — the calculated moment when the new moon is "born"
|
|
8
|
+
* for a given Hebrew month.
|
|
9
|
+
*
|
|
10
|
+
* The molad is announced in synagogue on Shabbat Mevarchim (the Shabbat
|
|
11
|
+
* before Rosh Chodesh) and is the anchor point for Kiddush Levana zmanim.
|
|
12
|
+
* Calculations use the traditional chalakim arithmetic
|
|
13
|
+
* (1 hour = 1080 chalakim) anchored to *Molad Tohu BaHaRaD*.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* import {Molad, months} from '@hebcal/core';
|
|
17
|
+
* const m = new Molad(5784, months.NISAN);
|
|
18
|
+
* console.log(m.getMonthName()); // 'Nisan'
|
|
19
|
+
* console.log(m.getHour(), m.getMinutes(), m.getChalakim()); // e.g. 1 31 12
|
|
20
|
+
* console.log(m.render('en')); // 'Molad Nisan: Mon, 1:31am and 12 chalakim'
|
|
8
21
|
*/
|
|
9
22
|
export declare class Molad {
|
|
10
23
|
private readonly m;
|
|
@@ -12,9 +25,9 @@ export declare class Molad {
|
|
|
12
25
|
private readonly month;
|
|
13
26
|
private instant?;
|
|
14
27
|
/**
|
|
15
|
-
* Calculates the molad for a Hebrew month
|
|
16
|
-
* @param year
|
|
17
|
-
* @param month 1=
|
|
28
|
+
* Calculates the molad for a given Hebrew year and month.
|
|
29
|
+
* @param year Hebrew year
|
|
30
|
+
* @param month 1=NISAN, 7=TISHREI (uses Nisan-based numbering)
|
|
18
31
|
*/
|
|
19
32
|
constructor(year: number, month: number);
|
|
20
33
|
/**
|
|
@@ -56,12 +69,18 @@ export declare class Molad {
|
|
|
56
69
|
*/
|
|
57
70
|
getChalakim(): number;
|
|
58
71
|
/**
|
|
59
|
-
* Returns the molad in Standard Time in Yerushalayim as a Temporal.ZonedDateTime
|
|
72
|
+
* Returns the molad in Standard Time in Yerushalayim as a `Temporal.ZonedDateTime`.
|
|
60
73
|
* This method subtracts 20.94 minutes (20 minutes and 56.496 seconds) from the computed time (Har Habayis with a longitude
|
|
61
74
|
* of 35.2354° is 5.2354° away from the %15 timezone longitude) to get to standard time. This method
|
|
62
75
|
* intentionally uses standard time and not daylight savings time.
|
|
63
76
|
*
|
|
64
|
-
*
|
|
77
|
+
* The returned value is cached after the first call.
|
|
78
|
+
* @example
|
|
79
|
+
* import {Molad, months} from '@hebcal/core';
|
|
80
|
+
* const m = new Molad(5784, months.NISAN);
|
|
81
|
+
* const zdt = m.getInstant();
|
|
82
|
+
* console.log(zdt.toString()); // e.g. '2024-04-08T17:21:13.333+00:00[UTC]'
|
|
83
|
+
* @return the `Temporal.ZonedDateTime` representing the moment of the molad
|
|
65
84
|
*/
|
|
66
85
|
getInstant(): Temporal.ZonedDateTime;
|
|
67
86
|
/**
|
|
@@ -109,8 +128,21 @@ export declare class Molad {
|
|
|
109
128
|
*/
|
|
110
129
|
getSofZmanKidushLevana15Days(): Temporal.ZonedDateTime;
|
|
111
130
|
/**
|
|
131
|
+
* Returns a human-readable, localized string announcing the molad —
|
|
132
|
+
* suitable for use on Shabbat Mevarchim. The format includes the Hebrew
|
|
133
|
+
* month name, day of week, hour : minute, and chalakim if non-zero.
|
|
134
|
+
*
|
|
135
|
+
* Time format honors `options.hour12` and `options.location` (12-hour vs.
|
|
136
|
+
* 24-hour); see {@link HebrewCalendar.reformatTimeStr}.
|
|
137
|
+
* @example
|
|
138
|
+
* import {Molad, months} from '@hebcal/core';
|
|
139
|
+
* const m = new Molad(5784, months.NISAN);
|
|
140
|
+
* m.render('en', {hour12: true});
|
|
141
|
+
* // => 'Molad Nisan: Mon, 7:21pm and 6 chalakim'
|
|
142
|
+
* m.render('he');
|
|
143
|
+
* // => 'מוֹלָד נִיסָן יִהְיֶה בַּיּוֹם שֵׁנִי בשָׁבוּעַ, …'
|
|
112
144
|
* @param [locale] Optional locale name (defaults to empty locale)
|
|
113
|
-
* @param options
|
|
145
|
+
* @param options used for time formatting (12-hour vs 24-hour)
|
|
114
146
|
*/
|
|
115
147
|
render(locale?: string, options?: CalOptions): string;
|
|
116
148
|
}
|
package/dist/esm/molad.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! @hebcal/core v6.5.
|
|
1
|
+
/*! @hebcal/core v6.5.2, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
|
|
2
2
|
import './temporal-shim.js';
|
|
3
3
|
import { Event, flags } from './event.js';
|
|
4
4
|
import { HDate, Locale, pad2 } from '@hebcal/hdate';
|
|
@@ -56,7 +56,20 @@ function getHebrewTimeOfDay(hour) {
|
|
|
56
56
|
return night;
|
|
57
57
|
}
|
|
58
58
|
/**
|
|
59
|
-
* Represents a molad
|
|
59
|
+
* Represents a *molad* — the calculated moment when the new moon is "born"
|
|
60
|
+
* for a given Hebrew month.
|
|
61
|
+
*
|
|
62
|
+
* The molad is announced in synagogue on Shabbat Mevarchim (the Shabbat
|
|
63
|
+
* before Rosh Chodesh) and is the anchor point for Kiddush Levana zmanim.
|
|
64
|
+
* Calculations use the traditional chalakim arithmetic
|
|
65
|
+
* (1 hour = 1080 chalakim) anchored to *Molad Tohu BaHaRaD*.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* import {Molad, months} from '@hebcal/core';
|
|
69
|
+
* const m = new Molad(5784, months.NISAN);
|
|
70
|
+
* console.log(m.getMonthName()); // 'Nisan'
|
|
71
|
+
* console.log(m.getHour(), m.getMinutes(), m.getChalakim()); // e.g. 1 31 12
|
|
72
|
+
* console.log(m.render('en')); // 'Molad Nisan: Mon, 1:31am and 12 chalakim'
|
|
60
73
|
*/
|
|
61
74
|
class Molad {
|
|
62
75
|
m;
|
|
@@ -64,9 +77,9 @@ class Molad {
|
|
|
64
77
|
month;
|
|
65
78
|
instant;
|
|
66
79
|
/**
|
|
67
|
-
* Calculates the molad for a Hebrew month
|
|
68
|
-
* @param year
|
|
69
|
-
* @param month 1=
|
|
80
|
+
* Calculates the molad for a given Hebrew year and month.
|
|
81
|
+
* @param year Hebrew year
|
|
82
|
+
* @param month 1=NISAN, 7=TISHREI (uses Nisan-based numbering)
|
|
70
83
|
*/
|
|
71
84
|
constructor(year, month) {
|
|
72
85
|
this.m = calculateMolad(year, month);
|
|
@@ -128,12 +141,18 @@ class Molad {
|
|
|
128
141
|
return this.m.chalakim;
|
|
129
142
|
}
|
|
130
143
|
/**
|
|
131
|
-
* Returns the molad in Standard Time in Yerushalayim as a Temporal.ZonedDateTime
|
|
144
|
+
* Returns the molad in Standard Time in Yerushalayim as a `Temporal.ZonedDateTime`.
|
|
132
145
|
* This method subtracts 20.94 minutes (20 minutes and 56.496 seconds) from the computed time (Har Habayis with a longitude
|
|
133
146
|
* of 35.2354° is 5.2354° away from the %15 timezone longitude) to get to standard time. This method
|
|
134
147
|
* intentionally uses standard time and not daylight savings time.
|
|
135
148
|
*
|
|
136
|
-
*
|
|
149
|
+
* The returned value is cached after the first call.
|
|
150
|
+
* @example
|
|
151
|
+
* import {Molad, months} from '@hebcal/core';
|
|
152
|
+
* const m = new Molad(5784, months.NISAN);
|
|
153
|
+
* const zdt = m.getInstant();
|
|
154
|
+
* console.log(zdt.toString()); // e.g. '2024-04-08T17:21:13.333+00:00[UTC]'
|
|
155
|
+
* @return the `Temporal.ZonedDateTime` representing the moment of the molad
|
|
137
156
|
*/
|
|
138
157
|
getInstant() {
|
|
139
158
|
this.instant ??= getMoladAsDate(this.m);
|
|
@@ -205,8 +224,21 @@ class Molad {
|
|
|
205
224
|
return zdt.add({ hours: 24 * 15 });
|
|
206
225
|
}
|
|
207
226
|
/**
|
|
227
|
+
* Returns a human-readable, localized string announcing the molad —
|
|
228
|
+
* suitable for use on Shabbat Mevarchim. The format includes the Hebrew
|
|
229
|
+
* month name, day of week, hour : minute, and chalakim if non-zero.
|
|
230
|
+
*
|
|
231
|
+
* Time format honors `options.hour12` and `options.location` (12-hour vs.
|
|
232
|
+
* 24-hour); see {@link HebrewCalendar.reformatTimeStr}.
|
|
233
|
+
* @example
|
|
234
|
+
* import {Molad, months} from '@hebcal/core';
|
|
235
|
+
* const m = new Molad(5784, months.NISAN);
|
|
236
|
+
* m.render('en', {hour12: true});
|
|
237
|
+
* // => 'Molad Nisan: Mon, 7:21pm and 6 chalakim'
|
|
238
|
+
* m.render('he');
|
|
239
|
+
* // => 'מוֹלָד נִיסָן יִהְיֶה בַּיּוֹם שֵׁנִי בשָׁבוּעַ, …'
|
|
208
240
|
* @param [locale] Optional locale name (defaults to empty locale)
|
|
209
|
-
* @param options
|
|
241
|
+
* @param options used for time formatting (12-hour vs 24-hour)
|
|
210
242
|
*/
|
|
211
243
|
render(locale, options) {
|
|
212
244
|
const monthName = Locale.gettext(this.getMonthName(), locale);
|