v1.2.7 修复时区导致计算错误的问题。
This commit is contained in:
@@ -147,4 +147,3 @@ test('身宫', () => {
|
||||
const eightChar = lunar.getEightChar();
|
||||
expect(eightChar.getShenGong()).toBe('壬午');
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
var {Solar, Lunar} = require('../lunar');
|
||||
var {Solar, Lunar, LunarYear} = require('../lunar');
|
||||
|
||||
test('干支', () => {
|
||||
let solar = Solar.fromYmdHms(2020, 1, 1, 13, 22, 0);
|
||||
@@ -530,3 +530,13 @@ test('test044', () => {
|
||||
const solar = Solar.fromYmd(1, 1, 1);
|
||||
expect(solar.getLunar().getYearShengXiao()).toBe('猴');
|
||||
});
|
||||
|
||||
test('test045', () => {
|
||||
const lunarMonth = LunarYear.fromYear(2020).getMonth(-4);
|
||||
expect(lunarMonth.toString()).toBe('2020年闰四月(29)天');
|
||||
});
|
||||
|
||||
test('test046', () => {
|
||||
const solar = Solar.fromYmdHms(2000, 1, 1, 16, 0, 0);
|
||||
expect(solar.getLunar().getHour()).toBe(16);
|
||||
});
|
||||
|
||||
35
lunar.js
35
lunar.js
@@ -22,10 +22,10 @@
|
||||
return date;
|
||||
},
|
||||
fromYmd:function(y,m,d){
|
||||
return this._(new Date(y+'/'+m+'/'+d+' 0:0:0 GMT+0800'),y,m,d);
|
||||
return this.fromYmdHms(y,m,d,0,0,0);
|
||||
},
|
||||
fromYmdHms:function(y,m,d,hour,minute,second){
|
||||
return this._(new Date(y+'/'+m+'/'+d+' '+hour+':'+minute+':'+second+' GMT+0800'),y,m,d);
|
||||
return this._(new Date(y+'/'+m+'/'+d+' '+hour+':'+minute+':'+second),y,m,d);
|
||||
}
|
||||
};
|
||||
})();
|
||||
@@ -68,7 +68,7 @@
|
||||
return _fromYmdHms(year,month,day,hour,minute,second);
|
||||
};
|
||||
var _fromYmdHms = function(y,m,d,hour,minute,second){
|
||||
if(y===1582&&m==10){
|
||||
if(y===1582&&m===10){
|
||||
if(d>=15){
|
||||
d -= 10;
|
||||
}
|
||||
@@ -174,7 +174,7 @@
|
||||
},
|
||||
toYmd:function(){
|
||||
var d = this._p.day;
|
||||
if(this._p.year===1582&&this._p.month==10){
|
||||
if(this._p.year===1582&&this._p.month===10){
|
||||
if(d>=5){
|
||||
d += 10;
|
||||
}
|
||||
@@ -335,7 +335,15 @@
|
||||
};
|
||||
})();
|
||||
var Lunar = (function(){
|
||||
var MS_PER_DAY = 86400000;
|
||||
var _diff = function(after, before) {
|
||||
var current = ExactDate.fromYmdHms(before.getFullYear(), before.getMonth()+1, before.getDate(), before.getHours(), before.getMinutes(), before.getSeconds());
|
||||
var n = 0;
|
||||
while(current<after){
|
||||
n++;
|
||||
current.setDate(current.getDate()+1);
|
||||
}
|
||||
return n;
|
||||
};
|
||||
var _computeJieQi = function(o,ly) {
|
||||
o['jieQiList'] = [];
|
||||
o['jieQi'] = {};
|
||||
@@ -493,7 +501,6 @@
|
||||
};
|
||||
var _fromDate = function(date){
|
||||
var c = ExactDate.fromYmd(date.getFullYear(),date.getMonth()+1,date.getDate());
|
||||
var solarTime = c.getTime();
|
||||
var lunarYear = 0;
|
||||
var lunarMonth = 0;
|
||||
var lunarDay = 0;
|
||||
@@ -508,7 +515,7 @@
|
||||
firstDay.setMinutes(0);
|
||||
firstDay.setSeconds(0);
|
||||
firstDay.setMilliseconds(0);
|
||||
var days = Math.floor((solarTime - firstDay.getTime()) / MS_PER_DAY);
|
||||
var days = _diff(c, firstDay);
|
||||
if (days < m.getDayCount()) {
|
||||
lunarYear = m.getYear();
|
||||
lunarMonth = m.getMonth();
|
||||
@@ -1376,7 +1383,7 @@
|
||||
if (currentCalendar < startCalendar || currentCalendar >= endCalendar) {
|
||||
return null;
|
||||
}
|
||||
var days = Math.floor((currentCalendar.getTime() - startCalendar.getTime()) / MS_PER_DAY);
|
||||
var days = _diff(currentCalendar,startCalendar);
|
||||
return this._buildNameAndIndex(LunarUtil.NUMBER[Math.floor(days / 9) + 1] + '九', days % 9 + 1);
|
||||
},
|
||||
getFu:function(){
|
||||
@@ -1399,7 +1406,7 @@
|
||||
return null;
|
||||
}
|
||||
|
||||
var days = Math.floor((currentCalendar.getTime() - startCalendar.getTime()) / MS_PER_DAY);
|
||||
var days = _diff(currentCalendar,startCalendar);
|
||||
if (days < 10) {
|
||||
return this._buildNameAndIndex('初伏', days + 1);
|
||||
}
|
||||
@@ -1407,7 +1414,7 @@
|
||||
// 第4个庚日,中伏第1天
|
||||
startCalendar.setDate(startCalendar.getDate() + 10);
|
||||
|
||||
days = Math.floor((currentCalendar.getTime() - startCalendar.getTime()) / MS_PER_DAY);
|
||||
days = _diff(currentCalendar,startCalendar);
|
||||
if (days < 10) {
|
||||
return this._buildNameAndIndex('中伏', days + 1);
|
||||
}
|
||||
@@ -1417,7 +1424,7 @@
|
||||
|
||||
var liQiuCalendar = ExactDate.fromYmd(liQiu.getYear(),liQiu.getMonth(),liQiu.getDay());
|
||||
|
||||
days = Math.floor((currentCalendar.getTime() - startCalendar.getTime()) / MS_PER_DAY);
|
||||
days = _diff(currentCalendar,startCalendar);
|
||||
// 末伏
|
||||
if (liQiuCalendar <= startCalendar) {
|
||||
if (days < 10) {
|
||||
@@ -1430,7 +1437,7 @@
|
||||
}
|
||||
// 末伏第1天
|
||||
startCalendar.setDate(startCalendar.getDate() + 10);
|
||||
days = Math.floor((currentCalendar.getTime() - startCalendar.getTime()) / MS_PER_DAY);
|
||||
days = _diff(currentCalendar,startCalendar);
|
||||
if (days < 10) {
|
||||
return this._buildNameAndIndex('末伏', days + 1);
|
||||
}
|
||||
@@ -1453,7 +1460,7 @@
|
||||
var currentCalendar = ExactDate.fromYmd(this._p.solar.getYear(),this._p.solar.getMonth(),this._p.solar.getDay());
|
||||
var startSolar = jieQi.getSolar();
|
||||
var startCalendar = ExactDate.fromYmd(startSolar.getYear(),startSolar.getMonth(),startSolar.getDay());
|
||||
var days = Math.floor((currentCalendar.getTime() - startCalendar.getTime()) / MS_PER_DAY);
|
||||
var days = _diff(currentCalendar,startCalendar);
|
||||
return LunarUtil.WU_HOU[(offset*3+Math.floor(days/5)) % LunarUtil.WU_HOU.length];
|
||||
}
|
||||
};
|
||||
@@ -2019,7 +2026,7 @@
|
||||
getDayCount:function(){return this._p.dayCount;},
|
||||
getFirstJulianDay:function(){return this._p.firstJulianDay;},
|
||||
isLeap:function(){return this._p.month<0;},
|
||||
toString:function(){return this.getYear()+'年'+LunarUtil.MONTH[Math.abs(this.getMonth())]+'月('+this.getDayCount()+')天';}
|
||||
toString:function(){return this.getYear()+'年'+(this.isLeap()?'闰':'')+LunarUtil.MONTH[Math.abs(this.getMonth())]+'月('+this.getDayCount()+')天';}
|
||||
};
|
||||
};
|
||||
return {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lunar-javascript",
|
||||
"version": "1.2.6",
|
||||
"version": "1.2.7",
|
||||
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
@@ -50,5 +50,6 @@
|
||||
"homepage": "https://github.com/6tail/lunar-javascript",
|
||||
"devDependencies": {
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
},
|
||||
"dependencies": {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user