Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbab78d641 | ||
|
|
a44ced263d | ||
|
|
bd19489441 | ||
|
|
a235e076db | ||
|
|
4995e3f9d0 | ||
|
|
554c474e4d |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.13</version>
|
||||
<version>1.1.15</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.1.13</version>
|
||||
<version>1.1.15</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.13</version>
|
||||
<version>1.1.15</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>
|
||||
|
||||
@@ -30,11 +30,11 @@ public class EightChar {
|
||||
|
||||
{
|
||||
//阳
|
||||
put("甲", 11);
|
||||
put("丙", 2);
|
||||
put("戊", 2);
|
||||
put("庚", 5);
|
||||
put("壬", 8);
|
||||
put("甲", 1);
|
||||
put("丙", 10);
|
||||
put("戊", 10);
|
||||
put("庚", 7);
|
||||
put("壬", 4);
|
||||
//阴
|
||||
put("乙", 6);
|
||||
put("丁", 9);
|
||||
|
||||
@@ -53,7 +53,8 @@ public class LiuNian {
|
||||
* @return 干支
|
||||
*/
|
||||
public String getGanZhi() {
|
||||
int offset = LunarUtil.getJiaZiIndex(lunar.getYearInGanZhiExact()) + this.index;
|
||||
// 干支与出生日期和起运日期都没关系
|
||||
int offset = LunarUtil.getJiaZiIndex(lunar.getJieQiTable().get("立春").getLunar().getYearInGanZhiExact()) + this.index;
|
||||
if (daYun.getIndex() > 0) {
|
||||
offset += daYun.getStartAge() - 1;
|
||||
}
|
||||
|
||||
@@ -191,6 +191,15 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(9, yun.getStartMonth());
|
||||
Assert.assertEquals(20, yun.getStartDay());
|
||||
Assert.assertEquals("1973-09-12", yun.getStartSolar().toYmd());
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
Assert.assertEquals(9, yun.getStartYear());
|
||||
Assert.assertEquals(0, yun.getStartMonth());
|
||||
Assert.assertEquals(10, yun.getStartDay());
|
||||
Assert.assertEquals("2001-02-12", yun.getStartSolar().toYmd());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,6 +225,25 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(endAges[i], daYun.getEndAge());
|
||||
Assert.assertEquals(yearGanZhi[i], daYun.getGanZhi());
|
||||
}
|
||||
|
||||
startYears = new int[]{1992, 2001, 2011, 2021, 2031, 2041, 2051, 2061, 2071, 2081};
|
||||
endYears = new int[]{2000, 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090};
|
||||
startAges = new int[]{1, 10, 20, 30, 40, 50, 60, 70, 80, 90};
|
||||
endAges = new int[]{9, 19, 29, 39, 49, 59, 69, 79, 89, 99};
|
||||
yearGanZhi = new String[]{"", "庚子", "己亥", "戊戌", "丁酉", "丙申", "乙未", "甲午", "癸巳", "壬辰"};
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
l = yun.getDaYun();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
DaYun daYun = l[i];
|
||||
Assert.assertEquals(startYears[i], daYun.getStartYear());
|
||||
Assert.assertEquals(endYears[i], daYun.getEndYear());
|
||||
Assert.assertEquals(startAges[i], daYun.getStartAge());
|
||||
Assert.assertEquals(endAges[i], daYun.getEndAge());
|
||||
Assert.assertEquals(yearGanZhi[i], daYun.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,6 +326,23 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
years = new int[]{1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000};
|
||||
ages = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
ganZhi = new String[]{"壬申","癸酉","甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰"};
|
||||
l = daYun[0].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,6 +377,19 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(ages[i], xiaoYun.getAge());
|
||||
Assert.assertEquals(years[i] + "年", ganZhi[i], xiaoYun.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
ganZhi = new String[]{"丁巳", "丙辰", "乙卯", "甲寅", "癸丑", "壬子","辛亥","庚戌","己酉"};
|
||||
l = daYun[0].getXiaoYun();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
XiaoYun xiaoYun = l[i];
|
||||
Assert.assertEquals(ganZhi[i], xiaoYun.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,6 +418,21 @@ public class BaZiTestNew {
|
||||
LiuYue liuYue = l[i];
|
||||
Assert.assertEquals(ganZhi[i], liuYue.getGanZhi());
|
||||
}
|
||||
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
ganZhi = new String[]{"壬寅", "癸卯", "甲辰", "乙巳", "丙午", "丁未", "戊申", "己酉", "庚戌", "辛亥", "壬子", "癸丑"};
|
||||
liuNian = daYun[0].getLiuNian();
|
||||
l = liuNian[0].getLiuYue();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuYue liuYue = l[i];
|
||||
Assert.assertEquals(ganZhi[i], liuYue.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,10 +87,90 @@ public class BaZiTest {
|
||||
Solar solar = new Solar(2005, 12, 23, 8, 37, 0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱地势", "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals("月柱地势", "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals("日柱地势", "死", eightChar.getDayDiShi());
|
||||
Assert.assertEquals("时柱地势", "墓", eightChar.getTimeDiShi());
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "死", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "墓", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 18, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "病", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "死", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "衰", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "绝", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 19, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "胎", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "绝", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "长生", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "死", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 20, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "绝", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "胎", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "病", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "长生", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 21, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "胎", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "绝", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "冠带", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "死", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 22, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "绝", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "胎", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "帝旺", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "长生", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 23, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "死", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "病", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "沐浴", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "帝旺", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 24, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "长生", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "沐浴", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "衰", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "临官", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 25, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "帝旺", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "临官", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "长生", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "沐浴", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 26, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "帝旺", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "病", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "病", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 27, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "沐浴", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "养", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "胎", eightChar.getTimeDiShi());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user