Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f2f9d702c | ||
|
|
c0bd1d5565 | ||
|
|
263f280395 | ||
|
|
5d18af8619 | ||
|
|
a41d2c6c2a |
@@ -59,4 +59,4 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
|
||||
## 文档
|
||||
|
||||
请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
|
||||
请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
|
||||
|
||||
@@ -59,4 +59,4 @@ Output:
|
||||
|
||||
## Documentation
|
||||
|
||||
Please visit [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
|
||||
Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
|
||||
|
||||
@@ -168,3 +168,12 @@ test('身宫3', () => {
|
||||
const eightChar = lunar.getEightChar();
|
||||
expect(eightChar.getShenGong()).toBe('庚申');
|
||||
});
|
||||
|
||||
test('test11', () => {
|
||||
const lunar = Lunar.fromYmdHms(1987, 12, 28, 23, 30, 0);
|
||||
const eightChar = lunar.getEightChar();
|
||||
expect(eightChar.getYear()).toBe('戊辰');
|
||||
expect(eightChar.getMonth()).toBe('甲寅');
|
||||
expect(eightChar.getDay()).toBe('庚子');
|
||||
expect(eightChar.getTime()).toBe('戊子');
|
||||
});
|
||||
|
||||
@@ -93,7 +93,7 @@ test('test7', () => {
|
||||
|
||||
test('test8', () => {
|
||||
const lunar = Lunar.fromYmd(2050, 12, 1);
|
||||
expect(lunar.getJieQiTable()['大雪'].toYmdHms()).toBe('2050-12-07 06:41:00');
|
||||
expect(lunar.getJieQiTable()['DA_XUE'].toYmdHms()).toBe('2050-12-07 06:41:00');
|
||||
});
|
||||
|
||||
test('test9', () => {
|
||||
|
||||
@@ -413,16 +413,6 @@ test('test022', () => {
|
||||
expect(lunar.getSolar().toString()).toBe('2033-12-22');
|
||||
});
|
||||
|
||||
test('test023', () => {
|
||||
const lunar = Lunar.fromYmd(2022, 1, 1);
|
||||
expect(lunar.getYearNineStar().toString()).toBe('六白金开阳');
|
||||
});
|
||||
|
||||
test('test024', () => {
|
||||
const lunar = Lunar.fromYmd(2033, 1, 1);
|
||||
expect(lunar.getYearNineStar().toString()).toBe('四绿木天权');
|
||||
});
|
||||
|
||||
test('test025', () => {
|
||||
const solar = Solar.fromYmdHms(2021, 6, 7, 21, 18, 0);
|
||||
expect(solar.getLunar().toString()).toBe('二〇二一年四月廿七');
|
||||
|
||||
16
__tests__/NineStar.test.js
Normal file
16
__tests__/NineStar.test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const {Solar, Lunar} = require('../lunar');
|
||||
|
||||
test('test1', () => {
|
||||
const lunar = Solar.fromYmd(1985, 2, 19).getLunar();
|
||||
expect(lunar.getYearNineStar().getNumber()).toBe('六');
|
||||
});
|
||||
|
||||
test('test023', () => {
|
||||
const lunar = Lunar.fromYmd(2022, 1, 1);
|
||||
expect(lunar.getYearNineStar().toString()).toBe('六白金开阳');
|
||||
});
|
||||
|
||||
test('test024', () => {
|
||||
const lunar = Lunar.fromYmd(2033, 1, 1);
|
||||
expect(lunar.getYearNineStar().toString()).toBe('四绿木天权');
|
||||
});
|
||||
@@ -83,3 +83,15 @@ test('test14', () => {
|
||||
const lunar = solar.getLunar();
|
||||
expect(lunar.getHou()).toBe('立夏 三候');
|
||||
});
|
||||
|
||||
test('test15', () => {
|
||||
const solar = Solar.fromYmd(2022, 8, 22);
|
||||
const lunar = solar.getLunar();
|
||||
expect(lunar.getWuHou()).toBe('寒蝉鸣');
|
||||
});
|
||||
|
||||
test('test16', () => {
|
||||
const solar = Solar.fromYmd(2022, 8, 23);
|
||||
const lunar = solar.getLunar();
|
||||
expect(lunar.getWuHou()).toBe('鹰乃祭鸟');
|
||||
});
|
||||
|
||||
49
lunar.js
49
lunar.js
@@ -567,6 +567,9 @@
|
||||
}
|
||||
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){
|
||||
@@ -1068,7 +1071,7 @@
|
||||
if(f){
|
||||
l.push(f);
|
||||
}
|
||||
if (Math.abs(this._p.month) === 12 && this._p.day >= 29 && this._p.year != this.next(1).getYear()) {
|
||||
if (Math.abs(this._p.month) === 12 && this._p.day >= 29 && this._p.year !== this.next(1).getYear()) {
|
||||
l.push('除夕');
|
||||
}
|
||||
return l;
|
||||
@@ -1221,13 +1224,16 @@
|
||||
return LunarUtil.YUE_XIANG[this._p.day];
|
||||
},
|
||||
_getYearNineStar:function(yearInGanZhi){
|
||||
var index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
||||
var yearOffset = 0;
|
||||
if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
|
||||
yearOffset = -1;
|
||||
var indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
||||
var index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1;
|
||||
var yearOffset = indexExact - index;
|
||||
if (yearOffset > 1) {
|
||||
yearOffset -= 60;
|
||||
} else if (yearOffset < -1) {
|
||||
yearOffset += 60;
|
||||
}
|
||||
var yuan = Math.floor((this._p.year + yearOffset + 2696) / 60) % 3;
|
||||
var offset = (62 + yuan * 3 - index) % 9;
|
||||
var offset = (62 + yuan * 3 - indexExact) % 9;
|
||||
if(0 === offset){
|
||||
offset = 9;
|
||||
}
|
||||
@@ -1377,7 +1383,7 @@
|
||||
var j;
|
||||
for(i=0,j=Lunar.JIE_QI.length;i<j;i++){
|
||||
if(Lunar.JIE_QI[i]===name){
|
||||
if(i%2==0){
|
||||
if(i%2===0){
|
||||
qi = true;
|
||||
}else{
|
||||
jie = true;
|
||||
@@ -1679,7 +1685,11 @@
|
||||
var startSolar = jieQi.getSolar();
|
||||
var startCalendar = ExactDate.fromYmd(startSolar.getYear(),startSolar.getMonth(),startSolar.getDay());
|
||||
var days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
|
||||
return LunarUtil.WU_HOU[(offset*3+Math.floor(days/5)) % LunarUtil.WU_HOU.length];
|
||||
var index = Math.floor(days / 5);
|
||||
if (index > 2) {
|
||||
index = 2;
|
||||
}
|
||||
return LunarUtil.WU_HOU[(offset * 3 + index) % LunarUtil.WU_HOU.length];
|
||||
},
|
||||
getHou:function(){
|
||||
var jieQi = this.getPrevJieQi(true);
|
||||
@@ -1945,22 +1955,15 @@
|
||||
},
|
||||
getWeeks:function(start){
|
||||
var l = [];
|
||||
var cy = this._p.year;
|
||||
var cm = this._p.month;
|
||||
var weeks = SolarUtil.getWeeksOfMonth(cy, cm, start);
|
||||
var days = SolarUtil.getDaysOfMonth(cy, cm);
|
||||
for(var i = 0;i<weeks;i++){
|
||||
var y = cy;
|
||||
var m = cm;
|
||||
var d = 1 + i * 7;
|
||||
if (d > days) {
|
||||
d -= days;
|
||||
m++;
|
||||
if (m > 12) {
|
||||
y++;
|
||||
}
|
||||
var week = SolarWeek.fromYmd(this._p.year, this._p.month, 1, start);
|
||||
var firstDay = week.getFirstDay();
|
||||
while (true) {
|
||||
l.push(week);
|
||||
week = week.next(1, false);
|
||||
firstDay = week.getFirstDay();
|
||||
if (firstDay.getYear() > this._p.year || firstDay.getMonth() > this._p.month) {
|
||||
break;
|
||||
}
|
||||
l.push(SolarWeek.fromYmd(y, m, d, start));
|
||||
}
|
||||
return l;
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lunar-javascript",
|
||||
"version": "1.2.33",
|
||||
"version": "1.2.36",
|
||||
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user