mirror of
https://gitee.com/6tail/lunar-javascript.git
synced 2026-10-07 23:30:04 +08:00
v1.2.36 修复立春比春节早时年九星的错误;修复跨年时阳历月中获取周的错误。
This commit is contained in:
@@ -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('四绿木天权');
|
||||||
|
});
|
||||||
37
lunar.js
37
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;
|
||||||
}
|
}
|
||||||
@@ -1952,23 +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++;
|
|
||||||
m=m-12;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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.35",
|
"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