1
0
mirror of synced 2026-04-10 10:28:39 +08:00

v1.3.6 中元节改为农历七月十五;修复Solar的nextMonth超期问题。

This commit is contained in:
6tail
2023-09-03 11:39:25 +08:00
parent d66cd71f44
commit ceac1afc3e
6 changed files with 38 additions and 19 deletions

View File

@@ -714,19 +714,17 @@ public class Solar {
int y = year + years;
int m = month;
int d = day;
// 2月处理
if (2 == m) {
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
} else if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
d = 28;
}
}
}
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
}
return fromYmdHms(y, m, d, hour, minute, second);
}
@@ -740,18 +738,15 @@ public class Solar {
int y = month.getYear();
int m = month.getMonth();
int d = day;
// 2月处理
if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
d = 28;
}
}
}
if (1582 == y && 10 == m) {
if (d > 4 && d < 15) {
d += 10;
}
} else {
int maxDay = SolarUtil.getDaysOfMonth(y, m);
if (d > maxDay) {
d = maxDay;
}
}
return fromYmdHms(y, m, d, hour, minute, second);
}

View File

@@ -159,7 +159,7 @@ public class LunarUtil{
put("6-6",Collections.nCopies(1,"天贶节"));
put("6-24",Collections.nCopies(1,"观莲节"));
put("6-25",Collections.nCopies(1,"五谷母节"));
put("7-14",Collections.nCopies(1,"中元节"));
put("7-15",Collections.nCopies(1,"中元节"));
put("7-22",Collections.nCopies(1,"财神节"));
put("7-29",Collections.nCopies(1,"地藏节"));
put("8-1",Collections.nCopies(1,"天灸日"));

View File

@@ -171,4 +171,28 @@ public class SolarTest {
Assert.assertEquals("1582-09-29", solar.next(-6).toYmd());
}
@Test
public void test27(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2023-09-30", solar.nextMonth(1).toYmd());
}
@Test
public void test28(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2023-10-31", solar.nextMonth(2).toYmd());
}
@Test
public void test29(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2025-08-31", solar.nextYear(2).toYmd());
}
@Test
public void test30(){
Solar solar = Solar.fromYmd(2023, 8, 31);
Assert.assertEquals("2024-02-29", solar.nextMonth(6).toYmd());
}
}