Skip to content

Commit

Permalink
v1.3.6 中元节改为农历七月十五;修复Solar的nextMonth超期问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Sep 3, 2023
1 parent d66cd71 commit ceac1af
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.3.5</version>
<version>1.3.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.3.5</version>
<version>1.3.6</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.3.5</version>
<version>1.3.6</version>
<name>${project.groupId}:${project.artifactId}</name>
<url>https://github.com/6tail/lunar-java</url>
<description>a calendar library for Solar and Chinese Lunar</description>
Expand Down
25 changes: 10 additions & 15 deletions src/main/java/com/nlf/calendar/Solar.java
Original file line number Diff line number Diff line change
Expand Up @@ -714,19 +714,17 @@ public Solar nextYear(int years) {
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);
}

Expand All @@ -740,18 +738,15 @@ public Solar nextMonth(int months) {
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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nlf/calendar/util/LunarUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,"天灸日"));
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/test/SolarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,28 @@ public void test26(){
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());
}

}

0 comments on commit ceac1af

Please sign in to comment.