ilib
Version:
iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
1 lines • 1.73 kB
JavaScript
var ilib=require("./ilib.js");var MathUtils=require("./MathUtils.js");var Calendar=require("./Calendar.js");var HebrewCal=function(){this.type="hebrew"};HebrewCal.elapsedDays=function(e){var r=Math.floor((235*e-234)/19);var a=204+793*MathUtils.mod(r,1080);var t=11+12*r+793*Math.floor(r/1080)+Math.floor(a/1080);var n=29*r+Math.floor(t/24);return MathUtils.mod(3*(n+1),7)<3?n+1:n};HebrewCal.newYearsCorrection=function(e,r){var a=HebrewCal.elapsedDays(e-1),t=r,n=HebrewCal.elapsedDays(e+1);return n-t==356?2:t-a==382?1:0};HebrewCal.newYear=function(e){var r=HebrewCal.elapsedDays(e);return r+HebrewCal.newYearsCorrection(e,r)};HebrewCal.daysInYear=function(e){return HebrewCal.newYear(e+1)-HebrewCal.newYear(e)};HebrewCal.longHeshvan=function(e){return MathUtils.mod(HebrewCal.daysInYear(e),10)===5};HebrewCal.longKislev=function(e){return MathUtils.mod(HebrewCal.daysInYear(e),10)!==3};HebrewCal.prototype.lastDayOfMonth=function(e,r){switch(e){case 2:case 4:case 6:case 10:return 29;case 13:return this.isLeapYear(r)?29:0;case 8:return HebrewCal.longHeshvan(r)?30:29;case 9:return HebrewCal.longKislev(r)?30:29;case 12:case 1:case 3:case 5:case 7:case 11:return 30;default:return 0}};HebrewCal.prototype.getNumMonths=function(e){return this.isLeapYear(e)?13:12};HebrewCal.prototype.getMonLength=function(e,r){if(e<1||e>13||e==13&&!this.isLeapYear(r)){return 0}return this.lastDayOfMonth(e,r)};HebrewCal.prototype.isLeapYear=function(e){var r=typeof e=="number"?e:e.year;return MathUtils.mod(1+7*r,19)<7};HebrewCal.prototype.getType=function(){return this.type};HebrewCal.prototype.newDateInstance=function(e){var r=require("./HebrewDate.js");return new r(e)};Calendar._constructors["hebrew"]=HebrewCal;module.exports=HebrewCal;