v1.3.11 修复命宫、身宫的错误。
This commit is contained in:
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.3.10</version>
|
||||
<version>1.3.11</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.10</version>
|
||||
<version>1.3.11</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.10</version>
|
||||
<version>1.3.11</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>
|
||||
|
||||
@@ -501,27 +501,27 @@ public class EightChar {
|
||||
public String getMingGong() {
|
||||
int monthZhiIndex = 0;
|
||||
int timeZhiIndex = 0;
|
||||
String monthZhi = getMonthZhi();
|
||||
String timeZhi = getTimeZhi();
|
||||
for (int i = 0, j = MONTH_ZHI.length; i < j; i++) {
|
||||
String zhi = MONTH_ZHI[i];
|
||||
if (lunar.getMonthZhiExact().equals(zhi)) {
|
||||
if (monthZhi.equals(MONTH_ZHI[i])) {
|
||||
monthZhiIndex = i;
|
||||
break;
|
||||
}
|
||||
if (lunar.getTimeZhi().equals(zhi)) {
|
||||
}
|
||||
for (int i = 0, j = MONTH_ZHI.length; i < j; i++) {
|
||||
if (timeZhi.equals(MONTH_ZHI[i])) {
|
||||
timeZhiIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int zhiIndex = 26 - (monthZhiIndex + timeZhiIndex);
|
||||
if (zhiIndex > 12) {
|
||||
zhiIndex -= 12;
|
||||
int offset = monthZhiIndex + timeZhiIndex;
|
||||
offset = (offset >= 14 ? 26 : 14) - offset;
|
||||
int ganIndex = (lunar.getYearGanIndexExact() + 1) * 2 + offset;
|
||||
while (ganIndex > 10) {
|
||||
ganIndex -= 10;
|
||||
}
|
||||
int jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
|
||||
if (jiaZiIndex >= 60) {
|
||||
jiaZiIndex -= 60;
|
||||
}
|
||||
if (jiaZiIndex < 0) {
|
||||
jiaZiIndex += 60;
|
||||
}
|
||||
return LunarUtil.JIA_ZI[jiaZiIndex];
|
||||
return LunarUtil.GAN[ganIndex] + MONTH_ZHI[offset];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -541,27 +541,29 @@ public class EightChar {
|
||||
public String getShenGong() {
|
||||
int monthZhiIndex = 0;
|
||||
int timeZhiIndex = 0;
|
||||
String monthZhi = getMonthZhi();
|
||||
String timeZhi = getTimeZhi();
|
||||
for (int i = 0, j = MONTH_ZHI.length; i < j; i++) {
|
||||
String zhi = MONTH_ZHI[i];
|
||||
if (lunar.getMonthZhiExact().equals(zhi)) {
|
||||
if (monthZhi.equals(MONTH_ZHI[i])) {
|
||||
monthZhiIndex = i;
|
||||
break;
|
||||
}
|
||||
if (lunar.getTimeZhi().equals(zhi)) {
|
||||
}
|
||||
for (int i = 0, j = MONTH_ZHI.length; i < j; i++) {
|
||||
if (timeZhi.equals(LunarUtil.ZHI[i])) {
|
||||
timeZhiIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
int zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
|
||||
if (zhiIndex > 12) {
|
||||
zhiIndex -= 12;
|
||||
int offset = monthZhiIndex + timeZhiIndex;
|
||||
while (offset > 12) {
|
||||
offset -= 12;
|
||||
}
|
||||
int jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
|
||||
if (jiaZiIndex >= 60) {
|
||||
jiaZiIndex -= 60;
|
||||
int ganIndex = (lunar.getYearGanIndexExact() + 1) * 2 + (offset % 12);
|
||||
while (ganIndex > 10) {
|
||||
ganIndex -= 10;
|
||||
}
|
||||
if (jiaZiIndex < 0) {
|
||||
jiaZiIndex += 60;
|
||||
}
|
||||
return LunarUtil.JIA_ZI[jiaZiIndex];
|
||||
return LunarUtil.GAN[ganIndex] + MONTH_ZHI[offset];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -234,7 +234,7 @@ public class BaZiTest {
|
||||
@Test
|
||||
public void testShenGong1() {
|
||||
Lunar lunar = new Solar(1994, 12, 6, 2, 0, 0).getLunar();
|
||||
Assert.assertEquals("身宫", "丁丑", lunar.getEightChar().getShenGong());
|
||||
Assert.assertEquals("身宫", "乙丑", lunar.getEightChar().getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -412,7 +412,7 @@ public class BaZiTest {
|
||||
Solar solar = new Solar(1986, 5, 29, 13, 37, 0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("辛丑", eightChar.getShenGong());
|
||||
Assert.assertEquals("己丑", eightChar.getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -437,4 +437,60 @@ public class BaZiTest {
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test20() {
|
||||
List<Solar> l = Solar.fromBaZi("乙未","己卯","丁丑","甲辰");
|
||||
List<String> actual = new ArrayList<String>();
|
||||
for (Solar solar : l) {
|
||||
actual.add(solar.toYmdHms());
|
||||
}
|
||||
|
||||
List<String> expected = new ArrayList<String>();
|
||||
expected.add("1955-03-17 08:00:00");
|
||||
Assert.assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test21() {
|
||||
Lunar lunar = Solar.fromYmdHms(2024, 1, 29, 9, 30, 0).getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("命宫", "癸亥", eightChar.getMingGong());
|
||||
Assert.assertEquals("身宫", "己未", eightChar.getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test22() {
|
||||
Assert.assertEquals("身宫", "丙寅", Solar.fromYmdHms(1990, 1, 27, 0, 0, 0).getLunar().getEightChar().getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test23() {
|
||||
Assert.assertEquals("甲戌", Solar.fromYmdHms(2019, 3, 7, 8, 0, 0).getLunar().getEightChar().getMingGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test24() {
|
||||
Assert.assertEquals("丁丑", Solar.fromYmdHms(2019, 3, 27, 2, 0, 0).getLunar().getEightChar().getMingGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test25() {
|
||||
Assert.assertEquals("丙寅", Lunar.fromYmdHms(1994, 5, 20, 18, 0 ,0).getEightChar().getMingGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test26() {
|
||||
Lunar lunar = Solar.fromYmdHms(1986, 2, 16, 8, 0, 0).getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("命宫", "己亥", eightChar.getMingGong());
|
||||
Assert.assertEquals("身宫", "乙未", eightChar.getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test27() {
|
||||
Lunar lunar = Solar.fromYmdHms(1972, 11, 27, 10, 0, 0).getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("身宫", "乙巳", eightChar.getShenGong());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user