Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13c251080b | ||
|
|
1f708a8d6f | ||
|
|
b926be0022 |
@@ -177,3 +177,7 @@ test('test11', () => {
|
||||
expect(eightChar.getDay()).toBe('庚子');
|
||||
expect(eightChar.getTime()).toBe('戊子');
|
||||
});
|
||||
|
||||
test('test12', () => {
|
||||
expect(Solar.fromYmdHms('1999', '06', '07', '09', '11', '00').getLunar().getEightChar().toString()).toBe('己卯 庚午 庚寅 辛巳');
|
||||
});
|
||||
|
||||
@@ -92,3 +92,18 @@ test('19', () => {
|
||||
})
|
||||
expect(timeList).toStrictEqual(['2020-07-21 22:00:00', '1960-08-05 22:00:00']);
|
||||
});
|
||||
|
||||
test('20', () => {
|
||||
const solar = Solar.fromYmd(1582, 10, 4);
|
||||
expect(solar.nextDay(1).toYmd()).toBe('1582-10-15');
|
||||
});
|
||||
|
||||
test('21', () => {
|
||||
const solar = Solar.fromYmd(1582, 10, 15);
|
||||
expect(solar.nextDay(-1).toYmd()).toBe('1582-10-04');
|
||||
});
|
||||
|
||||
test('22', () => {
|
||||
const solar = Solar.fromYmd(1582, 10, 15);
|
||||
expect(solar.nextDay(-5).toYmd()).toBe('1582-09-30');
|
||||
});
|
||||
|
||||
69
lunar.js
69
lunar.js
@@ -128,27 +128,32 @@
|
||||
isAfter: function(solar) {
|
||||
if (this._p.year > solar.getYear()) {
|
||||
return true;
|
||||
} else if (this._p.year < solar.getYear()) {
|
||||
}
|
||||
if (this._p.year < solar.getYear()) {
|
||||
return false;
|
||||
}
|
||||
if (this._p.month > solar.getMonth()) {
|
||||
return true;
|
||||
} else if (this._p.month < solar.getMonth()) {
|
||||
}
|
||||
if (this._p.month < solar.getMonth()) {
|
||||
return false;
|
||||
}
|
||||
if (this._p.day > solar.getDay()) {
|
||||
return true;
|
||||
} else if (this._p.day < solar.getDay()) {
|
||||
}
|
||||
if (this._p.day < solar.getDay()) {
|
||||
return false;
|
||||
}
|
||||
if (this._p.hour > solar.getHour()) {
|
||||
return true;
|
||||
} else if (this._p.hour < solar.getHour()) {
|
||||
}
|
||||
if (this._p.hour < solar.getHour()) {
|
||||
return false;
|
||||
}
|
||||
if (this._p.minute > solar.getMinute()) {
|
||||
return true;
|
||||
} else if (this._p.minute < solar.getMinute()) {
|
||||
}
|
||||
if (this._p.minute < solar.getMinute()) {
|
||||
return false;
|
||||
}
|
||||
return this._p.second > solar.getSecond();
|
||||
@@ -156,27 +161,32 @@
|
||||
isBefore: function(solar) {
|
||||
if (this._p.year > solar.getYear()) {
|
||||
return false;
|
||||
} else if (this._p.year < solar.getYear()) {
|
||||
}
|
||||
if (this._p.year < solar.getYear()) {
|
||||
return true;
|
||||
}
|
||||
if (this._p.month > solar.getMonth()) {
|
||||
return false;
|
||||
} else if (this._p.month < solar.getMonth()) {
|
||||
}
|
||||
if (this._p.month < solar.getMonth()) {
|
||||
return true;
|
||||
}
|
||||
if (this._p.day > solar.getDay()) {
|
||||
return false;
|
||||
} else if (this._p.day < solar.getDay()) {
|
||||
}
|
||||
if (this._p.day < solar.getDay()) {
|
||||
return true;
|
||||
}
|
||||
if (this._p.hour > solar.getHour()) {
|
||||
return false;
|
||||
} else if (this._p.hour < solar.getHour()) {
|
||||
}
|
||||
if (this._p.hour < solar.getHour()) {
|
||||
return true;
|
||||
}
|
||||
if (this._p.minute > solar.getMinute()) {
|
||||
return false;
|
||||
} else if (this._p.minute < solar.getMinute()) {
|
||||
}
|
||||
if (this._p.minute < solar.getMinute()) {
|
||||
return true;
|
||||
}
|
||||
return this._p.second < solar.getSecond();
|
||||
@@ -334,12 +344,7 @@
|
||||
if (2 === m) {
|
||||
if (d > 28) {
|
||||
if (!SolarUtil.isLeapYear(y)) {
|
||||
d -= 28;
|
||||
m++;
|
||||
if (m > 12) {
|
||||
m = 1;
|
||||
y++;
|
||||
}
|
||||
d = 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,12 +370,7 @@
|
||||
if (2 === m) {
|
||||
if (d > 28) {
|
||||
if (!SolarUtil.isLeapYear(y)) {
|
||||
d -= 28;
|
||||
m++;
|
||||
if (m > 12) {
|
||||
m = 1;
|
||||
y++;
|
||||
}
|
||||
d = 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -390,33 +390,36 @@
|
||||
var y = this._p.year;
|
||||
var m = this._p.month;
|
||||
var d = this._p.day;
|
||||
if (1582 === y && 10 === m) {
|
||||
if (d > 4) {
|
||||
d -= 10
|
||||
}
|
||||
}
|
||||
if (days > 0) {
|
||||
d = this._p.day + days;
|
||||
d += days;
|
||||
var daysInMonth = SolarUtil.getDaysOfMonth(y, m);
|
||||
while (d > daysInMonth) {
|
||||
d -= daysInMonth;
|
||||
m++;
|
||||
if (m > 12) {
|
||||
m -= 12;
|
||||
m = 1;
|
||||
y++;
|
||||
}
|
||||
daysInMonth = SolarUtil.getDaysOfMonth(y, m);
|
||||
}
|
||||
} else if (days < 0) {
|
||||
var rest = -days;
|
||||
while (d <= rest) {
|
||||
rest -= d;
|
||||
while (d + days <= 0) {
|
||||
m--;
|
||||
if (m < 1) {
|
||||
m = 12;
|
||||
y--;
|
||||
}
|
||||
d = SolarUtil.getDaysOfMonth(y, m);
|
||||
d += SolarUtil.getDaysOfMonth(y, m);
|
||||
}
|
||||
d -= rest;
|
||||
d += days;
|
||||
}
|
||||
if (1582 === y && 10 === m) {
|
||||
if (d > 4 && d < 15) {
|
||||
if (d > 4) {
|
||||
d += 10;
|
||||
}
|
||||
}
|
||||
@@ -514,9 +517,13 @@
|
||||
offsetYear += 60;
|
||||
}
|
||||
var startYear = today.getYear() - offsetYear - 1;
|
||||
while (startYear >= baseYear) {
|
||||
while (true) {
|
||||
years.push(startYear);
|
||||
startYear -= 60;
|
||||
if (startYear < baseYear) {
|
||||
years.push(baseYear);
|
||||
break;
|
||||
}
|
||||
}
|
||||
var hour = 0;
|
||||
var timeZhi = timeGanZhi.substr(1);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lunar-javascript",
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.2",
|
||||
"description": "lunar is a calendar library for Solar and Chinese Lunar.",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user