UNPKG

ilib

Version:

iLib is a cross-engine library of internationalization (i18n) classes written in pure JS

1 lines 1.86 kB
var MathUtils=require("./MathUtils.js"),Calendar=require("./Calendar.js"),HebrewCal=function(options){this.type="hebrew",options&&"function"==typeof options.onLoad&&options.onLoad(this)};HebrewCal.elapsedDays=function(year){var months=Math.floor((235*year-234)/19),parts=204+793*MathUtils.mod(months,1080),hours=11+12*months+793*Math.floor(months/1080)+Math.floor(parts/1080),days=29*months+Math.floor(hours/24);return MathUtils.mod(3*(days+1),7)<3?days+1:days},HebrewCal.newYearsCorrection=function(year,elapsed){var lastYear=HebrewCal.elapsedDays(year-1),thisYear=elapsed;return HebrewCal.elapsedDays(year+1)-thisYear==356?2:thisYear-lastYear==382?1:0},HebrewCal.newYear=function(year){var elapsed=HebrewCal.elapsedDays(year);return elapsed+HebrewCal.newYearsCorrection(year,elapsed)},HebrewCal.daysInYear=function(year){return HebrewCal.newYear(year+1)-HebrewCal.newYear(year)},HebrewCal.longHeshvan=function(year){return 5===MathUtils.mod(HebrewCal.daysInYear(year),10)},HebrewCal.longKislev=function(year){return 3!==MathUtils.mod(HebrewCal.daysInYear(year),10)},HebrewCal.prototype.lastDayOfMonth=function(month,year){switch(month){case 2:case 4:case 6:case 10:return 29;case 13:return this.isLeapYear(year)?29:0;case 8:return HebrewCal.longHeshvan(year)?30:29;case 9:return HebrewCal.longKislev(year)?30:29;case 12:case 1:case 3:case 5:case 7:case 11:return 30;default:return 0}},HebrewCal.prototype.getNumMonths=function(year){return this.isLeapYear(year)?13:12},HebrewCal.prototype.getMonLength=function(month,year){return month<1||13<month||13==month&&!this.isLeapYear(year)?0:this.lastDayOfMonth(month,year)},HebrewCal.prototype.isLeapYear=function(year){var y="number"==typeof year?year:year.year;return MathUtils.mod(1+7*y,19)<7},HebrewCal.prototype.getType=function(){return this.type},Calendar._constructors.hebrew=HebrewCal,module.exports=HebrewCal;