Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60dde2c619 | ||
|
|
8fb86c0887 | ||
|
|
3a9fe80b5d |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.6tail</groupId>
|
<groupId>cn.6tail</groupId>
|
||||||
<artifactId>lunar</artifactId>
|
<artifactId>lunar</artifactId>
|
||||||
<version>1.3.0</version>
|
<version>1.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.6tail</groupId>
|
<groupId>cn.6tail</groupId>
|
||||||
<artifactId>lunar</artifactId>
|
<artifactId>lunar</artifactId>
|
||||||
<version>1.3.0</version>
|
<version>1.3.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
|||||||
<groupId>cn.6tail</groupId>
|
<groupId>cn.6tail</groupId>
|
||||||
<artifactId>lunar</artifactId>
|
<artifactId>lunar</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.3.0</version>
|
<version>1.3.2</version>
|
||||||
<name>${project.groupId}:${project.artifactId}</name>
|
<name>${project.groupId}:${project.artifactId}</name>
|
||||||
<url>https://github.com/6tail/lunar-java</url>
|
<url>https://github.com/6tail/lunar-java</url>
|
||||||
<description>a calendar library for Solar and Chinese Lunar</description>
|
<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));
|
throw new IllegalArgumentException(String.format("wrong solar year %d month %d day %d", year, month, day));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hour < 0 || hour > 23) {
|
if (month < 1 || month > 12) {
|
||||||
throw new IllegalArgumentException(String.format("wrong hour %d", hour));
|
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) {
|
if (minute < 0 || minute > 59) {
|
||||||
throw new IllegalArgumentException(String.format("wrong minute %d", minute));
|
throw new IllegalArgumentException(String.format("wrong minute %d", minute));
|
||||||
@@ -293,9 +296,13 @@ public class Solar {
|
|||||||
offsetYear += 60;
|
offsetYear += 60;
|
||||||
}
|
}
|
||||||
int startYear = today.getYear() - offsetYear - 1;
|
int startYear = today.getYear() - offsetYear - 1;
|
||||||
while (startYear >= baseYear) {
|
while (true) {
|
||||||
years.add(startYear);
|
years.add(startYear);
|
||||||
startYear -= 60;
|
startYear -= 60;
|
||||||
|
if (startYear < baseYear) {
|
||||||
|
years.add(baseYear);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int hour = 0;
|
int hour = 0;
|
||||||
String timeZhi = timeGanZhi.substring(1);
|
String timeZhi = timeGanZhi.substring(1);
|
||||||
@@ -614,30 +621,35 @@ public class Solar {
|
|||||||
public boolean isAfter(Solar solar) {
|
public boolean isAfter(Solar solar) {
|
||||||
if (year > solar.getYear()) {
|
if (year > solar.getYear()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (year < solar.getYear()) {
|
}
|
||||||
|
if (year < solar.getYear()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (month > solar.getMonth()) {
|
if (month > solar.getMonth()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (month < solar.getMonth()) {
|
}
|
||||||
|
if (month < solar.getMonth()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (day > solar.getDay()) {
|
if (day > solar.getDay()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (day < solar.getDay()) {
|
}
|
||||||
|
if (day < solar.getDay()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (hour > solar.getHour()) {
|
if (hour > solar.getHour()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (hour < solar.getHour()) {
|
}
|
||||||
|
if (hour < solar.getHour()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (minute > solar.getMinute()) {
|
if (minute > solar.getMinute()) {
|
||||||
return true;
|
return true;
|
||||||
} else if (minute < solar.getMinute()) {
|
}
|
||||||
|
if (minute < solar.getMinute()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return second > solar.second;
|
return second > solar.getSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -648,30 +660,35 @@ public class Solar {
|
|||||||
public boolean isBefore(Solar solar) {
|
public boolean isBefore(Solar solar) {
|
||||||
if (year > solar.getYear()) {
|
if (year > solar.getYear()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (year < solar.getYear()) {
|
}
|
||||||
|
if (year < solar.getYear()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (month > solar.getMonth()) {
|
if (month > solar.getMonth()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (month < solar.getMonth()) {
|
}
|
||||||
|
if (month < solar.getMonth()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (day > solar.getDay()) {
|
if (day > solar.getDay()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (day < solar.getDay()) {
|
}
|
||||||
|
if (day < solar.getDay()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (hour > solar.getHour()) {
|
if (hour > solar.getHour()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (hour < solar.getHour()) {
|
}
|
||||||
|
if (hour < solar.getHour()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (minute > solar.getMinute()) {
|
if (minute > solar.getMinute()) {
|
||||||
return false;
|
return false;
|
||||||
} else if (minute < solar.getMinute()) {
|
}
|
||||||
|
if (minute < solar.getMinute()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return second < solar.second;
|
return second < solar.getSecond();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -687,8 +704,7 @@ public class Solar {
|
|||||||
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++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -715,8 +731,7 @@ public class Solar {
|
|||||||
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++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -738,33 +753,36 @@ public class Solar {
|
|||||||
int y = year;
|
int y = year;
|
||||||
int m = month;
|
int m = month;
|
||||||
int d = day;
|
int d = day;
|
||||||
|
if (1582 == y && 10 == m) {
|
||||||
|
if (d > 4) {
|
||||||
|
d -= 10;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (days > 0) {
|
if (days > 0) {
|
||||||
d = day + days;
|
d += days;
|
||||||
int daysInMonth = SolarUtil.getDaysOfMonth(y, m);
|
int 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) {
|
||||||
int 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package test;
|
package test;
|
||||||
|
|
||||||
|
import com.nlf.calendar.Lunar;
|
||||||
import com.nlf.calendar.Solar;
|
import com.nlf.calendar.Solar;
|
||||||
import com.nlf.calendar.util.SolarUtil;
|
import com.nlf.calendar.util.SolarUtil;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
@@ -145,4 +146,29 @@ public class SolarTest {
|
|||||||
Assert.assertEquals(355, days);
|
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