1
0
mirror of synced 2026-04-16 05:18:43 +08:00

Compare commits

...

3 Commits

4 changed files with 58 additions and 32 deletions

View File

@@ -177,3 +177,7 @@ test('test11', () => {
expect(eightChar.getDay()).toBe('庚子'); expect(eightChar.getDay()).toBe('庚子');
expect(eightChar.getTime()).toBe('戊子'); expect(eightChar.getTime()).toBe('戊子');
}); });
test('test12', () => {
expect(Solar.fromYmdHms('1999', '06', '07', '09', '11', '00').getLunar().getEightChar().toString()).toBe('己卯 庚午 庚寅 辛巳');
});

View File

@@ -92,3 +92,18 @@ test('19', () => {
}) })
expect(timeList).toStrictEqual(['2020-07-21 22:00:00', '1960-08-05 22:00:00']); 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');
});

View File

@@ -128,27 +128,32 @@
isAfter: function(solar) { isAfter: function(solar) {
if (this._p.year > solar.getYear()) { if (this._p.year > solar.getYear()) {
return true; return true;
} else if (this._p.year < solar.getYear()) { }
if (this._p.year < solar.getYear()) {
return false; return false;
} }
if (this._p.month > solar.getMonth()) { if (this._p.month > solar.getMonth()) {
return true; return true;
} else if (this._p.month < solar.getMonth()) { }
if (this._p.month < solar.getMonth()) {
return false; return false;
} }
if (this._p.day > solar.getDay()) { if (this._p.day > solar.getDay()) {
return true; return true;
} else if (this._p.day < solar.getDay()) { }
if (this._p.day < solar.getDay()) {
return false; return false;
} }
if (this._p.hour > solar.getHour()) { if (this._p.hour > solar.getHour()) {
return true; return true;
} else if (this._p.hour < solar.getHour()) { }
if (this._p.hour < solar.getHour()) {
return false; return false;
} }
if (this._p.minute > solar.getMinute()) { if (this._p.minute > solar.getMinute()) {
return true; return true;
} else if (this._p.minute < solar.getMinute()) { }
if (this._p.minute < solar.getMinute()) {
return false; return false;
} }
return this._p.second > solar.getSecond(); return this._p.second > solar.getSecond();
@@ -156,27 +161,32 @@
isBefore: function(solar) { isBefore: function(solar) {
if (this._p.year > solar.getYear()) { if (this._p.year > solar.getYear()) {
return false; return false;
} else if (this._p.year < solar.getYear()) { }
if (this._p.year < solar.getYear()) {
return true; return true;
} }
if (this._p.month > solar.getMonth()) { if (this._p.month > solar.getMonth()) {
return false; return false;
} else if (this._p.month < solar.getMonth()) { }
if (this._p.month < solar.getMonth()) {
return true; return true;
} }
if (this._p.day > solar.getDay()) { if (this._p.day > solar.getDay()) {
return false; return false;
} else if (this._p.day < solar.getDay()) { }
if (this._p.day < solar.getDay()) {
return true; return true;
} }
if (this._p.hour > solar.getHour()) { if (this._p.hour > solar.getHour()) {
return false; return false;
} else if (this._p.hour < solar.getHour()) { }
if (this._p.hour < solar.getHour()) {
return true; return true;
} }
if (this._p.minute > solar.getMinute()) { if (this._p.minute > solar.getMinute()) {
return false; return false;
} else if (this._p.minute < solar.getMinute()) { }
if (this._p.minute < solar.getMinute()) {
return true; return true;
} }
return this._p.second < solar.getSecond(); return this._p.second < solar.getSecond();
@@ -334,12 +344,7 @@
if (2 === m) { if (2 === m) {
if (d > 28) { if (d > 28) {
if (!SolarUtil.isLeapYear(y)) { if (!SolarUtil.isLeapYear(y)) {
d -= 28; d = 28;
m++;
if (m > 12) {
m = 1;
y++;
}
} }
} }
} }
@@ -365,12 +370,7 @@
if (2 === m) { if (2 === m) {
if (d > 28) { if (d > 28) {
if (!SolarUtil.isLeapYear(y)) { if (!SolarUtil.isLeapYear(y)) {
d -= 28; d = 28;
m++;
if (m > 12) {
m = 1;
y++;
}
} }
} }
} }
@@ -390,33 +390,36 @@
var y = this._p.year; var y = this._p.year;
var m = this._p.month; var m = this._p.month;
var d = this._p.day; var d = this._p.day;
if (1582 === y && 10 === m) {
if (d > 4) {
d -= 10
}
}
if (days > 0) { if (days > 0) {
d = this._p.day + days; d += days;
var daysInMonth = SolarUtil.getDaysOfMonth(y, m); var daysInMonth = SolarUtil.getDaysOfMonth(y, m);
while (d > daysInMonth) { while (d > daysInMonth) {
d -= daysInMonth; d -= daysInMonth;
m++; m++;
if (m > 12) { if (m > 12) {
m -= 12; m = 1;
y++; y++;
} }
daysInMonth = SolarUtil.getDaysOfMonth(y, m); daysInMonth = SolarUtil.getDaysOfMonth(y, m);
} }
} else if (days < 0) { } else if (days < 0) {
var rest = -days; while (d + days <= 0) {
while (d <= rest) {
rest -= d;
m--; m--;
if (m < 1) { if (m < 1) {
m = 12; m = 12;
y--; y--;
} }
d = SolarUtil.getDaysOfMonth(y, m); d += SolarUtil.getDaysOfMonth(y, m);
} }
d -= rest; d += days;
} }
if (1582 === y && 10 === m) { if (1582 === y && 10 === m) {
if (d > 4 && d < 15) { if (d > 4) {
d += 10; d += 10;
} }
} }
@@ -514,9 +517,13 @@
offsetYear += 60; offsetYear += 60;
} }
var startYear = today.getYear() - offsetYear - 1; var startYear = today.getYear() - offsetYear - 1;
while (startYear >= baseYear) { while (true) {
years.push(startYear); years.push(startYear);
startYear -= 60; startYear -= 60;
if (startYear < baseYear) {
years.push(baseYear);
break;
}
} }
var hour = 0; var hour = 0;
var timeZhi = timeGanZhi.substr(1); var timeZhi = timeGanZhi.substr(1);

View File

@@ -1,6 +1,6 @@
{ {
"name": "lunar-javascript", "name": "lunar-javascript",
"version": "1.3.0", "version": "1.3.2",
"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": {