UNPKG

ilib

Version:

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

1 lines 3.31 kB
var LocaleInfo=require("./LocaleInfo.js"),IDate=function(options){};IDate._constructors={},IDate.prototype={getType:function(){return"date"},getTime:function(){return this.rd.getTime()},getTimeExtended:function(){return this.rd.getTimeExtended()},setTime:function(millis){this.rd=this.newRd({unixtime:millis,cal:this.cal}),this._calcDateComponents()},getDays:function(){return this.day},getMonths:function(){return this.month},getYears:function(){return this.year},getHours:function(){return this.hour},getMinutes:function(){return this.minute},getSeconds:function(){return this.second},getMilliseconds:function(){return this.millisecond},getEra:function(){return this.year<1?-1:1},setDays:function(day){this.day=parseInt(day,10)||1,this.rd._setDateComponents(this)},setMonths:function(month){this.month=parseInt(month,10)||1,this.rd._setDateComponents(this)},setYears:function(year){this.year=parseInt(year,10)||0,this.rd._setDateComponents(this)},setHours:function(hour){this.hour=parseInt(hour,10)||0,this.rd._setDateComponents(this)},setMinutes:function(minute){this.minute=parseInt(minute,10)||0,this.rd._setDateComponents(this)},setSeconds:function(second){this.second=parseInt(second,10)||0,this.rd._setDateComponents(this)},setMilliseconds:function(milli){this.millisecond=parseInt(milli,10)||0,this.rd._setDateComponents(this)},before:function(dow){return new this.constructor({rd:this.rd.before(dow,this.offset),timezone:this.timezone})},after:function(dow){return new this.constructor({rd:this.rd.after(dow,this.offset),timezone:this.timezone})},onOrBefore:function(dow){return new this.constructor({rd:this.rd.onOrBefore(dow,this.offset),timezone:this.timezone})},onOrAfter:function(dow){return new this.constructor({rd:this.rd.onOrAfter(dow,this.offset),timezone:this.timezone})},getJSDate:function(){var unix=this.rd.getTimeExtended();return isNaN(unix)?void 0:new Date(unix)},getRataDie:function(){return this.rd.getRataDie()},setRd:function(rd){this.rd=this.newRd({rd:rd,cal:this.cal}),this._calcDateComponents()},getJulianDay:function(){return this.rd.getJulianDay()},setJulianDay:function(date){this.rd=this.newRd({julianday:"object"==typeof date?date.getDate():date,cal:this.cal}),this._calcDateComponents()},getTimeZone:function(){return this.timezone||"local"},setTimeZone:function(tzName){tzName&&""!==tzName?"string"==typeof tzName&&(this.timezone=tzName,this.tz=void 0,this._calcDateComponents()):(this.timezone=void 0,this.tz=void 0)},firstSunday:function(year){year=this.newRd({year:year,month:1,day:1,hour:0,minute:0,second:0,millisecond:0,cal:this.cal});return this.newRd({rd:year.onOrAfter(4),cal:this.cal}).before(0)},getWeekOfYear:function(){var rd=Math.floor(this.rd.getRataDie()),year=this._calcYear(rd+this.offset),yearStart=this.firstSunday(year);return rd<yearStart?yearStart=this.firstSunday(year-1):(year=this.firstSunday(year+1))<=rd&&(yearStart=year),Math.floor((rd-yearStart)/7)+1},getWeekOfMonth:function(locale){var locale=new LocaleInfo(locale),first=this.newRd({year:this._calcYear(this.rd.getRataDie()+this.offset),month:this.getMonths(),day:1,hour:0,minute:0,second:0,millisecond:0,cal:this.cal}),locale=first.onOrAfter(locale.getFirstDayOfWeek());return 3<locale-first.getRataDie()&&(locale-=7),Math.floor((this.rd.getRataDie()-locale)/7)+1}},module.exports=IDate;