v1.2.27 修复立春比春节早时年九星的错误;新增阳历月中获取周。
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -14,3 +14,4 @@ target/
|
|||||||
*.diff
|
*.diff
|
||||||
*.patch
|
*.patch
|
||||||
*.tmp
|
*.tmp
|
||||||
|
.DS_Store
|
||||||
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.6tail</groupId>
|
<groupId>cn.6tail</groupId>
|
||||||
<artifactId>lunar</artifactId>
|
<artifactId>lunar</artifactId>
|
||||||
<version>1.2.25</version>
|
<version>1.2.27</version>
|
||||||
</dependency>
|
</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>
|
<dependency>
|
||||||
<groupId>cn.6tail</groupId>
|
<groupId>cn.6tail</groupId>
|
||||||
<artifactId>lunar</artifactId>
|
<artifactId>lunar</artifactId>
|
||||||
<version>1.2.25</version>
|
<version>1.2.27</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -49,4 +49,4 @@ Output:
|
|||||||
|
|
||||||
## Documentation
|
## 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")
|
||||||
|
|||||||
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.2.26</version>
|
<version>1.2.27</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>
|
||||||
|
|||||||
@@ -2049,13 +2049,16 @@ public class Lunar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected NineStar getYearNineStar(String yearInGanZhi) {
|
protected NineStar getYearNineStar(String yearInGanZhi) {
|
||||||
int index = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
int indexExact = LunarUtil.getJiaZiIndex(yearInGanZhi) + 1;
|
||||||
int yearOffset = 0;
|
int index = LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1;
|
||||||
if (index != LunarUtil.getJiaZiIndex(this.getYearInGanZhi()) + 1) {
|
int yearOffset = indexExact - index;
|
||||||
yearOffset = -1;
|
if (yearOffset > 1) {
|
||||||
|
yearOffset -= 60;
|
||||||
|
} else if (yearOffset < -1) {
|
||||||
|
yearOffset += 60;
|
||||||
}
|
}
|
||||||
int yuan = ((this.year + yearOffset + 2696) / 60) % 3;
|
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) {
|
if (0 == offset) {
|
||||||
offset = 9;
|
offset = 9;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,26 @@ public class SolarMonth {
|
|||||||
return l;
|
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);
|
||||||
|
Solar firstDay = week.getFirstDay();
|
||||||
|
while (true) {
|
||||||
|
l.add(week);
|
||||||
|
week = week.next(1, false);
|
||||||
|
firstDay = week.getFirstDay();
|
||||||
|
if (firstDay.getYear() > year || firstDay.getMonth() > month) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取往后推几个月的阳历月,如果要往前推,则月数用负数
|
* 获取往后推几个月的阳历月,如果要往前推,则月数用负数
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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
|
@Test
|
||||||
public void test4() {
|
public void test4() {
|
||||||
Lunar lunar = Lunar.fromYmd(1985, 12, 27);
|
Lunar lunar = Lunar.fromYmd(1985, 12, 27);
|
||||||
@@ -295,4 +303,14 @@ public class BaZiTest {
|
|||||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,18 +161,6 @@ public class LunarTest {
|
|||||||
Assert.assertEquals("2033-12-22", lunar.getSolar().toYmd());
|
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
|
@Test
|
||||||
public void test25() {
|
public void test25() {
|
||||||
Solar solar = new Solar(2021, 6, 7, 21, 18, 0);
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user