Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66d16db39e | ||
|
|
98fb502c02 | ||
|
|
44a2b408cf |
@@ -31,3 +31,9 @@ test('test2', () => {
|
|||||||
const week = SolarWeek.fromYmd(2021, 5, 4, start);
|
const week = SolarWeek.fromYmd(2021, 5, 4, start);
|
||||||
expect(week.getIndex()).toBe(2);
|
expect(week.getIndex()).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test3', () => {
|
||||||
|
const start = 0;
|
||||||
|
const week = SolarWeek.fromYmd(2022, 3, 6, start);
|
||||||
|
expect(week.getIndexInYear()).toBe(11);
|
||||||
|
});
|
||||||
|
|||||||
@@ -77,3 +77,9 @@ test('test13', () => {
|
|||||||
const lunar = solar.getLunar();
|
const lunar = solar.getLunar();
|
||||||
expect(lunar.getHou()).toBe('小寒 初候');
|
expect(lunar.getHou()).toBe('小寒 初候');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test14', () => {
|
||||||
|
const solar = Solar.fromYmd(2022,5,20);
|
||||||
|
const lunar = solar.getLunar();
|
||||||
|
expect(lunar.getHou()).toBe('立夏 三候');
|
||||||
|
});
|
||||||
|
|||||||
@@ -31,3 +31,30 @@ it('test3', () => {
|
|||||||
expect(yun.getStartDay()).toBe(0);
|
expect(yun.getStartDay()).toBe(0);
|
||||||
expect(yun.getStartSolar().toYmd()).toBe('2020-02-06');
|
expect(yun.getStartSolar().toYmd()).toBe('2020-02-06');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('test4', () => {
|
||||||
|
const solar = Solar.fromYmdHms(2022, 3, 9, 20, 51, 0);
|
||||||
|
const lunar = solar.getLunar();
|
||||||
|
const eightChar = lunar.getEightChar();
|
||||||
|
const yun = eightChar.getYun(1);
|
||||||
|
expect(yun.getStartSolar().toYmd()).toBe('2030-12-19');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('test5', () => {
|
||||||
|
const solar = Solar.fromYmdHms(2022, 3, 9, 20, 51, 0);
|
||||||
|
const lunar = solar.getLunar();
|
||||||
|
const eightChar = lunar.getEightChar();
|
||||||
|
const yun = eightChar.getYun(1, 2);
|
||||||
|
expect(yun.getStartYear()).toBe(8);
|
||||||
|
expect(yun.getStartMonth()).toBe(9);
|
||||||
|
expect(yun.getStartDay()).toBe(2);
|
||||||
|
expect(yun.getStartSolar().toYmd()).toBe('2030-12-12');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('test6', () => {
|
||||||
|
const solar = Solar.fromYmdHms(2018, 6, 11, 9, 30, 0);
|
||||||
|
const lunar = solar.getLunar();
|
||||||
|
const eightChar = lunar.getEightChar();
|
||||||
|
const yun = eightChar.getYun(0, 2);
|
||||||
|
expect(yun.getStartSolar().toYmd()).toBe('2020-03-21');
|
||||||
|
});
|
||||||
|
|||||||
155
lunar.js
155
lunar.js
@@ -1174,11 +1174,11 @@
|
|||||||
}
|
}
|
||||||
return LunarUtil.POSITION_TAI_MONTH[m-1];
|
return LunarUtil.POSITION_TAI_MONTH[m-1];
|
||||||
},
|
},
|
||||||
getDayYi:function(){
|
getDayYi:function(sect){
|
||||||
return LunarUtil.getDayYi(this.getMonthInGanZhiExact(),this.getDayInGanZhi());
|
return LunarUtil.getDayYi(2 == sect ? this.getMonthInGanZhiExact() : this.getMonthInGanZhi(), this.getDayInGanZhi());
|
||||||
},
|
},
|
||||||
getDayJi:function(){
|
getDayJi:function(sect){
|
||||||
return LunarUtil.getDayJi(this.getMonthInGanZhiExact(),this.getDayInGanZhi());
|
return LunarUtil.getDayJi(2 == sect ? this.getMonthInGanZhiExact() : this.getMonthInGanZhi(), this.getDayInGanZhi());
|
||||||
},
|
},
|
||||||
getDayJiShen:function(){
|
getDayJiShen:function(){
|
||||||
return LunarUtil.getDayJiShen(this.getMonth(),this.getDayInGanZhi());
|
return LunarUtil.getDayJiShen(this.getMonth(),this.getDayInGanZhi());
|
||||||
@@ -1660,8 +1660,13 @@
|
|||||||
var jieQi = this.getPrevJieQi(true);
|
var jieQi = this.getPrevJieQi(true);
|
||||||
var name = jieQi.getName();
|
var name = jieQi.getName();
|
||||||
var startSolar = jieQi.getSolar();
|
var startSolar = jieQi.getSolar();
|
||||||
var days = days = ExactDate.getDaysBetweenYmd(startSolar.getYear(),startSolar.getMonth(),startSolar.getDay(), this._p.solar.getYear(),this._p.solar.getMonth(),this._p.solar.getDay());
|
var days = ExactDate.getDaysBetweenYmd(startSolar.getYear(),startSolar.getMonth(),startSolar.getDay(), this._p.solar.getYear(),this._p.solar.getMonth(),this._p.solar.getDay());
|
||||||
return name + ' ' + LunarUtil.HOU[(Math.floor(days/5)) % LunarUtil.HOU.length];
|
var max = LunarUtil.HOU.length - 1;
|
||||||
|
var offset = Math.floor(days / 5);
|
||||||
|
if (offset > max) {
|
||||||
|
offset = max;
|
||||||
|
}
|
||||||
|
return name + ' ' + LunarUtil.HOU[offset];
|
||||||
},
|
},
|
||||||
getDayLu:function(){
|
getDayLu:function(){
|
||||||
var gan = LunarUtil.LU[this.getDayGan()];
|
var gan = LunarUtil.LU[this.getDayGan()];
|
||||||
@@ -1730,6 +1735,19 @@
|
|||||||
}
|
}
|
||||||
return Math.ceil((this._p.day + offset)/7);
|
return Math.ceil((this._p.day + offset)/7);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 获取当前日期是在当年第几周
|
||||||
|
* @return number 周序号,从1开始
|
||||||
|
*/
|
||||||
|
getIndexInYear:function(){
|
||||||
|
var firstDate = ExactDate.fromYmd(this._p.year, 1, 1);
|
||||||
|
var firstDayWeek = firstDate.getDay();
|
||||||
|
var offset = firstDayWeek - this._p.start;
|
||||||
|
if(offset < 0) {
|
||||||
|
offset += 7;
|
||||||
|
}
|
||||||
|
return Math.ceil((SolarUtil.getDaysInYear(this._p.year, this._p.month, this._p.day) + offset)/7);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 周推移
|
* 周推移
|
||||||
* @param weeks 推移的周数,负数为倒推
|
* @param weeks 推移的周数,负数为倒推
|
||||||
@@ -2266,6 +2284,9 @@
|
|||||||
toFullString:function(){
|
toFullString:function(){
|
||||||
return this.getYear()+'年';
|
return this.getYear()+'年';
|
||||||
},
|
},
|
||||||
|
next:function(n){
|
||||||
|
return LunarYear.fromYear(this._p.year + n);
|
||||||
|
},
|
||||||
_compute:function(){
|
_compute:function(){
|
||||||
this._p.months = [];
|
this._p.months = [];
|
||||||
this._p.jieQiJulianDays = [];
|
this._p.jieQiJulianDays = [];
|
||||||
@@ -2420,6 +2441,65 @@
|
|||||||
var offset = (n - monthZhiIndex) % 9;
|
var offset = (n - monthZhiIndex) % 9;
|
||||||
return NineStar.fromIndex(offset);
|
return NineStar.fromIndex(offset);
|
||||||
},
|
},
|
||||||
|
next:function(n){
|
||||||
|
if (0 == n) {
|
||||||
|
return LunarMonth.fromYm(this._p.year, this._p.month);
|
||||||
|
} else {
|
||||||
|
var rest = Math.abs(n);
|
||||||
|
var ny = this._p.year;
|
||||||
|
var iy = ny;
|
||||||
|
var im = this._p.month;
|
||||||
|
var index = 0;
|
||||||
|
var months = LunarYear.fromYear(ny).getMonths();
|
||||||
|
var i;
|
||||||
|
var m;
|
||||||
|
var size;
|
||||||
|
if (n > 0) {
|
||||||
|
while (true) {
|
||||||
|
size = months.length;
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
m = months[i];
|
||||||
|
if (m.getYear() === iy && m.getMonth() === im) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var more = size - index - 1;
|
||||||
|
if (rest < more) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rest -= more;
|
||||||
|
var lastMonth = months[size - 1];
|
||||||
|
iy = lastMonth.getYear();
|
||||||
|
im = lastMonth.getMonth();
|
||||||
|
ny++;
|
||||||
|
months = LunarYear.fromYear(ny).getMonths();
|
||||||
|
}
|
||||||
|
return months[index + rest];
|
||||||
|
} else {
|
||||||
|
while (true) {
|
||||||
|
size = months.length;
|
||||||
|
for (i = 0; i < size; i++) {
|
||||||
|
m = months[i];
|
||||||
|
if (m.getYear() === iy && m.getMonth() === im) {
|
||||||
|
index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rest <= index) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
rest -= index;
|
||||||
|
var firstMonth = months[0];
|
||||||
|
iy = firstMonth.getYear();
|
||||||
|
im = firstMonth.getMonth();
|
||||||
|
ny--;
|
||||||
|
months = LunarYear.fromYear(ny).getMonths();
|
||||||
|
}
|
||||||
|
return months[index - rest];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
toString:function(){return this.getYear()+'年'+(this.isLeap()?'闰':'')+LunarUtil.MONTH[Math.abs(this.getMonth())]+'月('+this.getDayCount()+')天';}
|
toString:function(){return this.getYear()+'年'+(this.isLeap()?'闰':'')+LunarUtil.MONTH[Math.abs(this.getMonth())]+'月('+this.getDayCount()+')天';}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -3453,7 +3533,8 @@
|
|||||||
},
|
},
|
||||||
getShenGongNaYin:function(){return LunarUtil.NAYIN[this.getShenGong()];},
|
getShenGongNaYin:function(){return LunarUtil.NAYIN[this.getShenGong()];},
|
||||||
getLunar:function(){return this._p.lunar;},
|
getLunar:function(){return this._p.lunar;},
|
||||||
getYun:function(gender){
|
getYun:function(gender, sect){
|
||||||
|
sect = (2 == sect) ? sect : 1;
|
||||||
var lunar = this.getLunar();
|
var lunar = this.getLunar();
|
||||||
var yang = 0 === lunar.getYearGanIndexExact() % 2;
|
var yang = 0 === lunar.getYearGanIndexExact() % 2;
|
||||||
var man = 1 === gender;
|
var man = 1 === gender;
|
||||||
@@ -3464,25 +3545,44 @@
|
|||||||
var current = lunar.getSolar();
|
var current = lunar.getSolar();
|
||||||
var start = forward ? current : prev.getSolar();
|
var start = forward ? current : prev.getSolar();
|
||||||
var end = forward ? next.getSolar() : current;
|
var end = forward ? next.getSolar() : current;
|
||||||
const endTimeZhiIndex = (end.getHour() === 23) ? 11 : LunarUtil.getTimeZhiIndex(end.toYmdHms().substr(11, 5));
|
|
||||||
const startTimeZhiIndex = (start.getHour() === 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().substr(11, 5));
|
var year;
|
||||||
// 时辰差
|
var month;
|
||||||
var hourDiff = endTimeZhiIndex - startTimeZhiIndex;
|
var day;
|
||||||
// 天数差
|
var hour = 0;
|
||||||
var dayDiff = ExactDate.getDaysBetweenYmd(start.getYear(), start.getMonth(), start.getDay(), end.getYear(), end.getMonth(), end.getDay());
|
|
||||||
if (hourDiff < 0) {
|
if (2 === sect) {
|
||||||
hourDiff += 12;
|
var minutes = Math.floor((end.getCalendar() - start.getCalendar()) / 60000);
|
||||||
dayDiff--;
|
year = Math.floor(minutes / 4320);
|
||||||
|
minutes -= year * 4320;
|
||||||
|
month = Math.floor(minutes / 360);
|
||||||
|
minutes -= month * 360;
|
||||||
|
day = Math.floor(minutes / 12);
|
||||||
|
minutes -= day * 12;
|
||||||
|
hour = minutes * 2;
|
||||||
|
} else {
|
||||||
|
var endTimeZhiIndex = (end.getHour() === 23) ? 11 : LunarUtil.getTimeZhiIndex(end.toYmdHms().substr(11, 5));
|
||||||
|
var startTimeZhiIndex = (start.getHour() === 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().substr(11, 5));
|
||||||
|
// 时辰差
|
||||||
|
var hourDiff = endTimeZhiIndex - startTimeZhiIndex;
|
||||||
|
// 天数差
|
||||||
|
var dayDiff = ExactDate.getDaysBetweenYmd(start.getYear(), start.getMonth(), start.getDay(), end.getYear(), end.getMonth(), end.getDay());
|
||||||
|
if (hourDiff < 0) {
|
||||||
|
hourDiff += 12;
|
||||||
|
dayDiff--;
|
||||||
|
}
|
||||||
|
var monthDiff = Math.floor(hourDiff * 10 / 30);
|
||||||
|
month = dayDiff * 4 + monthDiff;
|
||||||
|
day = hourDiff * 10 - monthDiff * 30;
|
||||||
|
year = Math.floor(month / 12);
|
||||||
|
month = month - year * 12;
|
||||||
}
|
}
|
||||||
var monthDiff = Math.floor(hourDiff * 10 / 30);
|
|
||||||
var month = dayDiff * 4 + monthDiff;
|
|
||||||
var day = hourDiff * 10 - monthDiff * 30;
|
|
||||||
var year = Math.floor(month / 12);
|
|
||||||
month = month - year * 12;
|
|
||||||
return {
|
return {
|
||||||
year: year,
|
year: year,
|
||||||
month: month,
|
month: month,
|
||||||
day: day
|
day: day,
|
||||||
|
hour: hour
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
var buildLiuYue = function(liuNian, index){
|
var buildLiuYue = function(liuNian, index){
|
||||||
@@ -3662,6 +3762,7 @@
|
|||||||
startYear: start.year,
|
startYear: start.year,
|
||||||
startMonth: start.month,
|
startMonth: start.month,
|
||||||
startDay: start.day,
|
startDay: start.day,
|
||||||
|
startHour: start.hour,
|
||||||
forward: forward,
|
forward: forward,
|
||||||
lunar: lunar
|
lunar: lunar
|
||||||
},
|
},
|
||||||
@@ -3669,6 +3770,7 @@
|
|||||||
getStartYear: function(){return this._p.startYear;},
|
getStartYear: function(){return this._p.startYear;},
|
||||||
getStartMonth: function(){return this._p.startMonth;},
|
getStartMonth: function(){return this._p.startMonth;},
|
||||||
getStartDay: function(){return this._p.startDay;},
|
getStartDay: function(){return this._p.startDay;},
|
||||||
|
getStartHour: function(){return this._p.startHour;},
|
||||||
isForward: function(){return this._p.forward;},
|
isForward: function(){return this._p.forward;},
|
||||||
getLunar: function(){return this._p.lunar;},
|
getLunar: function(){return this._p.lunar;},
|
||||||
getStartSolar: function(){
|
getStartSolar: function(){
|
||||||
@@ -3677,6 +3779,7 @@
|
|||||||
c.setFullYear(birth.getYear() + this._p.startYear);
|
c.setFullYear(birth.getYear() + this._p.startYear);
|
||||||
c.setMonth(birth.getMonth()-1+this._p.startMonth);
|
c.setMonth(birth.getMonth()-1+this._p.startMonth);
|
||||||
c.setDate(birth.getDay() + this._p.startDay);
|
c.setDate(birth.getDay() + this._p.startDay);
|
||||||
|
c.setHours(birth.getHour() + this._p.startHour);
|
||||||
return Solar.fromDate(c);
|
return Solar.fromDate(c);
|
||||||
},
|
},
|
||||||
getDaYun: function(n){
|
getDaYun: function(n){
|
||||||
@@ -4247,7 +4350,7 @@
|
|||||||
'冬至':'北方玄上玉宸天尊同黑帝五炁天君下降'
|
'冬至':'北方玄上玉宸天尊同黑帝五炁天君下降'
|
||||||
},
|
},
|
||||||
FESTIVAL: {
|
FESTIVAL: {
|
||||||
'1-1': [_f('天腊之辰', '天腊,此日五帝会于束方九炁青天')],
|
'1-1': [_f('天腊之辰', '天腊,此日五帝会于东方九炁青天')],
|
||||||
'1-3': [_f('郝真人圣诞'), _f('孙真人圣诞')],
|
'1-3': [_f('郝真人圣诞'), _f('孙真人圣诞')],
|
||||||
'1-5': [_f('孙祖清静元君诞')],
|
'1-5': [_f('孙祖清静元君诞')],
|
||||||
'1-7': [_f('举迁赏会', '此日上元赐福,天官同地水二官考校罪福')],
|
'1-7': [_f('举迁赏会', '此日上元赐福,天官同地水二官考校罪福')],
|
||||||
@@ -4282,7 +4385,7 @@
|
|||||||
'4-20': [_f('眼光圣母娘娘诞')],
|
'4-20': [_f('眼光圣母娘娘诞')],
|
||||||
'4-28': [_f('神农先帝诞')],
|
'4-28': [_f('神农先帝诞')],
|
||||||
'5-1': [_f('南极长生大帝圣诞')],
|
'5-1': [_f('南极长生大帝圣诞')],
|
||||||
'5-5': [_f('地腊之辰', '地腊,此日五帝会於南方三炁丹天'), _f('南方雷祖圣诞'), _f('地祗温元帅圣诞'), _f('雷霆邓天君圣诞')],
|
'5-5': [_f('地腊之辰', '地腊,此日五帝会于南方三炁丹天'), _f('南方雷祖圣诞'), _f('地祗温元帅圣诞'), _f('雷霆邓天君圣诞')],
|
||||||
'5-11': [_f('城隍爷圣诞')],
|
'5-11': [_f('城隍爷圣诞')],
|
||||||
'5-13': [_f('关圣帝君降神'), _f('关平太子圣诞')],
|
'5-13': [_f('关圣帝君降神'), _f('关平太子圣诞')],
|
||||||
'5-18': [_f('张天师圣诞')],
|
'5-18': [_f('张天师圣诞')],
|
||||||
@@ -4324,7 +4427,7 @@
|
|||||||
'9-22': [_f('增福财神诞')],
|
'9-22': [_f('增福财神诞')],
|
||||||
'9-23': [_f('萨翁真君圣诞')],
|
'9-23': [_f('萨翁真君圣诞')],
|
||||||
'9-28': [_f('五显灵官马元帅圣诞')],
|
'9-28': [_f('五显灵官马元帅圣诞')],
|
||||||
'10-1': [_f('民岁腊之辰', '民岁腊,此日五帝会於北方五炁黑天'), _f('东皇大帝圣诞')],
|
'10-1': [_f('民岁腊之辰', '民岁腊,此日五帝会于北方五炁黑天'), _f('东皇大帝圣诞')],
|
||||||
'10-3': [_f('三茅应化真君圣诞')],
|
'10-3': [_f('三茅应化真君圣诞')],
|
||||||
'10-6': [_f('天曹诸司五岳五帝圣诞')],
|
'10-6': [_f('天曹诸司五岳五帝圣诞')],
|
||||||
'10-15': [_f('下元水官大帝圣诞'), _f('建生大会', '此日下元解厄,水官同天地二官考校罪福')],
|
'10-15': [_f('下元水官大帝圣诞'), _f('建生大会', '此日下元解厄,水官同天地二官考校罪福')],
|
||||||
@@ -4335,7 +4438,7 @@
|
|||||||
'11-9': [_f('湘子韩祖圣诞')],
|
'11-9': [_f('湘子韩祖圣诞')],
|
||||||
'11-11': [_f('太乙救苦天尊圣诞')],
|
'11-11': [_f('太乙救苦天尊圣诞')],
|
||||||
'11-26': [_f('北方五道圣诞')],
|
'11-26': [_f('北方五道圣诞')],
|
||||||
'12-8': [_f('王侯腊之辰', '王侯腊,此日五帝会於上方玄都玉京')],
|
'12-8': [_f('王侯腊之辰', '王侯腊,此日五帝会于上方玄都玉京')],
|
||||||
'12-16': [_f('南岳大帝圣诞'), _f('福德正神诞')],
|
'12-16': [_f('南岳大帝圣诞'), _f('福德正神诞')],
|
||||||
'12-20': [_f('鲁班先师圣诞')],
|
'12-20': [_f('鲁班先师圣诞')],
|
||||||
'12-21': [_f('天猷上帝圣诞')],
|
'12-21': [_f('天猷上帝圣诞')],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lunar-javascript",
|
"name": "lunar-javascript",
|
||||||
"version": "1.2.26",
|
"version": "1.2.29",
|
||||||
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
|
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user