diff --git a/README.md b/README.md
index 25164ab..375fc2a 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
cn.6tail
lunar
- 1.3.1
+ 1.3.2
```
diff --git a/README_EN.md b/README_EN.md
index 0adae11..d3c92e0 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
cn.6tail
lunar
- 1.3.1
+ 1.3.2
```
diff --git a/pom.xml b/pom.xml
index 83e9565..301dab2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
cn.6tail
lunar
jar
- 1.3.1
+ 1.3.2
${project.groupId}:${project.artifactId}
https://github.com/6tail/lunar-java
a calendar library for Solar and Chinese Lunar
diff --git a/src/main/java/com/nlf/calendar/Solar.java b/src/main/java/com/nlf/calendar/Solar.java
index b6448ae..3580534 100644
--- a/src/main/java/com/nlf/calendar/Solar.java
+++ b/src/main/java/com/nlf/calendar/Solar.java
@@ -86,8 +86,11 @@ public Solar(int year, int month, int day, int hour, int minute, int second) {
throw new IllegalArgumentException(String.format("wrong solar year %d month %d day %d", year, month, day));
}
}
- if (hour < 0 || hour > 23) {
- throw new IllegalArgumentException(String.format("wrong hour %d", hour));
+ if (month < 1 || month > 12) {
+ throw new IllegalArgumentException(String.format("wrong month %d", month));
+ }
+ if (day < 1 || day > 31) {
+ throw new IllegalArgumentException(String.format("wrong day %d", day));
}
if (minute < 0 || minute > 59) {
throw new IllegalArgumentException(String.format("wrong minute %d", minute));
@@ -618,30 +621,35 @@ public int subtractMinute(Solar solar) {
public boolean isAfter(Solar solar) {
if (year > solar.getYear()) {
return true;
- } else if (year < solar.getYear()) {
+ }
+ if (year < solar.getYear()) {
return false;
}
if (month > solar.getMonth()) {
return true;
- } else if (month < solar.getMonth()) {
+ }
+ if (month < solar.getMonth()) {
return false;
}
if (day > solar.getDay()) {
return true;
- } else if (day < solar.getDay()) {
+ }
+ if (day < solar.getDay()) {
return false;
}
if (hour > solar.getHour()) {
return true;
- } else if (hour < solar.getHour()) {
+ }
+ if (hour < solar.getHour()) {
return false;
}
if (minute > solar.getMinute()) {
return true;
- } else if (minute < solar.getMinute()) {
+ }
+ if (minute < solar.getMinute()) {
return false;
}
- return second > solar.second;
+ return second > solar.getSecond();
}
/**
@@ -652,30 +660,35 @@ public boolean isAfter(Solar solar) {
public boolean isBefore(Solar solar) {
if (year > solar.getYear()) {
return false;
- } else if (year < solar.getYear()) {
+ }
+ if (year < solar.getYear()) {
return true;
}
if (month > solar.getMonth()) {
return false;
- } else if (month < solar.getMonth()) {
+ }
+ if (month < solar.getMonth()) {
return true;
}
if (day > solar.getDay()) {
return false;
- } else if (day < solar.getDay()) {
+ }
+ if (day < solar.getDay()) {
return true;
}
if (hour > solar.getHour()) {
return false;
- } else if (hour < solar.getHour()) {
+ }
+ if (hour < solar.getHour()) {
return true;
}
if (minute > solar.getMinute()) {
return false;
- } else if (minute < solar.getMinute()) {
+ }
+ if (minute < solar.getMinute()) {
return true;
}
- return second < solar.second;
+ return second < solar.getSecond();
}
/**
@@ -691,8 +704,7 @@ public Solar nextYear(int years) {
if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
- d -= 28;
- m++;
+ d = 28;
}
}
}
@@ -719,8 +731,7 @@ public Solar nextMonth(int months) {
if (2 == m) {
if (d > 28) {
if (!SolarUtil.isLeapYear(y)) {
- d -= 28;
- m++;
+ d = 28;
}
}
}
@@ -742,33 +753,36 @@ public Solar next(int days) {
int y = year;
int m = month;
int d = day;
+ if (1582 == y && 10 == m) {
+ if (d > 4) {
+ d -= 10;
+ }
+ }
if (days > 0) {
- d = day + days;
+ d += days;
int 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) {
- int 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;
}
}
diff --git a/src/test/java/test/SolarTest.java b/src/test/java/test/SolarTest.java
index c352107..431b493 100644
--- a/src/test/java/test/SolarTest.java
+++ b/src/test/java/test/SolarTest.java
@@ -1,5 +1,6 @@
package test;
+import com.nlf.calendar.Lunar;
import com.nlf.calendar.Solar;
import com.nlf.calendar.util.SolarUtil;
import org.junit.Assert;
@@ -145,4 +146,29 @@ public void test22(){
Assert.assertEquals(355, days);
}
+ @Test
+ public void test23(){
+ Solar solar = Solar.fromYmd(1991, 5, 12);
+ Lunar lunar = solar.getLunar();
+ Assert.assertEquals("壬午", lunar.getDayInGanZhi());
+ }
+
+ @Test
+ public void test24(){
+ Solar solar = new Solar(1582, 10, 15);
+ Assert.assertEquals("1582-09-30", solar.next(-5).toYmd());
+ }
+
+ @Test
+ public void test25(){
+ Solar solar = new Solar(1582, 10, 15);
+ Assert.assertEquals("1582-10-04", solar.next(-1).toYmd());
+ }
+
+ @Test
+ public void test26(){
+ Solar solar = new Solar(1582, 10, 15);
+ Assert.assertEquals("1582-09-29", solar.next(-6).toYmd());
+ }
+
}