diff --git a/lunar.js b/lunar.js index d2f2c1b..14b4539 100644 --- a/lunar.js +++ b/lunar.js @@ -689,26 +689,23 @@ weekIndex:gz.weekIndex, jieQi:gz.jieQi, jieQiList:gz.jieQiList, - solar:_solar - }, - getYear:function(){ - return this._p.year; - }, - getMonth:function(){ - return this._p.month; - }, - getDay:function(){ - return this._p.day; - }, - getHour:function(){ - return this._p.hour; - }, - getMinute:function(){ - return this._p.minute; - }, - getSecond:function(){ - return this._p.second; + solar:_solar, + eightChar:null }, + getYear:function(){return this._p.year;}, + getMonth:function(){return this._p.month;}, + getDay:function(){return this._p.day;}, + getHour:function(){return this._p.hour;}, + getMinute:function(){return this._p.minute;}, + getSecond:function(){return this._p.second;}, + getTimeGanIndex:function(){return this._p.timeGanIndex;}, + getTimeZhiIndex:function(){return this._p.timeZhiIndex;}, + getDayGanIndexExact:function(){return this._p.dayGanIndexExact;}, + getDayZhiIndexExact:function(){return this._p.dayZhiIndexExact;}, + getMonthGanIndexExact:function(){return this._p.monthGanIndexExact;}, + getMonthZhiIndexExact:function(){return this._p.monthZhiIndexExact;}, + getYearGanIndexExact:function(){return this._p.yearGanIndexExact;}, + getYearZhiIndexExact:function(){return this._p.yearZhiIndexExact;}, getGan:function(){ return this.getYearGan(); }, @@ -1303,6 +1300,12 @@ getJieQiList:function(){ return this._p.jieQiList; }, + getEightChar:function(){ + if(!this._p.eightChar){ + this._p.eightChar=EightChar.fromLunar(this); + } + return this._p.eightChar; + }, toString:function(){ return this.getYearInChinese()+'年'+this.getMonthInChinese()+'月'+this.getDayInChinese(); }, @@ -2340,12 +2343,212 @@ fromIndex:function(index){return _fromIndex(index);} }; })(); + var EightChar = (function(){ + var CHANG_SHENG_OFFSET = {'甲':11,'丙':2,'戊':2,'庚':5,'壬':8,'乙':6,'丁':9,'己':9,'辛':0,'癸':3}; + var _fromLunar=function(lunar){ + return { + _p:{lunar:lunar}, + getYear:function(){return this._p.lunar.getYearInGanZhiExact();}, + getYearGan:function(){return this._p.lunar.getYearGanExact();}, + getYearZhi:function(){return this._p.lunar.getYearZhiExact();}, + getYearHideGan:function(){return LunarUtil.ZHI_HIDE_GAN[this.getYearZhi()];}, + getYearWuXing:function(){ + return LunarUtil.WU_XING_GAN[this._p.lunar.getYearGanExact()]+LunarUtil.WU_XING_ZHI[this._p.lunar.getYearZhiExact()]; + }, + getYearNaYin:function(){return LunarUtil.NAYIN[this.getYear()];}, + getYearShiShenGan:function(){return LunarUtil.SHI_SHEN_GAN[this.getDayGan()+this.getYearGan()];}, + getYearShiShenZhi:function(){ + var dayGan = this.getDayGan(); + var zhi = this.getYearZhi(); + var hideGan = LunarUtil.ZHI_HIDE_GAN[zhi]; + var l = []; + for(var i=0,j=hideGan.length;i=12){ + index -= 12; + } + if(index<0){ + index += 12; + } + return EightChar.CHANG_SHENG[index]; + }, + getMonth:function(){return this._p.lunar.getMonthInGanZhiExact();}, + getMonthGan:function(){return this._p.lunar.getMonthGanExact();}, + getMonthZhi:function(){return this._p.lunar.getMonthZhiExact();}, + getMonthHideGan:function(){return LunarUtil.ZHI_HIDE_GAN[this.getMonthZhi()];}, + getMonthWuXing:function(){ + return LunarUtil.WU_XING_GAN[this._p.lunar.getMonthGanExact()]+LunarUtil.WU_XING_ZHI[this._p.lunar.getMonthZhiExact()]; + }, + getMonthNaYin:function(){return LunarUtil.NAYIN[this.getMonth()];}, + getMonthShiShenGan:function(){return LunarUtil.SHI_SHEN_GAN[this.getDayGan()+this.getMonthGan()];}, + getMonthShiShenZhi:function(){ + var dayGan = this.getDayGan(); + var zhi = this.getMonthZhi(); + var hideGan = LunarUtil.ZHI_HIDE_GAN[zhi]; + var l = []; + for(var i=0,j=hideGan.length;i=12){ + index -= 12; + } + if(index<0){ + index += 12; + } + return EightChar.CHANG_SHENG[index]; + }, + getDay:function(){return this._p.lunar.getDayInGanZhiExact();}, + getDayGan:function(){return this._p.lunar.getDayGanExact();}, + getDayZhi:function(){return this._p.lunar.getDayZhiExact();}, + getDayHideGan:function(){return LunarUtil.ZHI_HIDE_GAN[this.getDayZhi()];}, + getDayWuXing:function(){ + return LunarUtil.WU_XING_GAN[this._p.lunar.getDayGanExact()]+LunarUtil.WU_XING_ZHI[this._p.lunar.getDayZhiExact()]; + }, + getDayNaYin:function(){return LunarUtil.NAYIN[this.getDay()];}, + getDayShiShenGan:function(){return '日主';}, + getDayShiShenZhi:function(){ + var dayGan = this.getDayGan(); + var zhi = this.getDayZhi(); + var hideGan = LunarUtil.ZHI_HIDE_GAN[zhi]; + var l = []; + for(var i=0,j=hideGan.length;i=12){ + index -= 12; + } + if(index<0){ + index += 12; + } + return EightChar.CHANG_SHENG[index]; + }, + getTime:function(){return this._p.lunar.getTimeInGanZhi();}, + getTimeGan:function(){return this._p.lunar.getTimeGan();}, + getTimeZhi:function(){return this._p.lunar.getTimeZhi();}, + getTimeHideGan:function(){return LunarUtil.ZHI_HIDE_GAN[this.getTimeZhi()];}, + getTimeWuXing:function(){ + return LunarUtil.WU_XING_GAN[this._p.lunar.getTimeGan()]+LunarUtil.WU_XING_ZHI[this._p.lunar.getTimeZhi()]; + }, + getTimeNaYin:function(){return LunarUtil.NAYIN[this.getTime()];}, + getTimeShiShenGan:function(){return LunarUtil.SHI_SHEN_GAN[this.getDayGan()+this.getTimeGan()];}, + getTimeShiShenZhi:function(){ + var dayGan = this.getDayGan(); + var zhi = this.getTimeZhi(); + var hideGan = LunarUtil.ZHI_HIDE_GAN[zhi]; + var l = []; + for(var i=0,j=hideGan.length;i=12){ + index -= 12; + } + if(index<0){ + index += 12; + } + return EightChar.CHANG_SHENG[index]; + }, + getTaiYuan:function(){ + var ganIndex = this._p.lunar.getMonthGanIndexExact() + 1; + if(ganIndex>=10){ + ganIndex -= 10; + } + var zhiIndex = this._p.lunar.getMonthZhiIndexExact() + 3; + if(zhiIndex>=12){ + zhiIndex -= 12; + } + return LunarUtil.GAN[ganIndex+1]+LunarUtil.ZHI[zhiIndex+1]; + }, + getTaiYuanNaYin:function(){return LunarUtil.NAYIN[this.getTaiYuan()];}, + getMingGong:function(){ + var monthZhiIndex = 0; + var timeZhiIndex = 0; + for(var i=0,j=EightChar.MONTH_ZHI.length;i12){ + zhiIndex -= 12; + } + var jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex-zhiIndex); + if(jiaZiIndex>=60){ + jiaZiIndex -= 60; + } + if(jiaZiIndex<0){ + jiaZiIndex += 60; + } + return LunarUtil.JIA_ZI[jiaZiIndex]; + }, + getMingGongNaYin:function(){return LunarUtil.NAYIN[this.getMingGong()];}, + getShenGong:function(){ + var monthZhiIndex = 0; + var timeZhiIndex = 0; + for(var i=0,j=EightChar.MONTH_ZHI.length;i=60){ + jiaZiIndex -= 60; + } + if(jiaZiIndex<0){ + jiaZiIndex += 60; + } + return LunarUtil.JIA_ZI[jiaZiIndex]; + }, + getShenGongNaYin:function(){return LunarUtil.NAYIN[this.getShenGong()];}, + toString:function(){return this.getYear()+' '+this.getMonth()+' '+this.getDay()+' '+this.getTime();} + }; + }; + return { + MONTH_ZHI:['','寅','卯','辰','巳','午','未','申','酉','戌','亥','子','丑'], + CHANG_SHENG:['长生','沐浴','冠带','临官','帝旺','衰','病','死','墓','绝','胎','养'], + fromLunar:function(lunar){return _fromLunar(lunar);} + }; + })(); return { SolarUtil:SolarUtil, LunarUtil:LunarUtil, Solar:Solar, Lunar:Lunar, NineStar:NineStar, + EightChar:EightChar, SolarWeek:SolarWeek, SolarMonth:SolarMonth, SolarSeason:SolarSeason, diff --git a/package.json b/package.json index 068b932..452723f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lunar-javascript", - "version": "1.0.16", + "version": "1.0.17", "description": "lunar is a calendar library for Solar and Chinese Lunar.", "main": "index.js", "scripts": {