|
|
|
|
@@ -27,13 +27,7 @@
|
|
|
|
|
fromYmdHms:function(y,m,d,hour,minute,second){
|
|
|
|
|
return this._(new Date(y+'/'+m+'/'+d+' '+hour+':'+minute+':'+second),y,m,d);
|
|
|
|
|
},
|
|
|
|
|
getDaysBetween:function(date0, date1){
|
|
|
|
|
var ay = date0.getFullYear();
|
|
|
|
|
var by = date1.getFullYear();
|
|
|
|
|
var am = date0.getMonth() + 1;
|
|
|
|
|
var bm = date1.getMonth() + 1;
|
|
|
|
|
var ad = date0.getDate();
|
|
|
|
|
var bd = date1.getDate();
|
|
|
|
|
getDaysBetweenYmd:function(ay, am, ad, by, bm, bd){
|
|
|
|
|
var n;
|
|
|
|
|
var days;
|
|
|
|
|
var i;
|
|
|
|
|
@@ -55,6 +49,9 @@
|
|
|
|
|
n = days;
|
|
|
|
|
}
|
|
|
|
|
return n;
|
|
|
|
|
},
|
|
|
|
|
getDaysBetween:function(date0, date1){
|
|
|
|
|
return this.getDaysBetweenYmd(date0.getFullYear(), date0.getMonth() + 1, date0.getDate(), date1.getFullYear(), date1.getMonth() + 1, date1.getDate());
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
})();
|
|
|
|
|
@@ -304,7 +301,7 @@
|
|
|
|
|
if(offsetYear<0){
|
|
|
|
|
offsetYear = offsetYear+60;
|
|
|
|
|
}
|
|
|
|
|
var startYear = today.getYear() - offsetYear;
|
|
|
|
|
var startYear = lunar.getYear() - offsetYear;
|
|
|
|
|
var hour = 0;
|
|
|
|
|
var timeZhi = timeGanZhi.substr(1);
|
|
|
|
|
for(var i=0,j=LunarUtil.ZHI.length;i<j;i++){
|
|
|
|
|
@@ -366,7 +363,7 @@
|
|
|
|
|
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){return _fromBaZi(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi);}
|
|
|
|
|
fromBaZi:function(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi,sect,baseYear){return _fromBaZi(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi,sect,baseYear);}
|
|
|
|
|
};
|
|
|
|
|
})();
|
|
|
|
|
var Lunar = (function(){
|
|
|
|
|
@@ -527,22 +524,19 @@
|
|
|
|
|
return o;
|
|
|
|
|
};
|
|
|
|
|
var _fromDate = function(date){
|
|
|
|
|
var c = ExactDate.fromYmd(date.getFullYear(),date.getMonth()+1,date.getDate());
|
|
|
|
|
var currentYear = date.getFullYear();
|
|
|
|
|
var currentMonth = date.getMonth() + 1;
|
|
|
|
|
var currentDay = date.getDate();
|
|
|
|
|
var lunarYear = 0;
|
|
|
|
|
var lunarMonth = 0;
|
|
|
|
|
var lunarDay = 0;
|
|
|
|
|
var y = c.getFullYear();
|
|
|
|
|
var ly = LunarYear.fromYear(y);
|
|
|
|
|
var ly = LunarYear.fromYear(currentYear);
|
|
|
|
|
var lms = ly.getMonths();
|
|
|
|
|
for (var i = 0, j = lms.length; i < j; i++) {
|
|
|
|
|
var m = lms[i];
|
|
|
|
|
// 初一
|
|
|
|
|
var firstDay = Solar.fromJulianDay(m.getFirstJulianDay()).getCalendar();
|
|
|
|
|
firstDay.setHours(0);
|
|
|
|
|
firstDay.setMinutes(0);
|
|
|
|
|
firstDay.setSeconds(0);
|
|
|
|
|
firstDay.setMilliseconds(0);
|
|
|
|
|
var days = ExactDate.getDaysBetween(firstDay, c);
|
|
|
|
|
var firstDay = Solar.fromJulianDay(m.getFirstJulianDay());
|
|
|
|
|
var days = ExactDate.getDaysBetweenYmd(firstDay.getYear(), firstDay.getMonth(), firstDay.getDay(), currentYear, currentMonth, currentDay);
|
|
|
|
|
if (days < m.getDayCount()) {
|
|
|
|
|
lunarYear = m.getYear();
|
|
|
|
|
lunarMonth = m.getMonth();
|
|
|
|
|
@@ -776,9 +770,9 @@
|
|
|
|
|
getTimePositionCaiDesc:function(){
|
|
|
|
|
return LunarUtil.POSITION_DESC[this.getTimePositionCai()];
|
|
|
|
|
},
|
|
|
|
|
getDayPositionTaiSui:function(){
|
|
|
|
|
_getDayPositionTaiSui:function(dayInGanZhi, yearZhiIndex){
|
|
|
|
|
var p = '';
|
|
|
|
|
switch (this.getDayInGanZhi()) {
|
|
|
|
|
switch (dayInGanZhi) {
|
|
|
|
|
case '甲子':
|
|
|
|
|
case '乙丑':
|
|
|
|
|
case '丙寅':
|
|
|
|
|
@@ -820,12 +814,91 @@
|
|
|
|
|
p = '坎';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
p = LunarYear.fromYear(this.getYear()).getPositionTaiSui();
|
|
|
|
|
p = LunarUtil.POSITION_TAI_SUI_YEAR[yearZhiIndex];
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
},
|
|
|
|
|
getDayPositionTaiSuiDesc:function(){
|
|
|
|
|
return LunarUtil.POSITION_DESC[this.getDayPositionTaiSui()];
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return this._getDayPositionTaiSui(dayInGanZhi, yearZhiIndex);
|
|
|
|
|
},
|
|
|
|
|
getDayPositionTaiSuiDesc:function(sect){
|
|
|
|
|
return LunarUtil.POSITION_DESC[this.getDayPositionTaiSui(sect)];
|
|
|
|
|
},
|
|
|
|
|
_getMonthPositionTaiSui:function(monthZhiIndex, monthGanIndex){
|
|
|
|
|
var p = '';
|
|
|
|
|
var m = monthZhiIndex - LunarUtil.BASE_MONTH_ZHI_INDEX;
|
|
|
|
|
if (m < 0) {
|
|
|
|
|
m += 12;
|
|
|
|
|
}
|
|
|
|
|
switch(m) {
|
|
|
|
|
case 0:
|
|
|
|
|
case 4:
|
|
|
|
|
case 8:
|
|
|
|
|
p = '艮';
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
case 6:
|
|
|
|
|
case 10:
|
|
|
|
|
p = '坤';
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
case 7:
|
|
|
|
|
case 11:
|
|
|
|
|
p = '巽';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
p = LunarUtil.POSITION_GAN[monthGanIndex];
|
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
},
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
return this._getMonthPositionTaiSui(monthZhiIndex, monthGanIndex);
|
|
|
|
|
},
|
|
|
|
|
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)];
|
|
|
|
|
},
|
|
|
|
|
getChong:function(){
|
|
|
|
|
return this.getDayChong();
|
|
|
|
|
@@ -1130,26 +1203,69 @@
|
|
|
|
|
getYueXiang:function(){
|
|
|
|
|
return LunarUtil.YUE_XIANG[this._p.day];
|
|
|
|
|
},
|
|
|
|
|
getYearNineStar:function(){
|
|
|
|
|
return LunarYear.fromYear(this._p.year).getNineStar();
|
|
|
|
|
_getYearNineStar:function(yearInGanZhi){
|
|
|
|
|
var index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
|
|
|
|
var yearOffset = 0;
|
|
|
|
|
if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
|
|
|
|
|
yearOffset = -1;
|
|
|
|
|
}
|
|
|
|
|
var n = 65;
|
|
|
|
|
var yuan = Math.floor((this._p.year + yearOffset + 2696) / 60) % 3;
|
|
|
|
|
switch(yuan){
|
|
|
|
|
case 2:
|
|
|
|
|
n = 68;
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
|
n = 62;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
}
|
|
|
|
|
var offset = (n - index) % 9;
|
|
|
|
|
if(0 === offset){
|
|
|
|
|
offset = 9;
|
|
|
|
|
}
|
|
|
|
|
return NineStar.fromIndex(offset - 1);
|
|
|
|
|
},
|
|
|
|
|
getMonthNineStar:function(){
|
|
|
|
|
var n = 12;
|
|
|
|
|
var yearZhi = this.getYearZhi();
|
|
|
|
|
if ('子午卯酉'.indexOf(yearZhi)>-1) {
|
|
|
|
|
n = 18;
|
|
|
|
|
} else if ('辰戌丑未'.indexOf(yearZhi)>-1) {
|
|
|
|
|
n = 15;
|
|
|
|
|
getYearNineStar:function(sect){
|
|
|
|
|
var yearInGanZhi;
|
|
|
|
|
switch (sect) {
|
|
|
|
|
case 1:
|
|
|
|
|
yearInGanZhi = this.getYearInGanZhi();
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
yearInGanZhi = this.getYearInGanZhiExact();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
yearInGanZhi = this.getYearInGanZhiByLiChun();
|
|
|
|
|
}
|
|
|
|
|
var m = this._p.month;
|
|
|
|
|
if(m<0){
|
|
|
|
|
m = -m;
|
|
|
|
|
return this._getYearNineStar(yearInGanZhi);
|
|
|
|
|
},
|
|
|
|
|
_getMonthNineStar:function(yearZhiIndex, monthZhiIndex){
|
|
|
|
|
var index = yearZhiIndex % 3;
|
|
|
|
|
var n = 27 - (index * 3);
|
|
|
|
|
if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX) {
|
|
|
|
|
n -= 3;
|
|
|
|
|
}
|
|
|
|
|
var offset = (n-m)%9;
|
|
|
|
|
if(0===offset){
|
|
|
|
|
offset=9;
|
|
|
|
|
var offset = (n - monthZhiIndex) % 9;
|
|
|
|
|
return NineStar.fromIndex(offset);
|
|
|
|
|
},
|
|
|
|
|
getMonthNineStar:function(sect){
|
|
|
|
|
var yearZhiIndex;
|
|
|
|
|
var monthZhiIndex;
|
|
|
|
|
switch (sect) {
|
|
|
|
|
case 1:
|
|
|
|
|
yearZhiIndex = this._p.yearZhiIndex;
|
|
|
|
|
monthZhiIndex = this._p.monthZhiIndex;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
yearZhiIndex = this._p.yearZhiIndexExact;
|
|
|
|
|
monthZhiIndex = this._p.monthZhiIndexExact;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
yearZhiIndex = this._p.yearZhiIndexByLiChun;
|
|
|
|
|
monthZhiIndex = this._p.monthZhiIndex;
|
|
|
|
|
}
|
|
|
|
|
return NineStar.fromIndex(offset-1);
|
|
|
|
|
return this._getMonthNineStar(yearZhiIndex, monthZhiIndex);
|
|
|
|
|
},
|
|
|
|
|
getDayNineStar:function(){
|
|
|
|
|
var solarYmd = this._p.solar.toYmd();
|
|
|
|
|
@@ -1159,9 +1275,9 @@
|
|
|
|
|
var dongZhiIndex = LunarUtil.getJiaZiIndex(dongZhi.getLunar().getDayInGanZhi());
|
|
|
|
|
var dongZhiIndex2 = LunarUtil.getJiaZiIndex(dongZhi2.getLunar().getDayInGanZhi());
|
|
|
|
|
var xiaZhiIndex = LunarUtil.getJiaZiIndex(xiaZhi.getLunar().getDayInGanZhi());
|
|
|
|
|
var solarShunBai = null;
|
|
|
|
|
var solarShunBai2 = null;
|
|
|
|
|
var solarNiZi = null;
|
|
|
|
|
var solarShunBai;
|
|
|
|
|
var solarShunBai2;
|
|
|
|
|
var solarNiZi;
|
|
|
|
|
if (dongZhiIndex>29) {
|
|
|
|
|
solarShunBai = dongZhi.next(60 - dongZhiIndex);
|
|
|
|
|
} else {
|
|
|
|
|
@@ -1206,8 +1322,7 @@
|
|
|
|
|
start = asc ? 3 : 5;
|
|
|
|
|
}
|
|
|
|
|
var index = asc ? start + this._p.timeZhiIndex : start + 9 - this._p.timeZhiIndex;
|
|
|
|
|
var offset = index % 9;
|
|
|
|
|
return NineStar.fromIndex(offset);
|
|
|
|
|
return NineStar.fromIndex(index % 9);
|
|
|
|
|
},
|
|
|
|
|
getSolar:function(){
|
|
|
|
|
return this._p.solar;
|
|
|
|
|
@@ -2300,6 +2415,24 @@
|
|
|
|
|
getPositionTaiSuiDesc:function(){
|
|
|
|
|
return LunarUtil.POSITION_DESC[this.getPositionTaiSui()];
|
|
|
|
|
},
|
|
|
|
|
getMonthNineStar:function(){
|
|
|
|
|
var n = 12;
|
|
|
|
|
var yearZhi = LunarYear.fromYear(this._p.year).getZhi();
|
|
|
|
|
if ('子午卯酉'.indexOf(yearZhi)>-1) {
|
|
|
|
|
n = 18;
|
|
|
|
|
} else if ('辰戌丑未'.indexOf(yearZhi)>-1) {
|
|
|
|
|
n = 15;
|
|
|
|
|
}
|
|
|
|
|
var m = this._p.month;
|
|
|
|
|
if(m<0){
|
|
|
|
|
m = -m;
|
|
|
|
|
}
|
|
|
|
|
var offset = (n-m)%9;
|
|
|
|
|
if(0===offset){
|
|
|
|
|
offset=9;
|
|
|
|
|
}
|
|
|
|
|
return NineStar.fromIndex(offset-1);
|
|
|
|
|
},
|
|
|
|
|
toString:function(){return this.getYear()+'年'+(this.isLeap()?'闰':'')+LunarUtil.MONTH[Math.abs(this.getMonth())]+'月('+this.getDayCount()+')天';}
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
@@ -2577,6 +2710,9 @@
|
|
|
|
|
days += this.getDaysOfMonth(year, i);
|
|
|
|
|
}
|
|
|
|
|
days += day;
|
|
|
|
|
if (1582 === year && 10 === month && day >= 15) {
|
|
|
|
|
days -= 10;
|
|
|
|
|
}
|
|
|
|
|
return days;
|
|
|
|
|
},
|
|
|
|
|
getWeeksOfMonth:function(year,month,start){
|
|
|
|
|
|