Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2eb2b508ee | ||
|
|
04195c201b | ||
|
|
b9acfec4d5 | ||
|
|
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.16</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.16</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.16</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);
|
||||
@@ -44,6 +44,11 @@ public class EightChar {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 流派,2晚子时日柱按当天,1晚子时日柱按明天
|
||||
*/
|
||||
protected int sect = 2;
|
||||
|
||||
/**
|
||||
* 阴历
|
||||
*/
|
||||
@@ -62,6 +67,24 @@ public class EightChar {
|
||||
return getYear() + " " + getMonth() + " " + getDay() + " " + getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流派
|
||||
*
|
||||
* @return 流派,2晚子时日柱按当天,1晚子时日柱按明天
|
||||
*/
|
||||
public int getSect() {
|
||||
return sect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置流派
|
||||
*
|
||||
* @param sect 流派,2晚子时日柱按当天,1晚子时日柱按明天,其他值默认为2
|
||||
*/
|
||||
public void setSect(int sect) {
|
||||
this.sect = (1 == sect) ? 1 : 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年柱
|
||||
*
|
||||
@@ -104,7 +127,7 @@ public class EightChar {
|
||||
* @return 五行
|
||||
*/
|
||||
public String getYearWuXing() {
|
||||
return LunarUtil.WU_XING_GAN.get(lunar.getYearGanExact()) + LunarUtil.WU_XING_ZHI.get(lunar.getYearZhiExact());
|
||||
return LunarUtil.WU_XING_GAN.get(getYearGan()) + LunarUtil.WU_XING_ZHI.get(getYearZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,9 +166,27 @@ public class EightChar {
|
||||
return getShiShenZhi(getYearZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日干下标
|
||||
*
|
||||
* @return 日干下标,0-9
|
||||
*/
|
||||
public int getDayGanIndex() {
|
||||
return 2 == sect ? lunar.getDayGanIndexExact2() : lunar.getDayGanIndexExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日支下标
|
||||
*
|
||||
* @return 日支下标,0-11
|
||||
*/
|
||||
public int getDayZhiIndex() {
|
||||
return 2 == sect ? lunar.getDayZhiIndexExact2() : lunar.getDayZhiIndexExact();
|
||||
}
|
||||
|
||||
private String getDiShi(int zhiIndex) {
|
||||
int offset = CHANG_SHENG_OFFSET.get(getDayGan());
|
||||
int index = offset + (lunar.getDayGanIndexExact() % 2 == 0 ? zhiIndex : -zhiIndex);
|
||||
int index = offset + (getDayGanIndex() % 2 == 0 ? zhiIndex : -zhiIndex);
|
||||
if (index >= 12) {
|
||||
index -= 12;
|
||||
}
|
||||
@@ -206,7 +247,7 @@ public class EightChar {
|
||||
* @return 五行
|
||||
*/
|
||||
public String getMonthWuXing() {
|
||||
return LunarUtil.WU_XING_GAN.get(lunar.getMonthGanExact()) + LunarUtil.WU_XING_ZHI.get(lunar.getMonthZhiExact());
|
||||
return LunarUtil.WU_XING_GAN.get(getMonthGan()) + LunarUtil.WU_XING_ZHI.get(getMonthZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,7 +292,7 @@ public class EightChar {
|
||||
* @return 日柱
|
||||
*/
|
||||
public String getDay() {
|
||||
return lunar.getDayInGanZhiExact();
|
||||
return 2 == sect ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +301,7 @@ public class EightChar {
|
||||
* @return 天干
|
||||
*/
|
||||
public String getDayGan() {
|
||||
return lunar.getDayGanExact();
|
||||
return 2 == sect ? lunar.getDayGanExact2() : lunar.getDayGanExact();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +310,7 @@ public class EightChar {
|
||||
* @return 地支
|
||||
*/
|
||||
public String getDayZhi() {
|
||||
return lunar.getDayZhiExact();
|
||||
return 2 == sect ? lunar.getDayZhiExact2() : lunar.getDayZhiExact();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,7 +328,7 @@ public class EightChar {
|
||||
* @return 五行
|
||||
*/
|
||||
public String getDayWuXing() {
|
||||
return LunarUtil.WU_XING_GAN.get(lunar.getDayGanExact()) + LunarUtil.WU_XING_ZHI.get(lunar.getDayZhiExact());
|
||||
return LunarUtil.WU_XING_GAN.get(getDayGan()) + LunarUtil.WU_XING_ZHI.get(getDayZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,7 +364,7 @@ public class EightChar {
|
||||
* @return 地势
|
||||
*/
|
||||
public String getDayDiShi() {
|
||||
return getDiShi(lunar.getDayZhiIndexExact());
|
||||
return getDiShi(getDayZhiIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -526,65 +567,73 @@ public class EightChar {
|
||||
|
||||
/**
|
||||
* 获取年柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getYearXun(){
|
||||
public String getYearXun() {
|
||||
return lunar.getYearXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getYearXunKong(){
|
||||
public String getYearXunKong() {
|
||||
return lunar.getYearXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getMonthXun(){
|
||||
public String getMonthXun() {
|
||||
return lunar.getMonthXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getMonthXunKong(){
|
||||
public String getMonthXunKong() {
|
||||
return lunar.getMonthXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXun(){
|
||||
return lunar.getDayXunExact();
|
||||
public String getDayXun() {
|
||||
return 2 == sect ? lunar.getDayXunExact2() : lunar.getDayXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getDayXunKong(){
|
||||
return lunar.getDayXunKongExact();
|
||||
public String getDayXunKong() {
|
||||
return 2 == sect ? lunar.getDayXunKongExact2() : lunar.getDayXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getTimeXun(){
|
||||
public String getTimeXun() {
|
||||
return lunar.getTimeXun();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getTimeXunKong(){
|
||||
public String getTimeXunKong() {
|
||||
return lunar.getTimeXunKong();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,10 +55,14 @@ public class Lunar{
|
||||
private int dayGanIndex;
|
||||
/** 日对应的地支下标,0-11 */
|
||||
private int dayZhiIndex;
|
||||
/** 日对应的天干下标(最精确的,供八字用,晚子时算第二天),0-9 */
|
||||
/** 日对应的天干下标(八字流派1,晚子时日柱算明天),0-9 */
|
||||
private int dayGanIndexExact;
|
||||
/** 日对应的地支下标(最精确的,供八字用,晚子时算第二天),0-11 */
|
||||
/** 日对应的地支下标(八字流派1,晚子时日柱算明天),0-11 */
|
||||
private int dayZhiIndexExact;
|
||||
/** 日对应的天干下标(八字流派2,晚子时日柱算当天),0-9 */
|
||||
private int dayGanIndexExact2;
|
||||
/** 日对应的地支下标(八字流派2,晚子时日柱算当天),0-11 */
|
||||
private int dayZhiIndexExact2;
|
||||
/** 月对应的天干下标(以节交接当天起算),0-9 */
|
||||
private int monthGanIndex;
|
||||
/** 月对应的地支下标(以节交接当天起算),0-11 */
|
||||
@@ -564,7 +568,11 @@ public class Lunar{
|
||||
int dayGanExact = dayGanIndex;
|
||||
int dayZhiExact = dayZhiIndex;
|
||||
|
||||
// 晚子时(夜子/子夜)应算作第二天
|
||||
// 八字流派2,晚子时(夜子/子夜)日柱算当天
|
||||
dayGanIndexExact2 = dayGanExact;
|
||||
dayZhiIndexExact2 = dayZhiExact;
|
||||
|
||||
// 八字流派1,晚子时(夜子/子夜)日柱算明天
|
||||
String hm = (hour<10?"0":"")+hour+":"+(minute<10?"0":"")+minute;
|
||||
if(hm.compareTo("23:00")>=0&&hm.compareTo("23:59")<=0){
|
||||
dayGanExact++;
|
||||
@@ -807,7 +815,7 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支纪日(日柱,晚子时算第二天)
|
||||
* 获取干支纪日(日柱,晚子时日柱算明天)
|
||||
*
|
||||
* @return 干支纪日(日柱),如己卯
|
||||
*/
|
||||
@@ -815,6 +823,15 @@ public class Lunar{
|
||||
return getDayGanExact()+getDayZhiExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支纪日(日柱,晚子时日柱算当天)
|
||||
*
|
||||
* @return 干支纪日(日柱),如己卯
|
||||
*/
|
||||
public String getDayInGanZhiExact2(){
|
||||
return getDayGanExact2()+getDayZhiExact2();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日天干
|
||||
*
|
||||
@@ -825,7 +842,7 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日天干(晚子时算第二天)
|
||||
* 获取日天干(晚子时日柱算明天)
|
||||
*
|
||||
* @return 日天干,如甲
|
||||
*/
|
||||
@@ -833,6 +850,15 @@ public class Lunar{
|
||||
return LunarUtil.GAN[dayGanIndexExact+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日天干(晚子时日柱算当天)
|
||||
*
|
||||
* @return 日天干,如甲
|
||||
*/
|
||||
public String getDayGanExact2(){
|
||||
return LunarUtil.GAN[dayGanIndexExact2+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日地支
|
||||
*
|
||||
@@ -843,7 +869,7 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日地支(晚子时算第二天)
|
||||
* 获取日地支(晚子时日柱算明天)
|
||||
*
|
||||
* @return 日地支,如卯
|
||||
*/
|
||||
@@ -851,6 +877,15 @@ public class Lunar{
|
||||
return LunarUtil.ZHI[dayZhiIndexExact+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日地支(晚子时日柱算当天)
|
||||
*
|
||||
* @return 日地支,如卯
|
||||
*/
|
||||
public String getDayZhiExact2(){
|
||||
return LunarUtil.ZHI[dayZhiIndexExact2+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年生肖
|
||||
*
|
||||
@@ -2308,10 +2343,18 @@ public class Lunar{
|
||||
return dayGanIndexExact;
|
||||
}
|
||||
|
||||
public int getDayGanIndexExact2() {
|
||||
return dayGanIndexExact2;
|
||||
}
|
||||
|
||||
public int getDayZhiIndexExact() {
|
||||
return dayZhiIndexExact;
|
||||
}
|
||||
|
||||
public int getDayZhiIndexExact2() {
|
||||
return dayZhiIndexExact2;
|
||||
}
|
||||
|
||||
public int getMonthGanIndexExact() {
|
||||
return monthGanIndexExact;
|
||||
}
|
||||
@@ -2479,13 +2522,21 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日所在旬(晚子时算第二天)
|
||||
* 获取日所在旬(晚子时日柱算明天)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXunExact(){
|
||||
return LunarUtil.getXun(getDayInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日所在旬(晚子时日柱算当天)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXunExact2(){
|
||||
return LunarUtil.getXun(getDayInGanZhiExact2());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡
|
||||
* @return 空亡(旬空)
|
||||
@@ -2495,13 +2546,21 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡(晚子时算第二天)
|
||||
* 获取值日空亡(晚子时日柱算明天)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getDayXunKongExact(){
|
||||
return LunarUtil.getXunKong(getDayInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡(晚子时日柱算当天)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getDayXunKongExact2(){
|
||||
return LunarUtil.getXunKong(getDayInGanZhiExact2());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时辰所在旬
|
||||
* @return 旬
|
||||
|
||||
@@ -208,7 +208,7 @@ public class Solar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过八字获取阳历列表
|
||||
* 通过八字获取阳历列表(晚子时日柱按当天)
|
||||
* @param yearGanZhi 年柱
|
||||
* @param monthGanZhi 月柱
|
||||
* @param dayGanZhi 日柱
|
||||
@@ -216,6 +216,20 @@ public class Solar{
|
||||
* @return 符合的阳历列表
|
||||
*/
|
||||
public static List<Solar> fromBaZi(String yearGanZhi,String monthGanZhi,String dayGanZhi,String timeGanZhi){
|
||||
return fromBaZi(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi,2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过八字获取阳历列表
|
||||
* @param yearGanZhi 年柱
|
||||
* @param monthGanZhi 月柱
|
||||
* @param dayGanZhi 日柱
|
||||
* @param timeGanZhi 时柱
|
||||
* @param sect 流派,2晚子时日柱按当天,1晚子时日柱按明天
|
||||
* @return 符合的阳历列表
|
||||
*/
|
||||
public static List<Solar> fromBaZi(String yearGanZhi,String monthGanZhi,String dayGanZhi,String timeGanZhi,int sect){
|
||||
sect = (1==sect)?1:2;
|
||||
List<Solar> l = new ArrayList<Solar>();
|
||||
Solar today = new Solar();
|
||||
Lunar lunar = today.getLunar();
|
||||
@@ -271,7 +285,8 @@ public class Solar{
|
||||
Solar solar = new Solar(year, month, day, hour, 0, 0);
|
||||
while (counter < 61) {
|
||||
lunar = solar.getLunar();
|
||||
if (lunar.getYearInGanZhiExact().equals(yearGanZhi) && lunar.getMonthInGanZhiExact().equals(monthGanZhi) && lunar.getDayInGanZhiExact().equals(dayGanZhi) && lunar.getTimeInGanZhi().equals(timeGanZhi)) {
|
||||
String dgz = (2==sect)?lunar.getDayInGanZhiExact2():lunar.getDayInGanZhiExact();
|
||||
if (lunar.getYearInGanZhiExact().equals(yearGanZhi) && lunar.getMonthInGanZhiExact().equals(monthGanZhi) && dgz.equals(dayGanZhi) && lunar.getTimeInGanZhi().equals(timeGanZhi)) {
|
||||
l.add(solar);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,12 @@ public class BaZiTest {
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
|
||||
eightChar.setSect(1);
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "辛丑", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
|
||||
@@ -87,10 +93,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