Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3082dbbf2 | ||
|
|
12a8eec123 | ||
|
|
51afe36b4b | ||
|
|
ee0b227f75 | ||
|
|
a16767e2c7 | ||
|
|
dc0c03ff09 | ||
|
|
1aefcdcf0c |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -13,4 +13,5 @@ target/
|
||||
*.cache
|
||||
*.diff
|
||||
*.patch
|
||||
*.tmp
|
||||
*.tmp
|
||||
.DS_Store
|
||||
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.2.23</version>
|
||||
<version>1.2.28</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -53,4 +53,4 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
|
||||
## 文档
|
||||
|
||||
请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
|
||||
请移步至 [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
|
||||
|
||||
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.2.23</version>
|
||||
<version>1.2.28</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@@ -49,4 +49,4 @@ Output:
|
||||
|
||||
## Documentation
|
||||
|
||||
Please visit [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
|
||||
Please visit [https://6tail.cn/calendar/api.html](https://6tail.cn/calendar/api.html "https://6tail.cn/calendar/api.html")
|
||||
|
||||
14
pom.xml
14
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.23</version>
|
||||
<version>1.2.28</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>
|
||||
@@ -48,6 +48,7 @@
|
||||
<sourceEncoding>UTF-8</sourceEncoding>
|
||||
<source-version>1.5</source-version>
|
||||
<target-version>1.5</target-version>
|
||||
<creator>6tail</creator>
|
||||
<maven-compiler-plugin-version>3.3</maven-compiler-plugin-version>
|
||||
<maven-surefire-plugin-version>2.5</maven-surefire-plugin-version>
|
||||
<maven-javadoc-plugin-version>2.9</maven-javadoc-plugin-version>
|
||||
@@ -60,7 +61,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -104,6 +105,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<additionalparam>-Xdoclint:none</additionalparam>
|
||||
<source>${source-version}</source>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -147,13 +149,21 @@
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>2.2-beta-5</version>
|
||||
<configuration>
|
||||
<appendAssemblyId>false</appendAssemblyId>
|
||||
<finalName>${project.artifactId}-${project.version}</finalName>
|
||||
<descriptors>
|
||||
<descriptor>${basedir}/src/assembly/assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Created-By>${creator}</Created-By>
|
||||
<Built-By>${creator}</Built-By>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -183,6 +183,9 @@ public class Lunar {
|
||||
this.second = second;
|
||||
Solar noon = Solar.fromJulianDay(m.getFirstJulianDay() + lunarDay - 1);
|
||||
this.solar = Solar.fromYmdHms(noon.getYear(), noon.getMonth(), noon.getDay(), hour, minute, second);
|
||||
if (noon.getYear() != lunarYear) {
|
||||
y = LunarYear.fromYear(noon.getYear());
|
||||
}
|
||||
compute(y);
|
||||
}
|
||||
|
||||
@@ -2046,13 +2049,16 @@ public class Lunar {
|
||||
}
|
||||
|
||||
protected NineStar getYearNineStar(String yearInGanZhi) {
|
||||
int index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
||||
int yearOffset = 0;
|
||||
if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
|
||||
yearOffset = -1;
|
||||
int indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
||||
int index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1;
|
||||
int yearOffset = indexExact - index;
|
||||
if (yearOffset > 1) {
|
||||
yearOffset -= 60;
|
||||
} else if (yearOffset < -1) {
|
||||
yearOffset += 60;
|
||||
}
|
||||
int yuan = ((this.year + yearOffset + 2696) / 60) % 3;
|
||||
int offset = (62 + yuan * 3 - index) % 9;
|
||||
int offset = (62 + yuan * 3 - indexExact) % 9;
|
||||
if (0 == offset) {
|
||||
offset = 9;
|
||||
}
|
||||
@@ -2987,7 +2993,11 @@ public class Lunar {
|
||||
}
|
||||
Solar startSolar = jieQi.getSolar();
|
||||
int days = ExactDate.getDaysBetween(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay(), solar.getYear(), solar.getMonth(), solar.getDay());
|
||||
return LunarUtil.WU_HOU[(offset * 3 + days / 5) % LunarUtil.WU_HOU.length];
|
||||
int index = days / 5;
|
||||
if (index > 2) {
|
||||
index = 2;
|
||||
}
|
||||
return LunarUtil.WU_HOU[(offset * 3 + index) % LunarUtil.WU_HOU.length];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -122,6 +122,25 @@ public class SolarMonth {
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本月的阳历周列表
|
||||
* @param start 星期几作为一周的开始,1234560分别代表星期一至星期天
|
||||
* @return 周列表
|
||||
*/
|
||||
public List<SolarWeek> getWeeks(int start) {
|
||||
List<SolarWeek> l = new ArrayList<SolarWeek>();
|
||||
SolarWeek week = SolarWeek.fromYmd(year, month, 1, start);
|
||||
while (true) {
|
||||
l.add(week);
|
||||
week = week.next(1, false);
|
||||
Solar firstDay = week.getFirstDay();
|
||||
if (firstDay.getYear() > year || firstDay.getMonth() > month) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取往后推几个月的阳历月,如果要往前推,则月数用负数
|
||||
*
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -258,6 +258,14 @@ public class BaZiTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaZi2Solar1() {
|
||||
List<Solar> l = Solar.fromBaZi("壬寅","庚戌","己未","乙亥");
|
||||
for(Solar s:l){
|
||||
System.out.println(s.toFullString());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4() {
|
||||
Lunar lunar = Lunar.fromYmd(1985, 12, 27);
|
||||
@@ -276,4 +284,33 @@ public class BaZiTest {
|
||||
Assert.assertEquals("1990-04-15", lunar.getEightChar().getYun(1).getStartSolar().toYmd());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test10(){
|
||||
Lunar lunar = Solar.fromYmdHms(1988, 2, 15, 23, 30, 0).getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11(){
|
||||
Lunar lunar = Lunar.fromYmdHms(1987, 12, 28, 23, 30, 0);
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test13(){
|
||||
Lunar lunar = Lunar.fromYmdHms(1991, 4, 5, 3, 37, 0);
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "辛未", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "癸巳", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "戊子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "甲寅", eightChar.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,8 +94,11 @@ public class HolidayTest {
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
|
||||
|
||||
// 更改节假日名称
|
||||
String[] names = HolidayUtil.NAMES;
|
||||
// 自定义节假日名称
|
||||
String[] names = new String[HolidayUtil.NAMES.length];
|
||||
for (int i = 0, j = HolidayUtil.NAMES.length; i < j; i++) {
|
||||
names[i] = HolidayUtil.NAMES[i];
|
||||
}
|
||||
names[0] = "元旦";
|
||||
names[1] = "大年初一";
|
||||
|
||||
@@ -125,4 +128,17 @@ public class HolidayTest {
|
||||
Assert.assertNotNull(holiday.getTarget());
|
||||
Assert.assertEquals("2016-10-01",holiday.getTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
// 设置默认的节假日名称
|
||||
HolidayUtil.fix(HolidayUtil.NAMES, null);
|
||||
Holiday holiday = HolidayUtil.getHoliday(2010,1,1);
|
||||
Assert.assertNotNull(holiday);
|
||||
Assert.assertEquals("元旦节",holiday.getName());
|
||||
|
||||
HolidayUtil.fix("20100101~000000000000000000000000000");
|
||||
holiday = HolidayUtil.getHoliday(2010,1,1);
|
||||
Assert.assertNull(holiday);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class JieQiTest {
|
||||
@Test
|
||||
public void test8() {
|
||||
Lunar lunar = Lunar.fromYmd(2050, 12, 1);
|
||||
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("大雪").toYmdHms());
|
||||
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -161,18 +161,6 @@ public class LunarTest {
|
||||
Assert.assertEquals("2033-12-22", lunar.getSolar().toYmd());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test23() {
|
||||
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
|
||||
Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test24() {
|
||||
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
|
||||
Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test25() {
|
||||
Solar solar = new Solar(2021, 6, 7, 21, 18, 0);
|
||||
|
||||
26
src/test/java/test/NineStarTest.java
Normal file
26
src/test/java/test/NineStarTest.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class NineStarTest {
|
||||
@Test
|
||||
public void test1() {
|
||||
Lunar lunar = Solar.fromYmd(1985, 2, 19).getLunar();
|
||||
Assert.assertEquals("六", lunar.getYearNineStar().getNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
|
||||
Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
|
||||
Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
|
||||
}
|
||||
}
|
||||
@@ -103,4 +103,18 @@ public class WuHouTest {
|
||||
Assert.assertEquals(solar.toString(),"小寒 初候",lunar.getHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test15(){
|
||||
Solar solar = new Solar(2022,8,22);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"寒蝉鸣",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test16(){
|
||||
Solar solar = new Solar(2022,8,23);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"鹰乃祭鸟",lunar.getWuHou());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user