Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f2f9d702c | ||
|
|
c0bd1d5565 | ||
|
|
263f280395 | ||
|
|
5d18af8619 |
@@ -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
|
## 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")
|
||||||
|
|||||||
@@ -413,16 +413,6 @@ test('test022', () => {
|
|||||||
expect(lunar.getSolar().toString()).toBe('2033-12-22');
|
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', () => {
|
test('test025', () => {
|
||||||
const solar = Solar.fromYmdHms(2021, 6, 7, 21, 18, 0);
|
const solar = Solar.fromYmdHms(2021, 6, 7, 21, 18, 0);
|
||||||
expect(solar.getLunar().toString()).toBe('二〇二一年四月廿七');
|
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();
|
const lunar = solar.getLunar();
|
||||||
expect(lunar.getHou()).toBe('立夏 三候');
|
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('鹰乃祭鸟');
|
||||||
|
});
|
||||||
|
|||||||
42
lunar.js
42
lunar.js
@@ -1224,13 +1224,16 @@
|
|||||||
return LunarUtil.YUE_XIANG[this._p.day];
|
return LunarUtil.YUE_XIANG[this._p.day];
|
||||||
},
|
},
|
||||||
_getYearNineStar:function(yearInGanZhi){
|
_getYearNineStar:function(yearInGanZhi){
|
||||||
var index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
var indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
||||||
var yearOffset = 0;
|
var index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1;
|
||||||
if (index !== LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
|
var yearOffset = indexExact - index;
|
||||||
yearOffset = -1;
|
if (yearOffset > 1) {
|
||||||
|
yearOffset -= 60;
|
||||||
|
} else if (yearOffset < -1) {
|
||||||
|
yearOffset += 60;
|
||||||
}
|
}
|
||||||
var yuan = Math.floor((this._p.year + yearOffset + 2696) / 60) % 3;
|
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){
|
if(0 === offset){
|
||||||
offset = 9;
|
offset = 9;
|
||||||
}
|
}
|
||||||
@@ -1682,7 +1685,11 @@
|
|||||||
var startSolar = jieQi.getSolar();
|
var startSolar = jieQi.getSolar();
|
||||||
var startCalendar = ExactDate.fromYmd(startSolar.getYear(),startSolar.getMonth(),startSolar.getDay());
|
var startCalendar = ExactDate.fromYmd(startSolar.getYear(),startSolar.getMonth(),startSolar.getDay());
|
||||||
var days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
|
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(){
|
getHou:function(){
|
||||||
var jieQi = this.getPrevJieQi(true);
|
var jieQi = this.getPrevJieQi(true);
|
||||||
@@ -1948,22 +1955,15 @@
|
|||||||
},
|
},
|
||||||
getWeeks:function(start){
|
getWeeks:function(start){
|
||||||
var l = [];
|
var l = [];
|
||||||
var cy = this._p.year;
|
var week = SolarWeek.fromYmd(this._p.year, this._p.month, 1, start);
|
||||||
var cm = this._p.month;
|
var firstDay = week.getFirstDay();
|
||||||
var weeks = SolarUtil.getWeeksOfMonth(cy, cm, start);
|
while (true) {
|
||||||
var days = SolarUtil.getDaysOfMonth(cy, cm);
|
l.push(week);
|
||||||
for(var i = 0;i<weeks;i++){
|
week = week.next(1, false);
|
||||||
var y = cy;
|
firstDay = week.getFirstDay();
|
||||||
var m = cm;
|
if (firstDay.getYear() > this._p.year || firstDay.getMonth() > this._p.month) {
|
||||||
var d = 1 + i * 7;
|
break;
|
||||||
if (d > days) {
|
|
||||||
d -= days;
|
|
||||||
m++;
|
|
||||||
if (m > 12) {
|
|
||||||
y++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
l.push(SolarWeek.fromYmd(y, m, d, start));
|
|
||||||
}
|
}
|
||||||
return l;
|
return l;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lunar-javascript",
|
"name": "lunar-javascript",
|
||||||
"version": "1.2.34",
|
"version": "1.2.36",
|
||||||
"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