v1.3.2 修复阳历推移错误的问题。
This commit is contained in:
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@@ -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.1</version>
|
||||
<version>1.3.2</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.3.1</version>
|
||||
<version>1.3.2</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>
|
||||
|
||||
@@ -86,8 +86,11 @@ public class Solar {
|
||||
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 class 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 class 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 class Solar {
|
||||
if (2 == m) {
|
||||
if (d > 28) {
|
||||
if (!SolarUtil.isLeapYear(y)) {
|
||||
d -= 28;
|
||||
m++;
|
||||
d = 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -719,8 +731,7 @@ public class Solar {
|
||||
if (2 == m) {
|
||||
if (d > 28) {
|
||||
if (!SolarUtil.isLeapYear(y)) {
|
||||
d -= 28;
|
||||
m++;
|
||||
d = 28;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -742,33 +753,36 @@ public class Solar {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 class SolarTest {
|
||||
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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user