ilib
Version:
iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
1 lines • 1.84 kB
JavaScript
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 year=Math.floor((235*year-234)/19),parts=204+793*MathUtils.mod(year,1080),parts=11+12*year+793*Math.floor(year/1080)+Math.floor(parts/1080),year=29*year+Math.floor(parts/24);return MathUtils.mod(3*(year+1),7)<3?year+1:year},HebrewCal.newYearsCorrection=function(year,elapsed){var lastYear=HebrewCal.elapsedDays(year-1);return HebrewCal.elapsedDays(year+1)-elapsed==356?2:elapsed-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){year="number"==typeof year?year:year.year;return MathUtils.mod(1+7*year,19)<7},HebrewCal.prototype.getType=function(){return this.type},Calendar._constructors.hebrew=HebrewCal,module.exports=HebrewCal;