jcal-zmanim
Version:
A comprehensive JavaScript library for the Jewish Calendar, Zmanim, Holidays, and daily Shul notes.
2,034 lines (2,033 loc) • 345 kB
JavaScript
function _array_like_to_array(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _array_without_holes(arr) {
if (Array.isArray(arr)) return _array_like_to_array(arr);
}
function _assert_this_initialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _call_super(_this, derived, args) {
derived = _get_prototype_of(derived);
return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
}
function _class_call_check(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for(var i = 0; i < props.length; i++){
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, descriptor.key, descriptor);
}
}
function _create_class(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
return Constructor;
}
function _define_property(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _get_prototype_of(o) {
_get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _get_prototype_of(o);
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
if (superClass) _set_prototype_of(subClass, superClass);
}
function _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _iterable_to_array(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _non_iterable_spread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _object_spread(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i] != null ? arguments[i] : {};
var ownKeys = Object.keys(source);
if (typeof Object.getOwnPropertySymbols === "function") {
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
}));
}
ownKeys.forEach(function(key) {
_define_property(target, key, source[key]);
});
}
return target;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) {
symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
}
keys.push.apply(keys, symbols);
}
return keys;
}
function _object_spread_props(target, source) {
source = source != null ? source : {};
if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
return target;
}
function _possible_constructor_return(self, call) {
if (call && (_type_of(call) === "object" || typeof call === "function")) {
return call;
}
return _assert_this_initialized(self);
}
function _set_prototype_of(o, p) {
_set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _set_prototype_of(o, p);
}
function _to_consumable_array(arr) {
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
}
function _type_of(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
}
function _unsupported_iterable_to_array(o, minLen) {
if (!o) return;
if (typeof o === "string") return _array_like_to_array(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
}
function _is_native_reflect_construct() {
try {
var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
} catch (_) {}
return (_is_native_reflect_construct = function() {
return !!result;
})();
}
// src/JCal/DateUtils.ts
var MS_PER_DAY = 864e5;
var JS_START_DATE_ABS = 719163;
var JS_START_OFFSET = /* @__PURE__ */ new Date(0).getTimezoneOffset();
var DateUtils = /*#__PURE__*/ function() {
"use strict";
function _DateUtils() {
_class_call_check(this, _DateUtils);
}
_create_class(_DateUtils, null, [
{
key: "toInt",
value: /**
* Converts the given complex number to an integer by removing the decimal part.
*/ function toInt(float) {
return Math.floor(float);
}
},
{
key: "toSuffixed",
value: /**
* Add two character suffix to number. e.g. 21st, 102nd, 93rd, 500th
*/ function toSuffixed(num) {
var t = num.toString();
var suffix = "th";
if (t.length === 1 || t[t.length - 2] !== "1") {
switch(t[t.length - 1]){
case "1":
suffix = "st";
break;
case "2":
suffix = "nd";
break;
case "3":
suffix = "rd";
break;
}
}
return t + suffix;
}
},
{
key: "absSd",
value: /**
* Gets the absolute date of the given javascript Date object.
* @param {Date} date
*/ function absSd(date) {
var ms = date.valueOf() - date.getTimezoneOffset() * 6e4;
var numFullDays = Math.floor(ms / MS_PER_DAY);
return JS_START_DATE_ABS + numFullDays;
}
},
{
key: "sdFromAbs",
value: /**
* Gets a javascript date from an absolute date
*/ function sdFromAbs(abs) {
var offset = JS_START_OFFSET > 0 ? 1 : 0;
var daysSinceStart = abs - JS_START_DATE_ABS + offset;
return new Date(daysSinceStart * MS_PER_DAY);
}
},
{
key: "totalMinutes",
value: /**
* Gets the total number of minutes in the given time.
*/ function totalMinutes(time) {
return time ? time.hour * 60 + time.minute : 0;
}
},
{
key: "totalSeconds",
value: /**
* Gets the total number of seconds in the given time.
*/ function totalSeconds(time) {
return time ? _DateUtils.totalMinutes(time) * 60 + (time.second || 0) : 0;
}
},
{
key: "fixTime",
value: /**
* Makes sure hour is between 0 and 23 and minute is between 0 and 59.
*/ function fixTime(time) {
var result = {
hour: time.hour,
minute: time.minute,
second: time.second || 0
};
while(result.second >= 60){
result.minute += 1;
result.second -= 60;
}
while(result.second < 0){
result.minute -= 1;
result.second += 60;
}
while(result.minute < 0){
result.minute += 60;
result.hour--;
}
while(result.minute >= 60){
result.minute -= 60;
result.hour++;
}
if (result.hour < 0) {
result.hour = 24 + result.hour % 24;
}
if (result.hour > 23) {
result.hour = result.hour % 24;
}
return result;
}
},
{
key: "addMinutes",
value: /**
* Add the given number of minutes to the given time.
*/ function addMinutes(time, minutes) {
if (!time) return time;
return _DateUtils.fixTime({
hour: time.hour,
minute: time.minute + (minutes || 0),
second: time.second
});
}
},
{
key: "addSeconds",
value: /**
* Add the given number of seconds to the given time.
*/ function addSeconds(time, seconds) {
return _DateUtils.fixTime({
hour: time.hour,
minute: time.minute,
second: (time.second || 0) + seconds
});
}
},
{
key: "timeDiff",
value: /**
* Gets the time difference between two times of day.
*/ function timeDiff(earlierTime, laterTime) {
var showNegative = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
var earlySec = _DateUtils.totalSeconds(earlierTime), laterSec = _DateUtils.totalSeconds(laterTime), time = _DateUtils.fixTime({
hour: 0,
minute: 0,
second: earlySec <= laterSec ? laterSec - earlySec : showNegative ? earlySec - laterSec : 86400 - earlySec + laterSec
});
return _object_spread_props(_object_spread({}, time), {
sign: earlySec <= laterSec || !showNegative ? 1 : -1
});
}
},
{
key: "currUtcOffset",
value: /**
* Gets the UTC offset in whole hours for the users time zone.
*/ function currUtcOffset() {
var date = /* @__PURE__ */ new Date(), jan = new Date(date.getFullYear(), 0, 1), jul = new Date(date.getFullYear(), 6, 1);
return -_DateUtils.toInt(Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()) / 60);
}
},
{
key: "isDateDST",
value: /** Determines if the given date is within DST on the users system */ function isDateDST(date) {
return -_DateUtils.toInt(date.getTimezoneOffset() / 60) !== _DateUtils.currUtcOffset();
}
},
{
key: "isUSA_DST",
value: function isUSA_DST(date) {
var year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDate(), hour = date.getHours();
if (month < 3 || month == 12) {
return false;
} else if (month > 3 && month < 11) {
return true;
} else if (month === 3) {
var firstDOW = new Date(year, 2, 1).getDay(), targetDate = firstDOW == 0 ? 8 : 7 - (firstDOW + 7) % 7 + 8;
return day > targetDate || day === targetDate && hour >= 2;
} else {
var firstDOW1 = new Date(year, 10, 1).getDay(), targetDate1 = firstDOW1 === 0 ? 1 : 7 - (firstDOW1 + 7) % 7 + 1;
return day < targetDate1 || day === targetDate1 && hour < 2;
}
}
},
{
key: "isIsrael_DST",
value: function isIsrael_DST(date) {
var year = date.getFullYear(), month = date.getMonth() + 1, day = date.getDate(), hour = date.getHours();
if (month > 10 || month < 3) {
return false;
} else if (month > 3 && month < 10) {
return true;
} else if (month === 3) {
var lastFriDate = 31 - new Date(year, 2, 31).getDay() - 2;
return day > lastFriDate || day === lastFriDate && hour >= 2;
} else {
var lastSunDate = 31 - new Date(year, 9, 31).getDay();
return day < lastSunDate || day === lastSunDate && hour < 2;
}
}
},
{
key: "isDST",
value: /**
* Determines if the given date is within DST in the given location
*/ function isDST(location, date) {
if (location.UTCOffset === _DateUtils.currUtcOffset()) {
return _DateUtils.isDateDST(date);
} else if (location.Israel) {
return _DateUtils.isIsrael_DST(date);
} else {
return _DateUtils.isUSA_DST(date);
}
}
},
{
key: "has",
value: /** Returns whether or not the given, array, string, or argument list contains the given item or substring. */ function has(o) {
for(var _len = arguments.length, arr = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
arr[_key - 1] = arguments[_key];
}
if (arr.length === 1 && (Array.isArray(arr[0]) || typeof arr[0] === "string" || _instanceof(arr[0], String))) {
return arr[0].includes(o);
} else {
return arr.includes(o);
}
}
},
{
key: "isSecularLeapYear",
value: function isSecularLeapYear(year) {
return !(year % 400) || !!(year % 100) && !(year % 4);
}
},
{
key: "isValidDate",
value: function isValidDate(thing) {
return _instanceof(thing, Date) && !isNaN(thing.valueOf());
}
},
{
key: "isString",
value: function isString(thing) {
return typeof thing === "string" || _instanceof(thing, String);
}
},
{
key: "isNumber",
value: function isNumber(thing) {
return typeof thing === "number" || _instanceof(thing, Number);
}
}
]);
return _DateUtils;
}();
// src/JCal/Zmanim.ts
var _Zmanim = /*#__PURE__*/ function() {
"use strict";
function _Zmanim() {
_class_call_check(this, _Zmanim);
}
_create_class(_Zmanim, null, [
{
key: "getSunTimes",
value: /**
* Gets sunrise and sunset time for given date and Location.
* Accepts a javascript Date object, a string for creating a javascript date object or a jDate object.
* Location object is required.
* @returns {SunTimes}
* @param {Date | jDate} date A Javascript Date or Jewish Date for which to calculate the sun times.
* @param {Location} location Where on the globe to calculate the sun times for.
* @param {Boolean} considerElevation
*/ function getSunTimes(date, location) {
var considerElevation = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
var absDate;
if (date.Abs) {
absDate = date.Abs;
date = date.getDate();
} else {
if (typeof date === "string" || _instanceof(date, String)) {
date = new Date(date);
}
if (!DateUtils.isValidDate(date)) {
throw "Zmanim.getSunTimes: supplied date parameter cannot be converted to a Date";
}
absDate = DateUtils.absSd(date);
}
var cacheKey = "".concat(absDate, "|").concat(location.Name, "|").concat(location.Latitude, "|").concat(location.Longitude, "|").concat(location.Elevation, "|").concat(considerElevation);
if (_Zmanim._sunTimesCache.has(cacheKey)) {
return _Zmanim._sunTimesCache.get(cacheKey);
}
var sunrise, sunset, zenithDeg = 90, zenithMin = 50, lonHour = 0, longitude = 0, latitude = 0, cosLat = 0, sinLat = 0, cosZen = 0, sinDec = 0, cosDec = 0, xmRise = 0, xmSet = 0, xlRise = 0, xlSet = 0, aRise = 0, aSet = 0, ahrRise = 0, ahrSet = 0, hRise = 0, hSet = 0, tRise = 0, tSet = 0, utRise = 0, utSet = 0;
var day = _Zmanim.dayOfYear(date), earthRadius = 6356900, zenithAtElevation = _Zmanim.degToDec(zenithDeg, zenithMin) + _Zmanim.radToDeg(Math.acos(earthRadius / (earthRadius + (considerElevation ? location.Elevation : 0))));
zenithDeg = Math.floor(zenithAtElevation);
zenithMin = (zenithAtElevation - zenithDeg) * 60;
cosZen = Math.cos(0.01745 * _Zmanim.degToDec(zenithDeg, zenithMin));
longitude = location.Longitude;
lonHour = longitude / 15;
latitude = location.Latitude;
cosLat = Math.cos(0.01745 * latitude);
sinLat = Math.sin(0.01745 * latitude);
tRise = day + (6 + lonHour) / 24;
tSet = day + (18 + lonHour) / 24;
xmRise = _Zmanim.M(tRise);
xlRise = _Zmanim.L(xmRise);
xmSet = _Zmanim.M(tSet);
xlSet = _Zmanim.L(xmSet);
aRise = 57.29578 * Math.atan(0.91746 * Math.tan(0.01745 * xlRise));
aSet = 57.29578 * Math.atan(0.91746 * Math.tan(0.01745 * xlSet));
if (Math.abs(aRise + 360 - xlRise) > 90) {
aRise += 180;
}
if (aRise > 360) {
aRise -= 360;
}
if (Math.abs(aSet + 360 - xlSet) > 90) {
aSet += 180;
}
if (aSet > 360) {
aSet -= 360;
}
ahrRise = aRise / 15;
sinDec = 0.39782 * Math.sin(0.01745 * xlRise);
cosDec = Math.sqrt(1 - sinDec * sinDec);
hRise = (cosZen - sinDec * sinLat) / (cosDec * cosLat);
ahrSet = aSet / 15;
sinDec = 0.39782 * Math.sin(0.01745 * xlSet);
cosDec = Math.sqrt(1 - sinDec * sinDec);
hSet = (cosZen - sinDec * sinLat) / (cosDec * cosLat);
if (Math.abs(hRise) <= 1) {
hRise = 57.29578 * Math.acos(hRise);
utRise = (360 - hRise) / 15 + ahrRise + _Zmanim.adj(tRise) + lonHour;
sunrise = _Zmanim.timeAdj(utRise + location.UTCOffset, date, location);
if (sunrise.hour > 12) {
sunrise.hour -= 12;
}
}
if (Math.abs(hSet) <= 1) {
hSet = 57.29578 * Math.acos(hSet);
utSet = hRise / 15 + ahrSet + _Zmanim.adj(tSet) + lonHour;
sunset = _Zmanim.timeAdj(utSet + location.UTCOffset, date, location);
if (sunset.hour > 0 && sunset.hour < 12) {
sunset.hour += 12;
}
}
if (!sunrise || !sunset) {
var formattedDate = typeof date.toDateString === "function" ? date.toDateString() : date.toString();
throw new Error('Zmanim Calculation Error: The sun does not rise or set at location "'.concat(location.Name, '" (Lat: ').concat(location.Latitude, ") on ").concat(formattedDate, ". The location may be in a Polar region (Polar Night/Day)."));
}
var result = {
sunrise: sunrise,
sunset: sunset
};
_Zmanim._sunTimesCache.set(cacheKey, result);
if (_Zmanim._sunTimesCache.size > 2e3) _Zmanim._sunTimesCache.clear();
return result;
}
},
{
key: "getChatzos",
value: /**
* @param {jDate | Date} date
* @param {Location} location
*/ function getChatzos(date, location) {
return _Zmanim.getChatzosFromSuntimes(_Zmanim.getSunTimes(date, location, false));
}
},
{
key: "getChatzosFromSuntimes",
value: /**
* @param {SunTimes} sunTimes
*/ function getChatzosFromSuntimes(sunTimes) {
var rise = sunTimes.sunrise, set = sunTimes.sunset;
if (rise === void 0 || isNaN(rise.hour) || set === void 0 || isNaN(set.hour)) {
return {
hour: NaN,
minute: NaN
};
}
var chatz = DateUtils.toInt((DateUtils.totalSeconds(set) - DateUtils.totalSeconds(rise)) / 2);
return DateUtils.addSeconds(rise, chatz);
}
},
{
key: "getShaaZmanis",
value: /**
* @param {jDate | Date} date
* @param {Location} location
* @param {any} offset
*/ function getShaaZmanis(date, location, offset) {
return _Zmanim.getShaaZmanisFromSunTimes(_Zmanim.getSunTimes(date, location, false), offset);
}
},
{
key: "getShaaZmanisFromSunTimes",
value: /**
* @param {{ sunrise: any; sunset: any; }} sunTimes
* @param {number} [offset]
*/ function getShaaZmanisFromSunTimes(sunTimes, offset) {
if (!sunTimes || !sunTimes.sunrise || !sunTimes.sunset) {
return 0;
}
var rise = sunTimes.sunrise, set = sunTimes.sunset;
if (!rise || isNaN(rise.hour) || !set || isNaN(set.hour)) {
return NaN;
}
if (offset) {
rise = DateUtils.addMinutes(rise, -offset);
set = DateUtils.addMinutes(set, offset);
}
return (DateUtils.totalSeconds(set) - DateUtils.totalSeconds(rise)) / 720;
}
},
{
key: "getShaaZmanisMga",
value: /**
* @param {{ sunrise: any; sunset: any; }} sunTimes
* @param {boolean} israel
*/ function getShaaZmanisMga(sunTimes, israel2) {
var minutes = israel2 ? 90 : 72;
var rise = sunTimes.sunrise && DateUtils.addMinutes(sunTimes.sunrise, -minutes), set = sunTimes.sunset && DateUtils.addMinutes(sunTimes.sunset, minutes);
if (!rise || isNaN(rise.hour) || !set || isNaN(set.hour)) {
return NaN;
}
return (DateUtils.totalSeconds(set) - DateUtils.totalSeconds(rise)) / 720;
}
},
{
key: "getCandleLighting",
value: /**
* @param {jDate | Date} date
* @param {Location} location
*/ function getCandleLighting(date, location) {
return _Zmanim.getCandleLightingFromSunTimes(_Zmanim.getSunTimes(date, location), location);
}
},
{
key: "getCandleLightingFromSunTimes",
value: /**
* @param {SunTimes} sunTimes
* @param {any} location
*/ function getCandleLightingFromSunTimes(sunTimes, location) {
return sunTimes.sunset && _Zmanim.getCandleLightingFromSunset(sunTimes.sunset, location);
}
},
{
key: "getCandleLightingFromSunset",
value: /**
* @param {Time} sunset
* @param {Location} location
*/ function getCandleLightingFromSunset(sunset, location) {
return DateUtils.addMinutes(sunset, -(location.CandleLighting || 0));
}
},
{
key: "dayOfYear",
value: /**
* @param {Date} date
*/ function dayOfYear(date) {
var month = date.getMonth(), isLeap = function() {
return DateUtils.isSecularLeapYear(date.getFullYear());
}, yearDay = [
0,
1,
32,
60,
91,
121,
152,
182,
213,
244,
274,
305,
335
];
return yearDay[month + 1] + date.getDate() + (month > 1 && isLeap() ? 1 : 0);
}
},
{
key: "degToDec",
value: /**
* @param {number} deg
* @param {number} min
*/ function degToDec(deg, min) {
return deg + min / 60;
}
},
{
key: "M",
value: /**
* @param {number} x
*/ function M(x) {
return 0.9856 * x - 3.251;
}
},
{
key: "L",
value: /**
* @param {number} x
*/ function L(x) {
return x + 1.916 * Math.sin(0.01745 * x) + 0.02 * Math.sin(2 * 0.01745 * x) + 282.565;
}
},
{
key: "adj",
value: /**
* @param {number} x
*/ function adj(x) {
return -0.06571 * x - 6.62;
}
},
{
key: "radToDeg",
value: /**
* @param {number} rad
*/ function radToDeg(rad) {
return 57.29578 * rad;
}
},
{
key: "timeAdj",
value: /**
* @param {number} time
* @param {Date} date
* @param {Location} location
*/ function timeAdj(time, date, location) {
if (time < 0) {
time += 24;
}
var hour = DateUtils.toInt(time);
var minFloat = (time - hour) * 60 + 0.5, min = DateUtils.toInt(minFloat), sec = Math.round(60 * (minFloat - min));
if (DateUtils.isDST(location, date)) {
hour++;
}
return DateUtils.fixTime({
hour: hour,
minute: min,
second: sec
});
}
}
]);
return _Zmanim;
}();
_Zmanim._sunTimesCache = /* @__PURE__ */ new Map();
var Zmanim = _Zmanim;
// src/JCal/Sedra.ts
var _Sedra = /*#__PURE__*/ function() {
"use strict";
function _Sedra(jd, israel2) {
_class_call_check(this, _Sedra);
if (jd.Month === 7 && jd.Day >= 15 && jd.Day < (israel2 ? 23 : 24)) {
this.sedras = [
_Sedra.sedraList[53]
];
return;
}
var sedraArray = [], sedraOrder = _Sedra.getSedraOrder(jd.Year, israel2), absDate = jd.Abs, index, weekNum;
absDate = _Sedra.getDayOnOrBefore(6, absDate + 6);
weekNum = (absDate - sedraOrder.firstSatInYear) / 7;
if (sedraOrder.sedraArray && weekNum >= sedraOrder.sedraArray.length) {
var indexLast = sedraOrder.sedraArray[sedraOrder.sedraArray.length - 1];
if (indexLast < 0) {
index = -indexLast + 2;
} else {
index = indexLast + 1;
}
} else {
index = sedraOrder.sedraArray ? sedraOrder.sedraArray[weekNum] : -1;
}
if (index >= 0) {
sedraArray = [
_Sedra.sedraList[index]
];
} else {
var i = -index;
sedraArray = [
_Sedra.sedraList[i],
_Sedra.sedraList[i + 1]
];
}
this.sedras = sedraArray;
}
_create_class(_Sedra, [
{
/**
* Gets the sedra/s as a string. If there are two, they are seperated by a " - "
*/ key: "toString",
value: function toString() {
return this.sedras.length > 0 && this.sedras.map(function(s) {
return s.eng;
}).join(" - ");
}
},
{
/**
* Gets the sedra/s as a string. If there are two, they are seperated by a " - "
*/ key: "toStringHeb",
value: function toStringHeb() {
return this.sedras.length > 0 && this.sedras.map(function(s) {
return s.heb;
}).join(" - ");
}
}
], [
{
key: "getDayOnOrBefore",
value: function getDayOnOrBefore(day_of_week, date) {
return date - (date - day_of_week) % 7;
}
},
{
key: "getSedraOrder",
value: function getSedraOrder(year, israel2) {
if (_Sedra.lastCalculatedYear != null && _Sedra.lastCalculatedYear.year === year && _Sedra.lastCalculatedYear.israel === israel2) {
return _Sedra.lastCalculatedYear;
}
var longCheshvon = jDate.isLongCheshvan(year), shortKislev = jDate.isShortKislev(year), roshHashana = jDate.absJd(year, 7, 1), roshHashanaDOW = Math.abs(roshHashana % 7), firstSatInYear = _Sedra.getDayOnOrBefore(6, roshHashana + 6);
var yearType, sArray;
if (longCheshvon && !shortKislev) yearType = "complete";
else if (!longCheshvon && shortKislev) yearType = "incomplete";
else yearType = "regular";
if (!jDate.isJdLeapY(year)) {
switch(roshHashanaDOW){
case 6:
if (yearType === "incomplete") {
sArray = _Sedra.shabbos_short;
} else if (yearType === "complete") {
sArray = _Sedra.shabbos_long;
}
break;
case 1:
if (yearType === "incomplete") {
sArray = _Sedra.mon_short;
} else if (yearType === "complete") {
sArray = israel2 ? _Sedra.mon_short : _Sedra.mon_long;
}
break;
case 2:
if (yearType === "regular") {
sArray = israel2 ? _Sedra.mon_short : _Sedra.mon_long;
}
break;
case 4:
if (yearType === "regular") {
sArray = israel2 ? _Sedra.thu_normal_Israel : _Sedra.thu_normal;
} else if (yearType === "complete") {
sArray = _Sedra.thu_long;
}
break;
default:
throw "improper sedra year type calculated.";
}
} else {
switch(roshHashanaDOW){
case 6:
if (yearType === "incomplete") {
sArray = _Sedra.shabbos_short_leap;
} else if (yearType === "complete") {
sArray = israel2 ? _Sedra.shabbos_short_leap : _Sedra.shabbos_long_leap;
}
break;
case 1:
if (yearType === "incomplete") {
sArray = israel2 ? _Sedra.mon_short_leap_Israel : _Sedra.mon_short_leap;
} else if (yearType === "complete") {
sArray = israel2 ? _Sedra.mon_long_leap_Israel : _Sedra.mon_long_leap;
}
break;
case 2:
if (yearType === "regular") {
sArray = israel2 ? _Sedra.mon_long_leap_Israel : _Sedra.mon_long_leap;
}
break;
case 4:
if (yearType === "incomplete") {
sArray = _Sedra.thu_short_leap;
} else if (yearType === "complete") {
sArray = _Sedra.thu_long_leap;
}
break;
default:
throw "improper sedra year type calculated.";
}
}
var retobj = {
firstSatInYear: firstSatInYear,
sedraArray: sArray,
year: year,
israel: israel2
};
_Sedra.lastCalculatedYear = retobj;
return retobj;
}
}
]);
return _Sedra;
}();
_Sedra.lastCalculatedYear = null;
_Sedra.sedraList = [
{
eng: "Bereshis",
heb: "\u05D1\u05E8\u05D0\u05E9\u05D9\u05EA"
},
{
eng: "Noach",
heb: "\u05E0\u05D7"
},
{
eng: "Lech-Lecha",
heb: "\u05DC\u05DA \u05DC\u05DA"
},
{
eng: "Vayera",
heb: "\u05D5\u05D9\u05E8\u05D0"
},
{
eng: "Chayei Sara",
heb: "\u05D7\u05D9\u05D9 \u05E9\u05E8\u05D4"
},
{
eng: "Toldos",
heb: "\u05EA\u05D5\u05DC\u05D3\u05D5\u05EA"
},
{
eng: "Vayetzei",
heb: "\u05D5\u05D9\u05E6\u05D0"
},
{
eng: "Vayishlach",
heb: "\u05D5\u05D9\u05E9\u05DC\u05D7"
},
{
eng: "Vayeishev",
heb: "\u05D5\u05D9\u05E9\u05D1"
},
{
eng: "Mikeitz",
heb: "\u05DE\u05E7\u05E5"
},
{
eng: "Vayigash",
heb: "\u05D5\u05D9\u05D2\u05E9"
},
{
eng: "Vayechi",
heb: "\u05D5\u05D9\u05D7\u05D9"
},
{
eng: "Shemos",
heb: "\u05E9\u05DE\u05D5\u05EA"
},
{
eng: "Va'era",
heb: "\u05D5\u05D0\u05E8\u05D0"
},
{
eng: "Bo",
heb: "\u05D1\u05D0"
},
{
eng: "Beshalach",
heb: "\u05D1\u05E9\u05DC\u05D7"
},
{
eng: "Yisro",
heb: "\u05D9\u05EA\u05E8\u05D5"
},
{
eng: "Mishpatim",
heb: "\u05DE\u05E9\u05E4\u05D8\u05D9\u05DD"
},
{
eng: "Terumah",
heb: "\u05EA\u05E8\u05D5\u05DE\u05D4"
},
{
eng: "Tetzaveh",
heb: "\u05EA\u05E6\u05D5\u05D4"
},
{
eng: "Ki Sisa",
heb: "\u05DB\u05D9 \u05EA\u05E9\u05D0"
},
{
eng: "Vayakhel",
heb: "\u05D5\u05D9\u05E7\u05D4\u05DC"
},
{
eng: "Pekudei",
heb: "\u05E4\u05E7\u05D5\u05D3\u05D9"
},
{
eng: "Vayikra",
heb: "\u05D5\u05D9\u05E7\u05E8\u05D0"
},
{
eng: "Tzav",
heb: "\u05E6\u05D5"
},
{
eng: "Shmini",
heb: "\u05E9\u05DE\u05D9\u05E0\u05D9"
},
{
eng: "Tazria",
heb: "\u05EA\u05D6\u05E8\u05D9\u05E2"
},
{
eng: "Metzora",
heb: "\u05DE\u05E6\u05D5\u05E8\u05E2"
},
{
eng: "Achrei Mos",
heb: "\u05D0\u05D7\u05E8\u05D9 \u05DE\u05D5\u05EA"
},
{
eng: "Kedoshim",
heb: "\u05E7\u05D3\u05D5\u05E9\u05D9\u05DD"
},
{
eng: "Emor",
heb: "\u05D0\u05DE\u05D5\u05E8"
},
{
eng: "Behar",
heb: "\u05D1\u05D4\u05E8"
},
{
eng: "Bechukosai",
heb: "\u05D1\u05D7\u05E7\u05D5\u05EA\u05D9"
},
{
eng: "Bamidbar",
heb: "\u05D1\u05DE\u05D3\u05D1\u05E8"
},
{
eng: "Nasso",
heb: "\u05E0\u05E9\u05D0"
},
{
eng: "Beha'aloscha",
heb: "\u05D1\u05D4\u05E2\u05DC\u05EA\u05DA"
},
{
eng: "Sh'lach",
heb: "\u05E9\u05DC\u05D7"
},
{
eng: "Korach",
heb: "\u05E7\u05E8\u05D7"
},
{
eng: "Chukas",
heb: "\u05D7\u05E7\u05EA"
},
{
eng: "Balak",
heb: "\u05D1\u05DC\u05E7"
},
{
eng: "Pinchas",
heb: "\u05E4\u05D9\u05E0\u05D7\u05E1"
},
{
eng: "Matos",
heb: "\u05DE\u05D8\u05D5\u05EA"
},
{
eng: "Masei",
heb: "\u05DE\u05E1\u05E2\u05D9"
},
{
eng: "Devarim",
heb: "\u05D3\u05D1\u05E8\u05D9\u05DD"
},
{
eng: "Va'eschanan",
heb: "\u05D5\u05D0\u05EA\u05D7\u05E0\u05DF"
},
{
eng: "Eikev",
heb: "\u05E2\u05E7\u05D1"
},
{
eng: "Re'eh",
heb: "\u05E8\u05D0\u05D4"
},
{
eng: "Shoftim",
heb: "\u05E9\u05D5\u05E4\u05D8\u05D9\u05DD"
},
{
eng: "Ki Seitzei",
heb: "\u05DB\u05D9 \u05EA\u05E6\u05D0"
},
{
eng: "Ki Savo",
heb: "\u05DB\u05D9 \u05EA\u05D1\u05D0"
},
{
eng: "Nitzavim",
heb: "\u05E0\u05E6\u05D1\u05D9\u05DD"
},
{
eng: "Vayeilech",
heb: "\u05D5\u05D9\u05DC\u05DA"
},
{
eng: "Ha'Azinu",
heb: "\u05D4\u05D0\u05D6\u05D9\u05E0\u05D5"
},
{
eng: "Vezos Habracha",
heb: "\u05D5\u05D6\u05D0\u05EA \u05D4\u05D1\u05E8\u05DB\u05D4"
}
];
_Sedra.shabbos_short = [
52,
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
-21,
23,
24,
25,
25,
-26,
-28,
30,
-31,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
50
];
_Sedra.shabbos_long = [
52,
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
-21,
23,
24,
25,
25,
-26,
-28,
30,
-31,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
-50
];
_Sedra.mon_short = [
51,
52,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
-21,
23,
24,
25,
25,
-26,
-28,
30,
-31,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
-50
];
_Sedra.mon_long = [
51,
52,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
-21,
23,
24,
25,
25,
-26,
-28,
30,
-31,
33,
34,
34,
35,
36,
37,
-38,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
-50
];
_Sedra.thu_normal = [
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
-21,
23,
24,
25,
25,
25,
-26,
-28,
30,
-31,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
50
];
_Sedra.thu_normal_Israel = [
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
-21,
23,
24,
25,
25,
-26,
-28,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
50
];
_Sedra.thu_long = [
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
25,
-26,
-28,
30,
-31,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
50
];
_Sedra.shabbos_short_leap = [
52,
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
-50
];
_Sedra.shabbos_long_leap = [
52,
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
28,
29,
30,
31,
32,
33,
34,
34,
35,
36,
37,
-38,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
-50
];
_Sedra.mon_short_leap = [
51,
52,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
28,
29,
30,
31,
32,
33,
34,
34,
35,
36,
37,
-38,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
-50
];
_Sedra.mon_short_leap_Israel = [
51,
52,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
-50
];
_Sedra.mon_long_leap = [
51,
52,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
28,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
-41,
43,
44,
45,
46,
47,
48,
49,
50
];
_Sedra.mon_long_leap_Israel = [
51,
52,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50
];
_Sedra.thu_short_leap = [
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50
];
_Sedra.thu_long_leap = [
52,
53,
53,
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
-50
];
var Sedra = _Sedra;
// src/JCal/PirkeiAvos.ts
var _PirkeiAvos = /*#__PURE__*/ function() {
"use strict";
function _PirkeiAvos() {
_class_call_check(this, _PirkeiAvos);
}
_create_class(_PirkeiAvos, null, [
{
key: "getPrakim",
value: function getPrakim(jd, israel2) {
if (jd.getDayOfWeek() !== 6) {
return [];
}
var jMonth = jd.Month, jDay = jd.Day;
if (jMonth === 1 && jDay > (israel2 ? 21 : 22) || //All Shabbosim through Iyar, Sivan, Tamuz, Av - besides for the day/s of Shavuos and Tisha B'Av
jMonth > 1 && jMonth < 6 && !(jMonth === 3 && jDay === 6 || !israel2 && jMonth === 3 && jDay === 7) && !(jMonth === 5 && jDay === 9)) {
return [
_PirkeiAvos._get1stPerek(jd, israel2)
];
} else if (jMonth === 6) {
return _PirkeiAvos._ellul(jd, israel2);
} else {
return [];
}
}
}
]);
return _PirkeiAvos;
}();
_PirkeiAvos._get1stPerek = function(jd, israel2) {
var jYear = jd.Year, jMonth = jd.Month, jDay = jd.Day, pes1 = new jDate(jYear, 1, 15), shb1 = (israel2 ? 7 : 8) + (6 - pes1.getDayOfWeek()), cShb = jMonth === 1 && jDay === shb1 + 15 ? 1 : Utils.toInt((jd.Abs - (pes1.Abs + shb1)) / 7) + 1;
var prk = cShb % 6;
if (prk === 0) prk = 6;
if (!israel2 && pes1.getDayOfWeek() === 4 && (jMonth > 3 || jMonth === 3 && jDay > 6)) {
prk = prk === 1 ? 6 : prk - 1;
}
if (pes1.getDayOfWeek() === 6 && (jMonth > 5 || jMonth === 5 && jDay > 9)) {
prk = prk === 1 ? 6 : prk - 1;
}
return prk;
};
_PirkeiAvos._ellul = function(jd, israel2) {
var prakim;
var jYear = jd.Year, jDay = jd.Day, day1 = new jDate(jYear, 6, 1, jd.Abs - jd.Day + 1), day1DOW = day1.getDayOfWeek(), shabbos1Day = day1DOW === 6 ? 1 : 6 - (day1DOW + 6) % 6 + 1, shabbos1Date = new jDate(jYear, 6, shabbos1Day, day1.Abs + shabbos1Day - 1), cShb = jDay === shabbos1Day ? 1 : Utils.toInt((jDay - shabbos1Day) / 7) + 1;
switch(_PirkeiAvos._get1stPerek(shabbos1Date, israel2)){
case 1:
switch(cShb){
case 1:
prakim = [
1
];
break;
case 2:
prakim = [
2
];
break;
case 3:
prakim = [
3,
4
];
break;
case 4:
prakim = [
5,
6
];
break;
}
break;
case 2:
switch(cShb){
case 1:
prakim = [
2
];
break;
case 2:
prakim = [
3
];
break;
case 3:
prakim = [
4
];
break;
case 4:
prakim = [
5,
6
];
break;
}
break;
case 3:
switch(cShb){
case 1:
prakim = [
3
];
break;
case 2:
prakim = [
4
];
break;
case 3:
prakim = [
5
];
break;
case 4:
prakim = [
6
];
break;
}
break;
case 4:
switch(cShb){
case 1:
prakim = [
4,
5
];
break;
case 2:
prakim = [
6,
1