ilib
Version:
iLib is a cross-engine library of internationalization (i18n) classes written in pure JS
1 lines • 1.85 kB
JavaScript
var ilib=require("./ilib.js"),MathUtils=require("./MathUtils.js"),Astro=require("./Astro.js"),RataDie=require("./RataDie.js"),GregorianDate=require("./GregorianDate.js"),PersRataDie=function(params){this.rd=NaN,Astro.initAstro(!params||"boolean"!=typeof params.sync||params.sync,params&¶ms.loadParams,ilib.bind(this,function(x){RataDie.call(this,params),params&&"function"==typeof params.callback&¶ms.callback(this)}))};PersRataDie.prototype=new RataDie(),PersRataDie.prototype.parent=RataDie,(PersRataDie.prototype.constructor=PersRataDie).prototype.epoch=1948319.5,PersRataDie.prototype._tehranEquinox=function(year){var equJED,eot;return(equJED=Astro._equinox(year,0))-Astro._deltat(year)/86400+(eot=((eot=360*Astro._equationOfTime(equJED))-20*Math.floor(eot/20))/360)+52.5/360},PersRataDie.prototype._getYear=function(jd){var nexteq,guess=new GregorianDate({julianday:jd}).getYears()-2,ret={};for(ret.equinox=this._tehranEquinox(guess);ret.equinox>jd;)guess--,ret.equinox=this._tehranEquinox(guess);for(nexteq=ret.equinox-1;!(Math.floor(ret.equinox)+.5<=jd&&jd<Math.floor(nexteq)+.5);)ret.equinox=nexteq,guess++,nexteq=this._tehranEquinox(guess);return ret.year=Math.round((ret.equinox-this.epoch-1)/365.24219878)+1,ret},PersRataDie.prototype._setDateComponents=function(date){var adr,guess,jd;for(guess=this.epoch+1+365.24219878*((date.year||0)-2),adr={year:(date.year||0)-1,equinox:0};adr.year<date.year;)guess=(adr=this._getYear(guess)).equinox+367.24219878;jd=Math.floor(adr.equinox)+((date.month||0)<=7?31*((date.month||1)-1):30*((date.month||1)-1)+6)+((date.day||1)-1+.5),jd+=(36e5*(date.hour||0)+6e4*(date.minute||0)+1e3*(date.second||0)+(date.millisecond||0))/864e5,this.rd=jd-this.epoch},PersRataDie.prototype._onOrBefore=function(rd,dayOfWeek){return rd-MathUtils.mod(Math.floor(rd)-dayOfWeek-3,7)},module.exports=PersRataDie;