UNPKG

lunar-javascript

Version:

lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)、佛历和道历工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋、凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。lunar is a calendar library for Solar and Chinese Lunar.

1,423 lines (1,405 loc) 436 kB
;(function(root,factory){ if (typeof define==='function'&&define.amd){ define(factory); }else if(typeof module!='undefined'&&module.exports){ module.exports = factory(); }else{ var o = factory(); for(var i in o){ root[i] = o[i]; } } })(this,function(){ var Solar = (function(){ var _fromDate = function(date){ return _fromYmdHms(date.getFullYear(),date.getMonth()+1,date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds()); }; var _fromJulianDay = function(julianDay){ var d = Math.floor(julianDay + 0.5); var f = julianDay + 0.5 - d; var c; if (d >= 2299161) { c = Math.floor((d - 1867216.25) / 36524.25); d += 1 + c - Math.floor(c / 4); } d += 1524; var year = Math.floor((d - 122.1) / 365.25); d -= Math.floor(365.25 * year); var month = Math.floor(d / 30.601); d -= Math.floor(30.601 * month); var day = d; if (month > 13) { month -= 13; year -= 4715; } else { month -= 1; year -= 4716; } f *= 24; var hour = Math.floor(f); f -= hour; f *= 60; var minute = Math.floor(f); f -= minute; f *= 60; var second = Math.round(f); if(second>59){ second-=60; minute++; } if(minute>59){ minute-=60; hour++; } if(hour>23){ hour-=24; day+=1; } return _fromYmdHms(year,month,day,hour,minute,second); }; var _fromYmdHms = function(y,m,d,hour,minute,second){ var oy = y; var om = m; var od = d; var oh = hour; var oi = minute; var os = second; y *= 1; if(isNaN(y)){ throw new Error('wrong solar year '+oy); } m *= 1; if(isNaN(m)){ throw new Error('wrong solar month '+om); } d *= 1; if(isNaN(d)){ throw new Error('wrong solar day '+od); } hour *= 1; if(isNaN(hour)){ throw new Error('wrong hour '+oh); } minute *= 1; if(isNaN(minute)){ throw new Error('wrong minute '+oi); } second *= 1; if(isNaN(second)){ throw new Error('wrong second '+os); } if(1582===y && 10===m){ if(d>4&&d<15){ throw new Error('wrong solar year '+y+' month '+m+' day '+d); } } if(m<1||m>12){ throw new Error('wrong month ' + m); } if(d<1||d>31){ throw new Error('wrong day ' + d); } if(hour<0||hour>23){ throw new Error('wrong hour '+hour); } if(minute<0||minute>59){ throw new Error('wrong minute '+minute); } if(second<0||second>59){ throw new Error('wrong second '+second); } return { _p:{ year:y, month:m, day:d, hour:hour, minute:minute, second:second }, subtract:function(solar){ return SolarUtil.getDaysBetween(solar.getYear(), solar.getMonth(), solar.getDay(), this._p.year, this._p.month, this._p.day); }, subtractMinute:function(solar){ var days = this.subtract(solar); var cm = this._p.hour * 60 + this._p.minute; var sm = solar.getHour() * 60 + solar.getMinute(); var m = cm - sm; if (m < 0) { m += 1440; days--; } m += days * 1440; return m; }, isAfter: function(solar) { if (this._p.year > solar.getYear()) { return true; } if (this._p.year < solar.getYear()) { return false; } if (this._p.month > solar.getMonth()) { return true; } if (this._p.month < solar.getMonth()) { return false; } if (this._p.day > solar.getDay()) { return true; } if (this._p.day < solar.getDay()) { return false; } if (this._p.hour > solar.getHour()) { return true; } if (this._p.hour < solar.getHour()) { return false; } if (this._p.minute > solar.getMinute()) { return true; } if (this._p.minute < solar.getMinute()) { return false; } return this._p.second > solar.getSecond(); }, isBefore: function(solar) { if (this._p.year > solar.getYear()) { return false; } if (this._p.year < solar.getYear()) { return true; } if (this._p.month > solar.getMonth()) { return false; } if (this._p.month < solar.getMonth()) { return true; } if (this._p.day > solar.getDay()) { return false; } if (this._p.day < solar.getDay()) { return true; } if (this._p.hour > solar.getHour()) { return false; } if (this._p.hour < solar.getHour()) { return true; } if (this._p.minute > solar.getMinute()) { return false; } if (this._p.minute < solar.getMinute()) { return true; } return this._p.second < solar.getSecond(); }, 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; }, getWeek:function(){ return (Math.floor(this.getJulianDay() + 0.5) + 7000001) % 7; }, getWeekInChinese:function(){ return SolarUtil.WEEK[this.getWeek()]; }, /** * 获取当天的阳历周 * @param start 星期几作为一周的开始,1234560分别代表星期一至星期天 */ getSolarWeek:function(start){ return SolarWeek.fromYmd(this._p.year, this._p.month, this._p.day, start); }, isLeapYear:function(){ return SolarUtil.isLeapYear(this._p.year); }, getFestivals:function(){ var l = []; var f = SolarUtil.FESTIVAL[this._p.month+'-'+this._p.day]; if(f){ l.push(f); } var weeks = Math.ceil(this._p.day/7); var week = this.getWeek(); f = SolarUtil.WEEK_FESTIVAL[this._p.month+'-'+weeks+'-'+week]; if(f){ l.push(f); } if (this._p.day + 7 > SolarUtil.getDaysOfMonth(this._p.year, this._p.month)) { f = SolarUtil.WEEK_FESTIVAL[this._p.month + '-0-' + week]; if (f) { l.push(f); } } return l; }, getOtherFestivals:function(){ var l=[]; var fs=SolarUtil.OTHER_FESTIVAL[this._p.month+'-'+this._p.day]; if(fs){ l=l.concat(fs); } return l; }, getXingzuo:function(){ return this.getXingZuo(); }, getXingZuo:function(){ var index = 11; var y = this._p.month*100+this._p.day; if (y >= 321 && y <= 419) { index = 0; } else if (y >= 420 && y <= 520) { index = 1; } else if (y >= 521 && y <= 621) { index = 2; } else if (y >= 622 && y <= 722) { index = 3; } else if (y >= 723 && y <= 822) { index = 4; } else if (y >= 823 && y <= 922) { index = 5; } else if (y >= 923 && y <= 1023) { index = 6; } else if (y >= 1024 && y <= 1122) { index = 7; } else if (y >= 1123 && y <= 1221) { index = 8; } else if (y >= 1222 || y <= 119) { index = 9; } else if (y <= 218) { index = 10; } return SolarUtil.XINGZUO[index]; }, toYmd:function(){ var m = this._p.month; var d = this._p.day; var y = this._p.year + ''; while (y.length < 4) { y = '0' + y; } return [y,(m<10?'0':'')+m,(d<10?'0':'')+d].join('-'); }, toYmdHms:function(){ return this.toYmd()+' '+[(this._p.hour<10?'0':'')+this._p.hour,(this._p.minute<10?'0':'')+this._p.minute,(this._p.second<10?'0':'')+this._p.second].join(':'); }, toString:function(){ return this.toYmd(); }, toFullString:function(){ var s = this.toYmdHms(); if(this.isLeapYear()){ s += ' 闰年'; } s += ' 星期'+this.getWeekInChinese(); var festivals = this.getFestivals(); for(var i=0,j=festivals.length;i<j;i++){ s += ' ('+festivals[i]+')'; } s += ' '+this.getXingZuo()+'座'; return s; }, nextYear:function(years){ var oy = years; years *= 1; if (isNaN(years)) { throw new Error('wrong years ' + oy); } var y = this._p.year + years; var m = this._p.month; var d = this._p.day; if (1582 === y && 10 === m) { if (d > 4 && d < 15) { d += 10; } } else if (2 === m) { if (d > 28) { if (!SolarUtil.isLeapYear(y)) { d = 28; } } } return _fromYmdHms(y, m, d, this._p.hour, this._p.minute, this._p.second); }, nextMonth:function(months){ var om = months; months *= 1; if (isNaN(months)) { throw new Error('wrong months ' + om); } var month = SolarMonth.fromYm(this._p.year, this._p.month).next(months); var y = month.getYear(); var m = month.getMonth(); var d = this._p.day; if (1582 === y && 10 === m) { if (d > 4 && d < 15) { d += 10; } } else { var maxDay = SolarUtil.getDaysOfMonth(y, m); if (d > maxDay) { d = maxDay; } } return _fromYmdHms(y, m, d, this._p.hour, this._p.minute, this._p.second); }, nextDay:function(days){ var od = days; days *= 1; if (isNaN(days)) { throw new Error('wrong days ' + od); } var y = this._p.year; var m = this._p.month; var d = this._p.day; if (1582 === y && 10 === m) { if (d > 4) { d -= 10 } } if (days > 0) { d += days; var daysInMonth = SolarUtil.getDaysOfMonth(y, m); while (d > daysInMonth) { d -= daysInMonth; m++; if (m > 12) { m = 1; y++; } daysInMonth = SolarUtil.getDaysOfMonth(y, m); } } else if (days < 0) { while (d + days <= 0) { m--; if (m < 1) { m = 12; y--; } d += SolarUtil.getDaysOfMonth(y, m); } d += days; } if (1582 === y && 10 === m) { if (d > 4) { d += 10; } } return _fromYmdHms(y, m, d, this._p.hour, this._p.minute, this._p.second); }, nextWorkday:function(days){ var od = days; days *= 1; if (isNaN(days)) { throw new Error('wrong days ' + od); } var solar = _fromYmdHms(this._p.year, this._p.month, this._p.day, this._p.hour, this._p.minute, this._p.second); if (days !== 0) { var rest = Math.abs(days); var add = days < 1 ? -1 : 1; while (rest > 0) { solar = solar.next(add); var work = true; var holiday = HolidayUtil.getHoliday(solar.getYear(), solar.getMonth(), solar.getDay()); if (!holiday) { var week = solar.getWeek(); if (0 === week || 6 === week) { work = false; } } else { work = holiday.isWork(); } if (work) { rest -= 1; } } } return solar; }, next:function(days, onlyWorkday){ if (onlyWorkday) { return this.nextWorkday(days); } return this.nextDay(days); }, nextHour:function(hours){ var oh = hours; hours *= 1; if (isNaN(hours)) { throw new Error('wrong hours ' + oh); } var h = this._p.hour + hours; var n = h < 0 ? -1 : 1; var hour = Math.abs(h); var days = Math.floor(hour / 24) * n; hour = (hour % 24) * n; if (hour < 0) { hour += 24; days--; } var solar = this.next(days); return _fromYmdHms(solar.getYear(), solar.getMonth(), solar.getDay(), hour, solar.getMinute(), solar.getSecond()); }, getLunar:function(){ return Lunar.fromSolar(this); }, getJulianDay:function(){ var y = this._p.year; var m = this._p.month; var d = this._p.day + ((this._p.second / 60 + this._p.minute) / 60 + this._p.hour) / 24; var n = 0; var g = false; if (y * 372 + m * 31 + Math.floor(d) >= 588829) { g = true; } if (m <= 2) { m += 12; y--; } if (g) { n = Math.floor(y / 100); n = 2 - n + Math.floor(n / 4); } return Math.floor(365.25 * (y + 4716)) + Math.floor(30.6001 * (m + 1)) + d + n - 1524.5; }, getSalaryRate:function(){ // 元旦节 if (this._p.month === 1 && this._p.day === 1) { return 3; } // 劳动节 if (this._p.month === 5 && this._p.day === 1) { return 3; } // 国庆 if (this._p.month === 10 && this._p.day >= 1 && this._p.day <= 3) { return 3; } var lunar = this.getLunar(); // 春节 if (lunar.getMonth() === 1 && lunar.getDay() >= 1 && lunar.getDay() <= 3) { return 3; } // 端午 if (lunar.getMonth() === 5 && lunar.getDay() === 5) { return 3; } // 中秋 if (lunar.getMonth() === 8 && lunar.getDay() === 15) { return 3; } // 清明 if ('清明' === lunar.getJieQi()) { return 3; } var holiday = HolidayUtil.getHoliday(this._p.year, this._p.month, this._p.day); if (holiday) { // 法定假日非上班 if (!holiday.isWork()) { return 2; } } else { // 周末 var week = this.getWeek(); if (week === 6 || week === 0) { return 2; } } // 工作日 return 1; } }; }; var _fromBaZi=function(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi,sect,baseYear){ sect *= 1; if(isNaN(sect)){ sect = 2; } if (1 !== sect) { sect = 2; } baseYear *= 1; if(isNaN(baseYear)){ baseYear = 1900; } var l = []; // 月地支距寅月的偏移值 var m = LunarUtil.index(monthGanZhi.substring(1), LunarUtil.ZHI, -1) - 2; if (m < 0) { m += 12; } // 月天干要一致 if (((LunarUtil.index(yearGanZhi.substring(0, 1), LunarUtil.GAN, -1) + 1) * 2 + m) % 10 !== LunarUtil.index(monthGanZhi.substring(0,1), LunarUtil.GAN, -1)) { return l; } // 1年的立春是辛酉,序号57 var y = LunarUtil.getJiaZiIndex(yearGanZhi) - 57; if (y < 0) { y += 60; } y++; // 节令偏移值 m *= 2; // 时辰地支转时刻,子时按零点算 var h = LunarUtil.index(timeGanZhi.substring(1), LunarUtil.ZHI, -1) * 2; var hours = [h]; if (0 === h && 2 === sect) { hours = [0, 23]; } var startYear = baseYear - 1; // 结束年 var endYear = new Date().getFullYear(); while (y <= endYear) { if (y >= startYear) { // 立春为寅月的开始 var jieQiLunar = Lunar.fromYmd(y, 1, 1); var jieQiList = jieQiLunar.getJieQiList(); var jieQiTable = jieQiLunar.getJieQiTable(); // 节令推移,年干支和月干支就都匹配上了 var solarTime = jieQiTable[jieQiList[4 + m]]; if (solarTime.getYear() >= baseYear) { // 日干支和节令干支的偏移值 var d = LunarUtil.getJiaZiIndex(dayGanZhi) - LunarUtil.getJiaZiIndex(solarTime.getLunar().getDayInGanZhiExact2()); if (d < 0) { d += 60; } if (d > 0) { // 从节令推移天数 solarTime = solarTime.next(d); } for (var i = 0, j = hours.length; i < j; i++) { var hour = hours[i]; var mi = 0; var s = 0; if (d === 0 && hour === solarTime.getHour()) { // 如果正好是节令当天,且小时和节令的小时数相等的极端情况,把分钟和秒钟带上 mi = solarTime.getMinute(); s = solarTime.getSecond(); } // 验证一下 var solar = Solar.fromYmdHms(solarTime.getYear(), solarTime.getMonth(), solarTime.getDay(), hour, mi, s); var lunar = solar.getLunar(); var dgz = (2 === sect) ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact(); if (lunar.getYearInGanZhiExact() === yearGanZhi && lunar.getMonthInGanZhiExact() === monthGanZhi && dgz === dayGanZhi && lunar.getTimeInGanZhi() === timeGanZhi) { l.push(solar); } } } } y += 60; } return l; }; return { J2000:2451545, fromYmd:function(y,m,d){return _fromYmdHms(y,m,d,0,0,0);}, fromYmdHms:function(y,m,d,hour,minute,second){return _fromYmdHms(y,m,d,hour,minute,second);}, fromDate:function(date){return _fromDate(date);}, fromJulianDay:function(julianDay){return _fromJulianDay(julianDay);}, fromBaZi:function(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi,sect,baseYear){return _fromBaZi(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi,sect,baseYear);} }; })(); var Lunar = (function(){ var _computeJieQi = function(o,ly) { o['jieQiList'] = []; o['jieQi'] = {}; var julianDays = ly.getJieQiJulianDays(); for (var i = 0, j = LunarUtil.JIE_QI_IN_USE.length; i < j; i++) { var key = LunarUtil.JIE_QI_IN_USE[i]; o['jieQiList'].push(key); o['jieQi'][key] = Solar.fromJulianDay(julianDays[i]); } }; var _computeYear = function(o,solar,year){ //以正月初一开始 var offset = year - 4; var yearGanIndex = offset % 10; var yearZhiIndex = offset % 12; if (yearGanIndex < 0) { yearGanIndex += 10; } if (yearZhiIndex < 0) { yearZhiIndex += 12; } //以立春作为新一年的开始的干支纪年 var g = yearGanIndex; var z = yearZhiIndex; //精确的干支纪年,以立春交接时刻为准 var gExact = yearGanIndex; var zExact = yearZhiIndex; var solarYear = solar.getYear(); var solarYmd = solar.toYmd(); var solarYmdHms = solar.toYmdHms(); //获取立春的阳历时刻 var liChun = o['jieQi'][I18n.getMessage('jq.liChun')]; if (liChun.getYear() !== solarYear) { liChun = o['jieQi']['LI_CHUN']; } var liChunYmd = liChun.toYmd(); var liChunYmdHms = liChun.toYmdHms(); //阳历和阴历年份相同代表正月初一及以后 if(year===solarYear){ //立春日期判断 if(solarYmd<liChunYmd) { g--; z--; } //立春交接时刻判断 if(solarYmdHms<liChunYmdHms) { gExact--; zExact--; } }else if (year < solarYear){ if(solarYmd>=liChunYmd) { g++; z++; } if(solarYmdHms>=liChunYmdHms) { gExact++; zExact++; } } o['yearGanIndex'] = yearGanIndex; o['yearZhiIndex'] = yearZhiIndex; o['yearGanIndexByLiChun'] = (g<0?g+10:g)%10; o['yearZhiIndexByLiChun'] = (z<0?z+12:z)%12; o['yearGanIndexExact'] = (gExact<0?gExact+10:gExact)%10; o['yearZhiIndexExact'] = (zExact<0?zExact+12:zExact)%12; }; var _computeMonth = function(o,solar){ var start = null; var i; var end; var size = LunarUtil.JIE_QI_IN_USE.length; //序号:大雪以前-3,大雪到小寒之间-2,小寒到立春之间-1,立春之后0 var index = -3; for(i=0;i<size;i+=2){ end = o.jieQi[LunarUtil.JIE_QI_IN_USE[i]]; var ymd = solar.toYmd(); var symd = null==start?ymd:start.toYmd(); if(ymd>=symd&&ymd<end.toYmd()){ break; } start = end; index++; } var offset = (((o.yearGanIndexByLiChun+(index<0?1:0)) % 5 + 1) * 2) % 10; o['monthGanIndex'] = ((index<0?index+10:index) + offset) % 10; o['monthZhiIndex'] = ((index<0?index+12:index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12; start = null; index = -3; for(i=0;i<size;i+=2){ end = o.jieQi[LunarUtil.JIE_QI_IN_USE[i]]; var time = solar.toYmdHms(); var stime = null==start?time:start.toYmdHms(); if(time>=stime&&time<end.toYmdHms()){ break; } start = end; index++; } offset = (((o.yearGanIndexExact+(index<0?1:0)) % 5 + 1) * 2) % 10; o['monthGanIndexExact'] = ((index<0?index+10:index) + offset) % 10; o['monthZhiIndexExact'] = ((index<0?index+12:index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12; }; var _computeDay = function(o,solar,hour,minute){ var noon = Solar.fromYmdHms(solar.getYear(), solar.getMonth(), solar.getDay(), 12, 0, 0); var offset = Math.floor(noon.getJulianDay()) - 11; var dayGanIndex = offset % 10; var dayZhiIndex = offset % 12; o['dayGanIndex'] = dayGanIndex; o['dayZhiIndex'] = dayZhiIndex; var dayGanExact = dayGanIndex; var dayZhiExact = dayZhiIndex; o['dayGanIndexExact2'] = dayGanExact; o['dayZhiIndexExact2'] = dayZhiExact; var hm = (hour<10?'0':'')+hour+':'+(minute<10?'0':'')+minute; if(hm>='23:00'&&hm<='23:59'){ dayGanExact++; if(dayGanExact>=10){ dayGanExact -= 10; } dayZhiExact++; if(dayZhiExact>=12){ dayZhiExact -= 12; } } o['dayGanIndexExact'] = dayGanExact; o['dayZhiIndexExact'] = dayZhiExact; }; var _computeTime = function(o,hour,minute){ var timeZhiIndex = LunarUtil.getTimeZhiIndex((hour<10?'0':'')+hour+':'+(minute<10?'0':'')+minute); o['timeZhiIndex'] = timeZhiIndex; o['timeGanIndex'] = (o['dayGanIndexExact']%5*2+timeZhiIndex)%10; }; var _computeWeek = function(o,solar){ o['weekIndex'] = solar.getWeek(); }; var _compute = function(year,hour,minute,second,solar,ly){ var o = {}; _computeJieQi(o, ly); _computeYear(o, solar, year); _computeMonth(o, solar); _computeDay(o, solar, hour, minute); _computeTime(o, hour, minute); _computeWeek(o, solar); return o; }; var _fromSolar = function(solar){ var lunarYear = 0; var lunarMonth = 0; var lunarDay = 0; var ly = LunarYear.fromYear(solar.getYear()); var lms = ly.getMonths(); for (var i = 0, j = lms.length; i < j; i++) { var m = lms[i]; var days = solar.subtract(Solar.fromJulianDay(m.getFirstJulianDay())); if (days < m.getDayCount()) { lunarYear = m.getYear(); lunarMonth = m.getMonth(); lunarDay = days + 1; break; } } return _new(lunarYear, lunarMonth, lunarDay, solar.getHour(), solar.getMinute(), solar.getSecond(), solar, ly); }; var _fromDate = function(date){ return _fromSolar(Solar.fromDate(date)); }; var _fromYmdHms = function(lunarYear,lunarMonth,lunarDay,hour,minute,second) { var oy = lunarYear; var om = lunarMonth; var od = lunarDay; var oh = hour; var oi = minute; var os = second; lunarYear *= 1; if(isNaN(lunarYear)){ throw new Error('wrong lunar year '+oy); } lunarMonth *= 1; if(isNaN(lunarMonth)){ throw new Error('wrong lunar month '+om); } lunarDay *= 1; if(isNaN(lunarDay)){ throw new Error('wrong lunar day '+od); } hour *= 1; if(isNaN(hour)){ throw new Error('wrong hour '+oh); } minute *= 1; if(isNaN(minute)){ throw new Error('wrong minute '+oi); } second *= 1; if(isNaN(second)){ throw new Error('wrong second '+os); } if(hour<0||hour>23){ throw new Error('wrong hour '+hour); } if(minute<0||minute>59){ throw new Error('wrong minute '+minute); } if(second<0||second>59){ throw new Error('wrong second '+second); } var y = LunarYear.fromYear(lunarYear); var m = y.getMonth(lunarMonth); if (null == m) { throw new Error('wrong lunar year '+lunarYear+' month '+lunarMonth); } if (lunarDay < 1) { throw new Error('lunar day must bigger than 0'); } var days = m.getDayCount(); if (lunarDay > days) { throw new Error('only '+days+' days in lunar year '+lunarYear+' month '+lunarMonth); } var noon = Solar.fromJulianDay(m.getFirstJulianDay() + lunarDay - 1); var solar = Solar.fromYmdHms(noon.getYear(), noon.getMonth(), noon.getDay(), hour, minute, second); if (noon.getYear() !== lunarYear) { y = LunarYear.fromYear(noon.getYear()); } return _new(lunarYear, lunarMonth, lunarDay, hour, minute, second, solar, y); }; var _new = function(year,month,day,hour,minute,second,solar,ly){ var gz = _compute(year,hour,minute,second,solar,ly); return { _p:{ lang: I18n.getLanguage(), year:year, month:month, day:day, hour:hour, minute:minute, second:second, timeGanIndex:gz.timeGanIndex, timeZhiIndex:gz.timeZhiIndex, dayGanIndex:gz.dayGanIndex, dayZhiIndex:gz.dayZhiIndex, dayGanIndexExact:gz.dayGanIndexExact, dayZhiIndexExact:gz.dayZhiIndexExact, dayGanIndexExact2:gz.dayGanIndexExact2, dayZhiIndexExact2:gz.dayZhiIndexExact2, monthGanIndex:gz.monthGanIndex, monthZhiIndex:gz.monthZhiIndex, monthGanIndexExact:gz.monthGanIndexExact, monthZhiIndexExact:gz.monthZhiIndexExact, yearGanIndex:gz.yearGanIndex, yearZhiIndex:gz.yearZhiIndex, yearGanIndexByLiChun:gz.yearGanIndexByLiChun, yearZhiIndexByLiChun:gz.yearZhiIndexByLiChun, yearGanIndexExact:gz.yearGanIndexExact, yearZhiIndexExact:gz.yearZhiIndexExact, weekIndex:gz.weekIndex, jieQi:gz.jieQi, jieQiList:gz.jieQiList, 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;}, getDayGanIndex:function(){return this._p.dayGanIndex;}, getDayGanIndexExact:function(){return this._p.dayGanIndexExact;}, getDayGanIndexExact2:function(){return this._p.dayGanIndexExact2;}, getDayZhiIndex:function(){return this._p.dayZhiIndex;}, getDayZhiIndexExact:function(){return this._p.dayZhiIndexExact;}, getDayZhiIndexExact2:function(){return this._p.dayZhiIndexExact2;}, getMonthGanIndex:function(){return this._p.monthGanIndex;}, getMonthGanIndexExact:function(){return this._p.monthGanIndexExact;}, getMonthZhiIndex:function(){return this._p.monthZhiIndex;}, getMonthZhiIndexExact:function(){return this._p.monthZhiIndexExact;}, getYearGanIndex:function(){return this._p.yearGanIndex;}, getYearGanIndexByLiChun:function(){return this._p.yearGanIndexByLiChun;}, getYearGanIndexExact:function(){return this._p.yearGanIndexExact;}, getYearZhiIndex:function(){return this._p.yearZhiIndex;}, getYearZhiIndexByLiChun:function(){return this._p.yearZhiIndexByLiChun;}, getYearZhiIndexExact:function(){return this._p.yearZhiIndexExact;}, getGan:function(){return this.getYearGan();}, getZhi:function(){return this.getYearZhi();}, getYearGan:function(){return LunarUtil.GAN[this._p.yearGanIndex+1];}, getYearGanByLiChun:function(){return LunarUtil.GAN[this._p.yearGanIndexByLiChun+1];}, getYearGanExact:function(){return LunarUtil.GAN[this._p.yearGanIndexExact+1];}, getYearZhi:function(){return LunarUtil.ZHI[this._p.yearZhiIndex+1];}, getYearZhiByLiChun:function(){return LunarUtil.ZHI[this._p.yearZhiIndexByLiChun+1];}, getYearZhiExact:function(){return LunarUtil.ZHI[this._p.yearZhiIndexExact+1];}, getYearInGanZhi:function(){return this.getYearGan()+this.getYearZhi();}, getYearInGanZhiByLiChun:function(){return this.getYearGanByLiChun()+this.getYearZhiByLiChun();}, getYearInGanZhiExact:function(){return this.getYearGanExact()+this.getYearZhiExact();}, getMonthGan:function(){return LunarUtil.GAN[this._p.monthGanIndex+1];}, getMonthGanExact:function(){return LunarUtil.GAN[this._p.monthGanIndexExact+1];}, getMonthZhi:function(){return LunarUtil.ZHI[this._p.monthZhiIndex+1];}, getMonthZhiExact:function(){return LunarUtil.ZHI[this._p.monthZhiIndexExact+1];}, getMonthInGanZhi:function(){return this.getMonthGan()+this.getMonthZhi();}, getMonthInGanZhiExact:function(){return this.getMonthGanExact()+this.getMonthZhiExact();}, getDayGan:function(){return LunarUtil.GAN[this._p.dayGanIndex+1];}, getDayGanExact:function(){return LunarUtil.GAN[this._p.dayGanIndexExact+1];}, getDayGanExact2:function(){return LunarUtil.GAN[this._p.dayGanIndexExact2+1];}, getDayZhi:function(){return LunarUtil.ZHI[this._p.dayZhiIndex+1];}, getDayZhiExact:function(){return LunarUtil.ZHI[this._p.dayZhiIndexExact+1];}, getDayZhiExact2:function(){return LunarUtil.ZHI[this._p.dayZhiIndexExact2+1];}, getDayInGanZhi:function(){return this.getDayGan()+this.getDayZhi();}, getDayInGanZhiExact:function(){return this.getDayGanExact()+this.getDayZhiExact();}, getDayInGanZhiExact2:function(){return this.getDayGanExact2()+this.getDayZhiExact2();}, getTimeGan:function(){return LunarUtil.GAN[this._p.timeGanIndex+1];}, getTimeZhi:function(){return LunarUtil.ZHI[this._p.timeZhiIndex+1];}, getTimeInGanZhi:function(){return this.getTimeGan()+this.getTimeZhi();}, getShengxiao:function(){return this.getYearShengXiao();}, getYearShengXiao:function(){return LunarUtil.SHENGXIAO[this._p.yearZhiIndex+1];}, getYearShengXiaoByLiChun:function(){return LunarUtil.SHENGXIAO[this._p.yearZhiIndexByLiChun+1];}, getYearShengXiaoExact:function(){return LunarUtil.SHENGXIAO[this._p.yearZhiIndexExact+1];}, getMonthShengXiao:function(){return LunarUtil.SHENGXIAO[this._p.monthZhiIndex+1];}, getMonthShengXiaoExact:function(){return LunarUtil.SHENGXIAO[this._p.monthZhiIndexExact+1];}, getDayShengXiao:function(){return LunarUtil.SHENGXIAO[this._p.dayZhiIndex+1];}, getTimeShengXiao:function(){return LunarUtil.SHENGXIAO[this._p.timeZhiIndex+1];}, getYearInChinese:function(){ var y = this._p.year+''; var s = ''; var zero = '0'.charCodeAt(0); for(var i=0,j=y.length;i<j;i++){ s+=LunarUtil.NUMBER[y.charCodeAt(i)-zero]; } return s; }, getMonthInChinese:function(){ var month = this._p.month; return (month<0?'闰':'')+LunarUtil.MONTH[Math.abs(month)]; }, getDayInChinese:function(){ return LunarUtil.DAY[this._p.day]; }, getPengZuGan:function(){ return LunarUtil.PENGZU_GAN[this._p.dayGanIndex+1]; }, getPengZuZhi:function(){ return LunarUtil.PENGZU_ZHI[this._p.dayZhiIndex+1]; }, getPositionXi:function(){ return this.getDayPositionXi(); }, getPositionXiDesc:function(){ return this.getDayPositionXiDesc(); }, getPositionYangGui:function(){ return this.getDayPositionYangGui(); }, getPositionYangGuiDesc:function(){ return this.getDayPositionYangGuiDesc(); }, getPositionYinGui:function(){ return this.getDayPositionYinGui(); }, getPositionYinGuiDesc:function(){ return this.getDayPositionYinGuiDesc(); }, getPositionFu:function(){ return this.getDayPositionFu(); }, getPositionFuDesc:function(){ return this.getDayPositionFuDesc(); }, getPositionCai:function(){ return this.getDayPositionCai(); }, getPositionCaiDesc:function(){ return this.getDayPositionCaiDesc(); }, getDayPositionXi:function(){ return LunarUtil.POSITION_XI[this._p.dayGanIndex+1]; }, getDayPositionXiDesc:function(){ return LunarUtil.POSITION_DESC[this.getDayPositionXi()]; }, getDayPositionYangGui:function(){ return LunarUtil.POSITION_YANG_GUI[this._p.dayGanIndex+1]; }, getDayPositionYangGuiDesc:function(){ return LunarUtil.POSITION_DESC[this.getDayPositionYangGui()]; }, getDayPositionYinGui:function(){ return LunarUtil.POSITION_YIN_GUI[this._p.dayGanIndex+1]; }, getDayPositionYinGuiDesc:function(){ return LunarUtil.POSITION_DESC[this.getDayPositionYinGui()]; }, getDayPositionFu:function(sect){ return (1===sect?LunarUtil.POSITION_FU:LunarUtil.POSITION_FU_2)[this._p.dayGanIndex+1]; }, getDayPositionFuDesc:function(sect){ return LunarUtil.POSITION_DESC[this.getDayPositionFu(sect)]; }, getDayPositionCai:function(){ return LunarUtil.POSITION_CAI[this._p.dayGanIndex+1]; }, getDayPositionCaiDesc:function(){ return LunarUtil.POSITION_DESC[this.getDayPositionCai()]; }, getTimePositionXi:function(){ return LunarUtil.POSITION_XI[this._p.timeGanIndex+1]; }, getTimePositionXiDesc:function(){ return LunarUtil.POSITION_DESC[this.getTimePositionXi()]; }, getTimePositionYangGui:function(){ return LunarUtil.POSITION_YANG_GUI[this._p.timeGanIndex+1]; }, getTimePositionYangGuiDesc:function(){ return LunarUtil.POSITION_DESC[this.getTimePositionYangGui()]; }, getTimePositionYinGui:function(){ return LunarUtil.POSITION_YIN_GUI[this._p.timeGanIndex+1]; }, getTimePositionYinGuiDesc:function(){ return LunarUtil.POSITION_DESC[this.getTimePositionYinGui()]; }, getTimePositionFu:function(sect){ return (1===sect?LunarUtil.POSITION_FU:LunarUtil.POSITION_FU_2)[this._p.timeGanIndex+1]; }, getTimePositionFuDesc:function(sect){ return LunarUtil.POSITION_DESC[this.getTimePositionFu(sect)]; }, getTimePositionCai:function(){ return LunarUtil.POSITION_CAI[this._p.timeGanIndex+1]; }, getTimePositionCaiDesc:function(){ return LunarUtil.POSITION_DESC[this.getTimePositionCai()]; }, getDayPositionTaiSui:function(sect){ var dayInGanZhi; var yearZhiIndex; switch (sect) { case 1: dayInGanZhi = this.getDayInGanZhi(); yearZhiIndex = this._p.yearZhiIndex; break; case 3: dayInGanZhi = this.getDayInGanZhi(); yearZhiIndex = this._p.yearZhiIndexExact; break; default: dayInGanZhi = this.getDayInGanZhiExact2(); yearZhiIndex = this._p.yearZhiIndexByLiChun; } var p; if ([I18n.getMessage('jz.jiaZi'), I18n.getMessage('jz.yiChou'), I18n.getMessage('jz.bingYin'), I18n.getMessage('jz.dingMao'), I18n.getMessage('jz.wuChen'), I18n.getMessage('jz.jiSi')].join(',').indexOf(dayInGanZhi) > -1) { p = I18n.getMessage('bg.zhen'); } else if ([I18n.getMessage('jz.bingZi'), I18n.getMessage('jz.dingChou'), I18n.getMessage('jz.wuYin'), I18n.getMessage('jz.jiMao'), I18n.getMessage('jz.gengChen'), I18n.getMessage('jz.xinSi')].join(',').indexOf(dayInGanZhi) > -1) { p = I18n.getMessage('bg.li'); } else if ([I18n.getMessage('jz.wuZi'), I18n.getMessage('jz.jiChou'), I18n.getMessage('jz.gengYin'), I18n.getMessage('jz.xinMao'), I18n.getMessage('jz.renChen'), I18n.getMessage('jz.guiSi')].join(',').indexOf(dayInGanZhi) > -1) { p = I18n.getMessage('ps.center'); } else if ([I18n.getMessage('jz.gengZi'), I18n.getMessage('jz.xinChou'), I18n.getMessage('jz.renYin'), I18n.getMessage('jz.guiMao'), I18n.getMessage('jz.jiaChen'), I18n.getMessage('jz.yiSi')].join(',').indexOf(dayInGanZhi) > -1) { p = I18n.getMessage('bg.dui'); } else if ([I18n.getMessage('jz.renZi'), I18n.getMessage('jz.guiChou'), I18n.getMessage('jz.jiaYin'), I18n.getMessage('jz.yiMao'), I18n.getMessage('jz.bingChen'), I18n.getMessage('jz.dingSi')].join(',').indexOf(dayInGanZhi) > -1) { p = I18n.getMessage('bg.kan'); } else { p = LunarUtil.POSITION_TAI_SUI_YEAR[yearZhiIndex]; } return p; }, getDayPositionTaiSuiDesc:function(sect){ return LunarUtil.POSITION_DESC[this.getDayPositionTaiSui(sect)]; }, getMonthPositionTaiSui:function(sect){ var monthZhiIndex; var monthGanIndex; switch (sect) { case 3: monthZhiIndex = this._p.monthZhiIndexExact; monthGanIndex = this._p.monthGanIndexExact; break; default: monthZhiIndex = this._p.monthZhiIndex; monthGanIndex = this._p.monthGanIndex; } var m = monthZhiIndex - LunarUtil.BASE_MONTH_ZHI_INDEX; if (m < 0) { m += 12; } return [I18n.getMessage('bg.gen'), LunarUtil.POSITION_GAN[monthGanIndex], I18n.getMessage('bg.kun'), I18n.getMessage('bg.xun')][m % 4] }, getMonthPositionTaiSuiDesc:function(sect){ return LunarUtil.POSITION_DESC[this.getMonthPositionTaiSui(sect)]; }, getYearPositionTaiSui:function(sect){ var yearZhiIndex; switch (sect) { case 1: yearZhiIndex = this._p.yearZhiIndex; break; case 3: yearZhiIndex = this._p.yearZhiIndexExact; break; default: yearZhiIndex = this._p.yearZhiIndexByLiChun; } return LunarUtil.POSITION_TAI_SUI_YEAR[yearZhiIndex]; }, getYearPositionTaiSuiDesc:function(sect){ return LunarUtil.POSITION_DESC[this.getYearPositionTaiSui(sect)]; }, _checkLang:function(){ var lang = I18n.getLanguage(); if (this._p.lang !== lang) { for (var i = 0, j = LunarUtil.JIE_QI_IN_USE.length; i < j; i++) { var newKey = LunarUtil.JIE_QI_IN_USE[i]; var oldKey = this._p.jieQiList[i]; var value = this._p.jieQi[oldKey]; this._p.jieQiList[i] = newKey; this._p.jieQi[newKey] = value; } this._p.lang = lang; } }, _getJieQiSolar:function(name){ this._checkLang(); return this._p.jieQi[name]; }, getChong:function(){ return this.getDayChong(); }, getChongGan:function(){ return this.getDayChongGan(); }, getChongGanTie:function(){ return this.getDayChongGanTie(); }, getChongShengXiao:function(){ return this.getDayChongShengXiao(); }, getChongDesc:function(){ return this.getDayChongDesc(); }, getSha:function(){ return this.getDaySha(); }, getDayChong:function(){ return LunarUtil.CHONG[this._p.dayZhiIndex]; }, getDayChongGan:function(){ return LunarUtil.CHONG_GAN[this._p.dayGanIndex]; }, getDayChongGanTie:function(){ return LunarUtil.CHONG_GAN_TIE[this._p.dayGanIndex]; }, getDayChongShengXiao:function(){ var chong = this.getChong(); for(var i=0,j=LunarUtil.ZHI.length;i<j;i++){ if(LunarUtil.ZHI[i]===chong){ return LunarUtil.SHENGXIAO[i]; } } return ''; }, getDayChongDesc:function(){ return '('+this.getDayChongGan()+this.getDayChong()+')'+this.getDayChongShengXiao(); }, getDaySha:function(){ return LunarUtil.SHA[this.getDayZhi()]; }, getTimeChong:function(){ return LunarUtil.CHONG[this._p.timeZhiIndex]; }, getTimeChongGan:function(){ return LunarUtil.CHONG_GAN[this._p.timeGanIndex]; }, getTimeChongGanTie:function(){ return LunarUtil.CHONG_GAN_TIE[this._p.timeGanIndex]; }, getTimeChongShengXiao:function(){ var chong = this.getTimeChong(); for(var i=0,j=LunarUtil.ZHI.length;i<j;i++){ if(LunarUtil.ZHI[i]===chong){ return LunarUtil.SHENGXIAO[i]; } } return ''; }, getTimeChongDesc:function(){ return '('+this.getTimeChongGan()+this.getTimeChong()+')'+this.getTimeChongShengXiao(); }, getTimeSha:function(){ return LunarUtil.SHA[this.getTimeZhi()]; }, getYearNaYin:function(){ return LunarUtil.NAYIN[this.getYearInGanZhi()]; }, getMonthNaYin:function(){ return LunarUtil.NAYIN[this.getMonthInGanZhi()]; }, getDayNaYin:function(){ return LunarUtil.NAYIN[this.getDayInGanZhi()]; }, getTimeNaYin:function(){ return LunarUtil.NAYIN[this.getTimeInGanZhi()]; }, getSeason:function(){ return LunarUtil.SEASON[Math.abs(this._p.month)]; }, _convertJieQi:function(name){ var jq = name; if ('DONG_ZHI' === jq) { jq = I18n.getMessage('jq.dongZhi'); } else if ('DA_HAN' === jq) { jq = I18n.getMessage('jq.daHan'); } else if ('XIAO_HAN' === jq) { jq = I18n.getMessage('jq.xiaoHan'); } else if ('LI_CHUN' === jq) { jq = I18n.getMessage('jq.liChun'); } else if ('DA_XUE' === jq) { jq = I18n.getMessage('jq.daXue'); } else if ('YU_SHUI' === jq) { jq = I18n.getMessage('jq.yuShui'); } else if ('JING_ZHE' === jq) { jq = I18n.getMessage('jq.jingZhe'); } return jq; }, getJie:function(){ for(var i=0, j=LunarUtil.JIE_QI_IN_USE.length; i<j; i+=2){ var key = LunarUtil.JIE_QI_IN_USE[i]; var d = this._getJieQiSolar(key); if(d.getYear() === this._p.solar.getYear() && d.getMonth() === this._p.solar.getMonth() && d.getDay() === this._p.solar.getDay()){ return this._convertJieQi(key); } } return ''; }, getQi:function(){ for(var i=1, j=LunarUtil.JIE_QI_IN_USE.length; i<j; i+=2){ var key = LunarUtil.JIE_QI_IN_USE[i]; var d = this._getJieQiSolar(key); if(d.getYear() === this._p.solar.getYear() && d.getMonth() === this._p.solar.getMonth() && d.getDay() === this._p.solar.getDay()){ return this._convertJieQi(key); } } return ''; }, getJieQi:function(){ for(var key in this._p.jieQi){ var d = this._getJieQiSolar(key); if(d.getYear() === this._p.solar.getYear() && d.getMonth() === this._p.solar.getMonth() && d.getDay() === this._p.solar.getDay()){ return this._convertJieQi(key); } } return ''; }, getWeek:function(){ return this._p.weekIndex; }, getWeekInChinese:function(){ return SolarUtil.WEEK[this.getWeek()]; }, getXiu:function(){ return LunarUtil.XIU[this.getDayZhi()+this.getWeek()]; }, getXiuLuck:function(){ return LunarUtil.XIU_LUCK[this.getXiu()]; }, getXiuSong:function(){ return LunarUtil.XIU_SONG[this.getXiu()]; }, getZheng:function(){ return LunarUtil.ZHENG[this.getXiu()]; }, getAnimal:function(){ return LunarUtil.ANIMAL[this.getXiu()]; }, getGong:function(){ return LunarUtil.GONG[this.getXiu()]; }, getShou:function(){ return LunarUtil.SHOU[this.getGong()]; }, getFestivals:function(){ var l = []; var f = LunarUtil.FESTIVAL[this._p.month+'-'+this._p.day]; if(f){ l.push(f); } if (Math.abs(this._p.month) === 12 && this._p.day >= 29 && this._p.year !== this.next(1).getYear()) { l.push(I18n.getMessage('jr.chuXi')); } return l; }, getOtherFestivals:function(){ var l=[]; var fs=LunarUtil.OTHER_FESTIVAL[this._p.month+'-'+this._p.day]; if(fs){ l=l.concat(fs); } var solarYmd = this._p.solar.toYmd(); if(this._p.solar.toYmd() === this._getJieQiSolar(I18n.getMessage('jq.qingMing')).next(-1).toYmd()){ l.push('寒食节'); } var jq = this._getJieQiSolar(I18n.getMessage('jq.liChun')); var offset = 4 - jq.getLunar().getDayGanIndex(); if (offset < 0) { offset += 10; } if (solarYmd === jq.next(offset + 40).toYmd()) { l.push('春社'); } jq = this._getJieQiSolar(I18n.getMessage('jq.liQiu')); offset = 4 - jq.getLunar().getDayGanIndex(); if (offset < 0) { offset += 10; } if (solarYmd === jq.next(offset + 40).toYmd()) { l.push('秋社'); } return l; }, getBaZi:function(){ var bz = this.getEightChar(); var l = []; l.push(bz.getYear()); l.push(bz.getMonth()); l.push(bz.getDay()); l.push(bz.getTime()); return l; }, getBaZiWuXing:function(){ var bz = this.getEightChar(); var l = []; l.push(bz.getYearWuXing()); l.push(bz.getMonthWuXing()); l.push(bz.getDayWuXing()); l.push(bz.getTimeWuXing()); return l; }, getBaZiNaYin:function(){ var bz = this.getEightChar(); var l = []; l.push(bz.getYearNaYin()); l.push(bz.getMonthNaYin()); l.push(bz.getDayNaYin()); l.push(bz.getTimeNaYin()); return l; }, getBaZiShiShenGan:function(){ var bz = this.getEightChar(); var l = []; l.push(bz.getYearShiShenGan()); l.push(bz.getMonthShiShenGan()); l.push(bz.getDayShiShenGan()); l.push(bz.getTimeShiShenGan()); return l; }, getBaZiShiShenZhi:function(){ var bz = this.getEightChar(); var l = []; l.push(bz.getYearShiShenZhi()[0]); l.push(bz.getMonthShiShenZhi()[0]); l.push(bz.getDayShiShenZhi()[0]); l.push(bz.getTimeShiShenZhi()[0]); return l; }, getBaZiShiShenYearZhi:function(){ return this.getEightChar().getYearShiShenZhi(); }, getBaZiShiShenMonthZhi:function(){ return this.getEightChar().getMonthShiShenZhi(); }, getBaZiShiShenDayZhi:function(){ return this.getEightChar().getDayShiShenZhi(); }, getBaZiShiShenTimeZhi:function(){ return this.getEightChar().getTimeShiShenZhi(); }, getZhiXing:function(){ var offset = this._p.dayZhiIndex-this._p.monthZhiIndex; if(offset<0){ offset += 12; } return LunarUtil.ZHI_XING[offset+1]; }, getDayTianS