1
0
mirror of synced 2026-10-10 08:46:17 +08:00

Compare commits

..

6 Commits

24 changed files with 1645 additions and 286 deletions

View File

@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.13</version>
<version>1.2.19</version>
</dependency>
```

View File

@@ -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.13</version>
<version>1.2.19</version>
</dependency>
```

View File

@@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.2.13</version>
<version>1.2.19</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>

View File

@@ -1,5 +1,7 @@
package com.nlf.calendar;
import com.nlf.calendar.util.SolarUtil;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
@@ -20,6 +22,9 @@ public class ExactDate {
Calendar c = Calendar.getInstance(TIME_ZONE);
c.set(year, month - 1, day, hour, minute, second);
c.set(Calendar.MILLISECOND, 0);
if (0 == year) {
c.add(Calendar.YEAR, 1);
}
return c;
}
@@ -33,4 +38,50 @@ public class ExactDate {
c.set(Calendar.MILLISECOND, 0);
return c;
}
/**
* 获取两个日期之间相差的天数(如果日期a比日期b小,天数为正,如果日期a比日期b大,天数为负)
*
* @param ay 年a
* @param am 月a
* @param ad 日a
* @param by 年b
* @param bm 月b
* @param bd 日b
* @return 天数
*/
public static int getDaysBetween(int ay, int am, int ad, int by, int bm, int bd) {
int n;
int days;
int i;
if (ay == by) {
n = SolarUtil.getDaysInYear(by, bm, bd) - SolarUtil.getDaysInYear(ay, am, ad);
} else if (ay > by) {
days = SolarUtil.getDaysOfYear(by) - SolarUtil.getDaysInYear(by, bm, bd);
for (i = by + 1; i < ay; i++) {
days += SolarUtil.getDaysOfYear(i);
}
days += SolarUtil.getDaysInYear(ay, am, ad);
n = -days;
} else {
days = SolarUtil.getDaysOfYear(ay) - SolarUtil.getDaysInYear(ay, am, ad);
for (i = ay + 1; i < by; i++) {
days += SolarUtil.getDaysOfYear(i);
}
days += SolarUtil.getDaysInYear(by, bm, bd);
n = days;
}
return n;
}
/**
* 获取两个日期之间相差的天数(如果日期a比日期b小,天数为正,如果日期a比日期b大,天数为负)
*
* @param calendar0 日期a
* @param calendar1 日期b
* @return 天数
*/
public static int getDaysBetween(Calendar calendar0, Calendar calendar1) {
return getDaysBetween(calendar0.get(Calendar.YEAR), calendar0.get(Calendar.MONTH) + 1, calendar0.get(Calendar.DATE), calendar1.get(Calendar.YEAR), calendar1.get(Calendar.MONTH) + 1, calendar1.get(Calendar.DATE));
}
}

View File

@@ -83,11 +83,21 @@ public class Foto {
return l;
}
/**
* 是否月斋
*
* @return true/false
*/
public boolean isMonthZhai() {
int m = getMonth();
return 1 == m || 5 == m || 9 == m;
}
/**
* 是否杨公忌
*
* @return true/false
*/
public boolean isDayYangGong() {
for (FotoFestival f : getFestivals()) {
if ("杨公忌".equals(f.getName())) {
@@ -97,11 +107,21 @@ public class Foto {
return false;
}
/**
* 是否朔望斋
*
* @return true/false
*/
public boolean isDayZhaiShuoWang() {
int d = getDay();
return 1 == d || 15 == d;
}
/**
* 是否六斋日
*
* @return true/false
*/
public boolean isDayZhaiSix() {
int d = getDay();
if (8 == d || 14 == d || 15 == d || 23 == d || 29 == d || 30 == d) {
@@ -113,11 +133,21 @@ public class Foto {
return false;
}
/**
* 是否十斋日
*
* @return true/false
*/
public boolean isDayZhaiTen() {
int d = getDay();
return 1 == d || 8 == d || 14 == d || 15 == d || 18 == d || 23 == d || 24 == d || 28 == d || 29 == d || 30 == d;
}
/**
* 是否观音斋
*
* @return true/false
*/
public boolean isDayZhaiGuanYin() {
String k = getMonth() + "-" + getDay();
for (String d : FotoUtil.DAY_ZHAI_GUAN_YIN) {
@@ -128,6 +158,69 @@ public class Foto {
return false;
}
/**
* 获取星宿
*
* @return 星宿
*/
public String getXiu() {
return FotoUtil.getXiu(getMonth(), getDay());
}
/**
* 获取宿吉凶
*
* @return 吉/凶
*/
public String getXiuLuck() {
return LunarUtil.XIU_LUCK.get(getXiu());
}
/**
* 获取宿歌诀
*
* @return 宿歌诀
*/
public String getXiuSong() {
return LunarUtil.XIU_SONG.get(getXiu());
}
/**
* 获取政
*
* @return 政
*/
public String getZheng() {
return LunarUtil.ZHENG.get(getXiu());
}
/**
* 获取动物
*
* @return 动物
*/
public String getAnimal() {
return LunarUtil.ANIMAL.get(getXiu());
}
/**
* 获取宫
*
* @return 宫
*/
public String getGong() {
return LunarUtil.GONG.get(getXiu());
}
/**
* 获取兽
*
* @return 兽
*/
public String getShou() {
return LunarUtil.SHOU.get(getGong());
}
@Override
public String toString() {
return getYearInChinese() + "年" + getMonthInChinese() + "月" + getDayInChinese();

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,8 @@ package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
import java.util.List;
/**
* 农历月
*
@@ -31,9 +33,10 @@ public class LunarMonth {
/**
* 初始化
* @param lunarYear 农历年
* @param lunarMonth 农历月:1-12,闰月为负数,如闰2月为-2
* @param dayCount 天数
*
* @param lunarYear 农历年
* @param lunarMonth 农历月:1-12,闰月为负数,如闰2月为-2
* @param dayCount 天数
* @param firstJulianDay 初一的儒略日
*/
public LunarMonth(int lunarYear, int lunarMonth, int dayCount, double firstJulianDay) {
@@ -45,16 +48,18 @@ public class LunarMonth {
/**
* 通过农历年月初始化
* @param lunarYear 农历年
*
* @param lunarYear 农历年
* @param lunarMonth 农历月:1-12,闰月为负数,如闰2月为-2
* @return 农历月
*/
public static LunarMonth fromYm(int lunarYear, int lunarMonth){
public static LunarMonth fromYm(int lunarYear, int lunarMonth) {
return LunarYear.fromYear(lunarYear).getMonth(lunarMonth);
}
/**
* 获取农历年
*
* @return 农历年
*/
public int getYear() {
@@ -63,6 +68,7 @@ public class LunarMonth {
/**
* 获取农历月
*
* @return 农历月:1-12,闰月为负数,如闰2月为-2
*/
public int getMonth() {
@@ -71,6 +77,7 @@ public class LunarMonth {
/**
* 是否闰月
*
* @return true/false
*/
public boolean isLeap() {
@@ -79,6 +86,7 @@ public class LunarMonth {
/**
* 获取天数
*
* @return 天数
*/
public int getDayCount() {
@@ -87,14 +95,133 @@ public class LunarMonth {
/**
* 获取初一的儒略日
*
* @return 初一的儒略日
*/
public double getFirstJulianDay() {
return firstJulianDay;
}
/**
* 获取太岁方位
*
* @return 方位,如艮
*/
public String getPositionTaiSui() {
String p;
int m = Math.abs(month) % 4;
switch (m) {
case 0:
p = "巽";
break;
case 1:
p = "艮";
break;
case 3:
p = "坤";
break;
default:
p = LunarUtil.POSITION_GAN[Solar.fromJulianDay(this.getFirstJulianDay()).getLunar().getMonthGanIndex()];
}
return p;
}
/**
* 获取太岁方位描述
*
* @return 方位描述,如东北
*/
public String getPositionTaiSuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionTaiSui());
}
/**
* 获取月九星
*
* @return 九星
*/
public NineStar getNineStar() {
int index = LunarYear.fromYear(year).getZhiIndex() % 3;
int m = Math.abs(month);
int monthZhiIndex = (13 + m) % 12;
int n = 27 - index * 3;
if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX) {
n -= 3;
}
int offset = (n - monthZhiIndex) % 9;
return NineStar.fromIndex(offset);
}
@Override
public String toString() {
return year + "年" + (isLeap() ? "闰" : "") + LunarUtil.MONTH[Math.abs(month)] + "月(" + dayCount + "天)";
}
/**
* 获取往后推几个月的阴历月,如果要往前推,则月数用负数
*
* @param n 月数
* @return 阴历月
*/
public LunarMonth next(int n) {
if (0 == n) {
return LunarMonth.fromYm(year, month);
} else if (n > 0) {
int rest = n;
int ny = year;
int iy = ny;
int im = month;
int index = 0;
List<LunarMonth> months = LunarYear.fromYear(ny).getMonths();
while (true) {
int size = months.size();
for (int i = 0; i < size; i++) {
LunarMonth m = months.get(i);
if (m.getYear() == iy && m.getMonth() == im) {
index = i;
break;
}
}
int more = size - index - 1;
if (rest < more) {
break;
}
rest -= more;
LunarMonth lastMonth = months.get(size - 1);
iy = lastMonth.getYear();
im = lastMonth.getMonth();
ny++;
months = LunarYear.fromYear(ny).getMonths();
}
return months.get(index + rest);
} else {
int rest = -n;
int ny = year;
int iy = ny;
int im = month;
int index = 0;
List<LunarMonth> months = LunarYear.fromYear(ny).getMonths();
while (true) {
int size = months.size();
for (int i = 0; i < size; i++) {
LunarMonth m = months.get(i);
if (m.getYear() == iy && m.getMonth() == im) {
index = i;
break;
}
}
if (rest <= index) {
break;
}
rest -= index;
LunarMonth firstMonth = months.get(0);
iy = firstMonth.getYear();
im = firstMonth.getMonth();
ny--;
months = LunarYear.fromYear(ny).getMonths();
}
return months.get(index - rest);
}
}
}

View File

@@ -15,6 +15,16 @@ import java.util.Map;
*/
public class LunarYear {
/**
* 元
*/
private static final String[] YUAN = {"下", "上", "中"};
/**
* 运
*/
private static final String[] YUN = {"七", "八", "九", "一", "二", "三", "四", "五", "六"};
/**
* 闰冬月年份
*/
@@ -42,6 +52,16 @@ public class LunarYear {
*/
private int year;
/**
* 天干下标
*/
private int ganIndex;
/**
* 地支下标
*/
private int zhiIndex;
/**
* 农历月们
*/
@@ -59,6 +79,17 @@ public class LunarYear {
*/
public LunarYear(int lunarYear) {
this.year = lunarYear;
int offset = lunarYear - 4;
int yearGanIndex = offset % 10;
int yearZhiIndex = offset % 12;
if (yearGanIndex < 0) {
yearGanIndex += 10;
}
if (yearZhiIndex < 0) {
yearZhiIndex += 12;
}
this.ganIndex = yearGanIndex;
this.zhiIndex = yearZhiIndex;
compute();
}
@@ -183,6 +214,51 @@ public class LunarYear {
return jieQiJulianDays;
}
/**
* 获取天干序号,从0开始
*
* @return 序号
*/
public int getGanIndex() {
return ganIndex;
}
/**
* 获取地支序号,从0开始
*
* @return 序号
*/
public int getZhiIndex() {
return zhiIndex;
}
/**
* 获取天干
*
* @return 天干
*/
public String getGan() {
return LunarUtil.GAN[ganIndex + 1];
}
/**
* 获取地支
*
* @return 地支
*/
public String getZhi() {
return LunarUtil.ZHI[zhiIndex + 1];
}
/**
* 获取干支
*
* @return 干支
*/
public String getGanZhi() {
return getGan() + getZhi();
}
/**
* 获取农历月
*
@@ -212,30 +288,38 @@ public class LunarYear {
return 0;
}
/**
* 获取治水(正月第一个辰日是初几,就是几龙治水)
*
* @return 治水,如:二龙治水
*/
public String getZhiShui() {
int offset = 4 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
if (offset < 0) {
offset += 12;
}
return LunarUtil.NUMBER[offset+1] + "龙治水";
}
/**
* 获取分饼(正月第一个丙日是初几,就是几人分饼)
*
* @return 分饼,如:六人分饼
*/
public String getFenBing() {
int offset = 2 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
protected String getZaoByGan(int index, String name) {
int offset = index - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
if (offset < 0) {
offset += 10;
}
return LunarUtil.NUMBER[offset+1] + "人分饼";
return name.replaceFirst("几", LunarUtil.NUMBER[offset + 1]);
}
protected String getZaoByZhi(int index, String name) {
int offset = index - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
if (offset < 0) {
offset += 12;
}
return name.replaceFirst("几", LunarUtil.NUMBER[offset + 1]);
}
/**
* 获取几鼠偷粮
*
* @return 几鼠偷粮
*/
public String getTouLiang() {
return getZaoByZhi(0, "几鼠偷粮");
}
/**
* 获取草子几分
*
* @return 草子几分
*/
public String getCaoZi() {
return getZaoByZhi(0, "草子几分");
}
/**
@@ -244,11 +328,79 @@ public class LunarYear {
* @return 耕田,如:六牛耕田
*/
public String getGengTian() {
int offset = 1 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
if (offset < 0) {
offset += 12;
}
return LunarUtil.NUMBER[offset+1] + "牛耕田";
return getZaoByZhi(1, "几牛耕田");
}
/**
* 获取花收几分
*
* @return 花收几分
*/
public String getHuaShou() {
return getZaoByZhi(3, "花收几分");
}
/**
* 获取治水(正月第一个辰日是初几,就是几龙治水)
*
* @return 治水,如:二龙治水
*/
public String getZhiShui() {
return getZaoByZhi(4, "几龙治水");
}
/**
* 获取几马驮谷
*
* @return 几马驮谷
*/
public String getTuoGu() {
return getZaoByZhi(6, "几马驮谷");
}
/**
* 获取几鸡抢米
*
* @return 几鸡抢米
*/
public String getQiangMi() {
return getZaoByZhi(9, "几鸡抢米");
}
/**
* 获取几姑看蚕
*
* @return 几姑看蚕
*/
public String getKanCan() {
return getZaoByZhi(9, "几姑看蚕");
}
/**
* 获取几屠共猪
*
* @return 几屠共猪
*/
public String getGongZhu() {
return getZaoByZhi(11, "几屠共猪");
}
/**
* 获取甲田几分
*
* @return 甲田几分
*/
public String getJiaTian() {
return getZaoByGan(0, "甲田几分");
}
/**
* 获取分饼(正月第一个丙日是初几,就是几人分饼)
*
* @return 分饼,如:六人分饼
*/
public String getFenBing() {
return getZaoByGan(2, "几人分饼");
}
/**
@@ -257,11 +409,186 @@ public class LunarYear {
* @return 得金,如:一日得金
*/
public String getDeJin() {
int offset = 7 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
if (offset < 0) {
offset += 10;
return getZaoByGan(7, "几日得金");
}
/**
* 获取几人几丙
*
* @return 几人几丙
*/
public String getRenBing() {
return getZaoByGan(2, getZaoByZhi(2, "几人几丙"));
}
/**
* 获取几人几锄
*
* @return 几人几锄
*/
public String getRenChu() {
return getZaoByGan(3, getZaoByZhi(2, "几人几锄"));
}
/**
* 获取三元
*
* @return 元
*/
public String getYuan() {
return YUAN[((year + 2696) / 60) % 3] + "元";
}
/**
* 获取九运
*
* @return 运
*/
public String getYun() {
return YUN[((year + 2696) / 20) % 9] + "运";
}
/**
* 获取九星
*
* @return 九星
*/
public NineStar getNineStar() {
int index = LunarUtil.getJiaZiIndex(getGanZhi()) + 1;
int yuan = ((this.year + 2696) / 60) % 3;
int offset = (62 + yuan * 3 - index) % 9;
if (0 == offset) {
offset = 9;
}
return LunarUtil.NUMBER[offset+1] + "日得金";
return NineStar.fromIndex(offset - 1);
}
/**
* 获取喜神方位
*
* @return 方位,如艮
*/
public String getPositionXi() {
return LunarUtil.POSITION_XI[ganIndex + 1];
}
/**
* 获取喜神方位描述
*
* @return 方位描述,如东北
*/
public String getPositionXiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionXi());
}
/**
* 获取阳贵神方位
*
* @return 方位,如艮
*/
public String getPositionYangGui() {
return LunarUtil.POSITION_YANG_GUI[ganIndex + 1];
}
/**
* 获取阳贵神方位描述
*
* @return 方位描述,如东北
*/
public String getPositionYangGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYangGui());
}
/**
* 获取阴贵神方位
*
* @return 方位,如艮
*/
public String getPositionYinGui() {
return LunarUtil.POSITION_YIN_GUI[ganIndex + 1];
}
/**
* 获取阴贵神方位描述
*
* @return 方位描述,如东北
*/
public String getPositionYinGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYinGui());
}
/**
* 获取福神方位(默认流派:2)
*
* @return 方位,如艮
*/
public String getPositionFu() {
return getPositionFu(2);
}
/**
* 获取福神方位
*
* @param sect 流派,1或2
* @return 方位,如艮
*/
public String getPositionFu(int sect) {
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[ganIndex + 1];
}
/**
* 获取福神方位描述(默认流派:2)
*
* @return 方位描述,如东北
*/
public String getPositionFuDesc() {
return getPositionFuDesc(2);
}
/**
* 获取福神方位描述
*
* @param sect 流派,1或2
* @return 方位描述,如东北
*/
public String getPositionFuDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getPositionFu(sect));
}
/**
* 获取财神方位
*
* @return 财神方位,如艮
*/
public String getPositionCai() {
return LunarUtil.POSITION_CAI[ganIndex + 1];
}
/**
* 获取财神方位描述
*
* @return 方位描述,如东北
*/
public String getPositionCaiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionCai());
}
/**
* 获取太岁方位
*
* @return 方位,如艮
*/
public String getPositionTaiSui() {
return LunarUtil.POSITION_TAI_SUI_YEAR[zhiIndex];
}
/**
* 获取太岁方位描述
*
* @return 方位描述,如东北
*/
public String getPositionTaiSuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionTaiSui());
}
@Override
@@ -272,4 +599,14 @@ public class LunarYear {
public String toFullString() {
return year + "年";
}
/**
* 获取往后推几年的阴历年,如果要往前推,则年数用负数
*
* @param n 年数
* @return 阴历年
*/
public LunarYear next(int n) {
return LunarYear.fromYear(year + n);
}
}

View File

@@ -5,198 +5,250 @@ import com.nlf.calendar.util.LunarUtil;
/**
* 九星
* <p>玄空九星、奇门九星都来源于北斗九星,九数、七色、五行、后天八卦方位都是相通的。</p>
*
* @author 6tail
*/
public class NineStar {
/** 九数 */
public static final String[] NUMBER = {"一","二","三","四","五","六","七","八","九"};
/**
* 九数
*/
public static final String[] NUMBER = {"一", "二", "三", "四", "五", "六", "七", "八", "九"};
/** 七色 */
public static final String[] COLOR = {"白","黒","碧","绿","黄","白","赤","白","紫"};
/**
* 七色
*/
public static final String[] COLOR = {"白", "黒", "碧", "绿", "黄", "白", "赤", "白", "紫"};
/** 五行 */
public static final String[] WU_XING = {"水","土","木","木","土","金","金","土","火"};
/**
* 五行
*/
public static final String[] WU_XING = {"水", "土", "木", "木", "土", "金", "金", "土", "火"};
/** 后天八卦方位 */
public static final String[] POSITION = {"坎","坤","震","巽","中","乾","兑","艮","离"};
/**
* 后天八卦方位
*/
public static final String[] POSITION = {"坎", "坤", "震", "巽", "中", "乾", "兑", "艮", "离"};
/** 北斗九星 */
public static final String[] NAME_BEI_DOU = {"天枢","天璇","天玑","天权","玉衡","开阳","摇光","洞明","隐元"};
/**
* 北斗九星
*/
public static final String[] NAME_BEI_DOU = {"天枢", "天璇", "天玑", "天权", "玉衡", "开阳", "摇光", "洞明", "隐元"};
/** 玄空九星(玄空风水) */
public static final String[] NAME_XUAN_KONG = {"贪狼","巨门","禄存","文曲","廉贞","武曲","破军","左辅","右弼"};
/**
* 玄空九星(玄空风水)
*/
public static final String[] NAME_XUAN_KONG = {"贪狼", "巨门", "禄存", "文曲", "廉贞", "武曲", "破军", "左辅", "右弼"};
/** 奇门九星(奇门遁甲,也称天盘九星) */
public static final String[] NAME_QI_MEN = {"天蓬","天芮","天冲","天辅","天禽","天心","天柱","天任","天英"};
/**
* 奇门九星(奇门遁甲,也称天盘九星)
*/
public static final String[] NAME_QI_MEN = {"天蓬", "天芮", "天冲", "天辅", "天禽", "天心", "天柱", "天任", "天英"};
/** 八门(奇门遁甲) */
public static final String[] BA_MEN_QI_MEN = {"休","死","伤","杜","","开","惊","生","景"};
/**
* 八门(奇门遁甲)
*/
public static final String[] BA_MEN_QI_MEN = {"休", "死", "伤", "杜", "", "开", "惊", "生", "景"};
/** 太乙九神(太乙神数) */
public static final String[] NAME_TAI_YI = {"太乙","摄提","轩辕","招摇","天符","青龙","咸池","太阴","天乙"};
/**
* 太乙九神(太乙神数)
*/
public static final String[] NAME_TAI_YI = {"太乙", "摄提", "轩辕", "招摇", "天符", "青龙", "咸池", "太阴", "天乙"};
/** 太乙九神对应类型 */
public static final String[] TYPE_TAI_YI = {"吉神","凶神","安神","安神","凶神","吉神","凶神","吉神","吉神"};
/**
* 太乙九神对应类型
*/
public static final String[] TYPE_TAI_YI = {"吉神", "凶神", "安神", "安神", "凶神", "吉神", "凶神", "吉神", "吉神"};
/** 太乙九神歌诀(太乙神数) */
public static final String[] SONG_TAI_YI = {"门中太乙明,星官号贪狼,赌彩财喜旺,婚姻大吉昌,出入无阻挡,参谒见贤良,此行三五里,黑衣别阴阳。","门前见摄提,百事必忧疑,相生犹自可,相克祸必临,死门并相会,老妇哭悲啼,求谋并吉事,尽皆不相宜,只可藏隐遁,若动伤身疾。","出入会轩辕,凡事必缠牵,相生全不美,相克更忧煎,远行多不利,博彩尽输钱,九天玄女法,句句不虚言。","招摇号木星,当之事莫行,相克行人阻,阴人口舌迎,梦寐多惊惧,屋响斧自鸣,阴阳消息理,万法弗违情。","五鬼为天符,当门阴女谋,相克无好事,行路阻中途,走失难寻觅,道逢有尼姑,此星当门值,万事有灾除。","神光跃青龙,财气喜重重,投入有酒食,赌彩最兴隆,更逢相生旺,休言克破凶,见贵安营寨,万事总吉同。","吾将为咸池,当之尽不宜,出入多不利,相克有灾情,赌彩全输尽,求财空手回,仙人真妙语,愚人莫与知,动用虚惊退,反复逆风吹。","坐临太阴星,百祸不相侵,求谋悉成就,知交有觅寻,回风归来路,恐有殃伏起,密语中记取,慎乎莫轻行。","迎来天乙星,相逢百事兴,运用和合庆,茶酒喜相迎,求谋并嫁娶,好合有天成,祸福如神验,吉凶甚分明。"};
/**
* 太乙九神歌诀(太乙神数)
*/
public static final String[] SONG_TAI_YI = {"门中太乙明,星官号贪狼,赌彩财喜旺,婚姻大吉昌,出入无阻挡,参谒见贤良,此行三五里,黑衣别阴阳。", "门前见摄提,百事必忧疑,相生犹自可,相克祸必临,死门并相会,老妇哭悲啼,求谋并吉事,尽皆不相宜,只可藏隐遁,若动伤身疾。", "出入会轩辕,凡事必缠牵,相生全不美,相克更忧煎,远行多不利,博彩尽输钱,九天玄女法,句句不虚言。", "招摇号木星,当之事莫行,相克行人阻,阴人口舌迎,梦寐多惊惧,屋响斧自鸣,阴阳消息理,万法弗违情。", "五鬼为天符,当门阴女谋,相克无好事,行路阻中途,走失难寻觅,道逢有尼姑,此星当门值,万事有灾除。", "神光跃青龙,财气喜重重,投入有酒食,赌彩最兴隆,更逢相生旺,休言克破凶,见贵安营寨,万事总吉同。", "吾将为咸池,当之尽不宜,出入多不利,相克有灾情,赌彩全输尽,求财空手回,仙人真妙语,愚人莫与知,动用虚惊退,反复逆风吹。", "坐临太阴星,百祸不相侵,求谋悉成就,知交有觅寻,回风归来路,恐有殃伏起,密语中记取,慎乎莫轻行。", "迎来天乙星,相逢百事兴,运用和合庆,茶酒喜相迎,求谋并嫁娶,好合有天成,祸福如神验,吉凶甚分明。"};
/** 吉凶(玄空风水) */
public static final String[] LUCK_XUAN_KONG = {"吉","凶","凶","吉","凶","吉","凶","吉","吉"};
/**
* 吉凶(玄空风水)
*/
public static final String[] LUCK_XUAN_KONG = {"吉", "凶", "凶", "吉", "凶", "吉", "凶", "吉", "吉"};
/** 吉凶(奇门遁甲) */
public static final String[] LUCK_QI_MEN = {"大凶","大凶","小吉","大吉","大吉","大吉","小凶","小吉","小凶"};
/**
* 吉凶(奇门遁甲)
*/
public static final String[] LUCK_QI_MEN = {"大凶", "大凶", "小吉", "大吉", "大吉", "大吉", "小凶", "小吉", "小凶"};
/** 阴阳(奇门遁甲) */
public static final String[] YIN_YANG_QI_MEN = {"阳","阴","阳","阳","阳","阴","阴","阳","阴"};
/**
* 阴阳(奇门遁甲)
*/
public static final String[] YIN_YANG_QI_MEN = {"阳", "阴", "阳", "阳", "阳", "阴", "阴", "阳", "阴"};
/** 序号,0到8 */
/**
* 序号,0到8
*/
protected int index;
public NineStar(int index) {
this.index = index;
}
public static NineStar fromIndex(int index) {
return new NineStar(index);
}
/**
* 获取九数
*
* @return 九数
*/
public String getNumber(){
public String getNumber() {
return NUMBER[index];
}
/**
* 获取七色
*
* @return 七色
*/
public String getColor(){
public String getColor() {
return COLOR[index];
}
/**
* 获取五行
*
* @return 五行
*/
public String getWuXing(){
public String getWuXing() {
return WU_XING[index];
}
/**
* 获取方位
*
* @return 方位
*/
public String getPosition(){
public String getPosition() {
return POSITION[index];
}
/**
* 获取方位描述
*
* @return 方位描述
*/
public String getPositionDesc(){
public String getPositionDesc() {
return LunarUtil.POSITION_DESC.get(getPosition());
}
/**
* 获取玄空九星名称
*
* @return 玄空九星名称
*/
public String getNameInXuanKong(){
public String getNameInXuanKong() {
return NAME_XUAN_KONG[index];
}
/**
* 获取北斗九星名称
*
* @return 北斗九星名称
*/
public String getNameInBeiDou(){
public String getNameInBeiDou() {
return NAME_BEI_DOU[index];
}
/**
* 获取奇门九星名称
*
* @return 奇门九星名称
*/
public String getNameInQiMen(){
public String getNameInQiMen() {
return NAME_QI_MEN[index];
}
/**
* 获取太乙九神名称
*
* @return 太乙九神名称
*/
public String getNameInTaiYi(){
public String getNameInTaiYi() {
return NAME_TAI_YI[index];
}
/**
* 获取奇门九星吉凶
*
* @return 大吉/小吉/大凶/小凶
*/
public String getLuckInQiMen(){
public String getLuckInQiMen() {
return LUCK_QI_MEN[index];
}
/**
* 获取玄空九星吉凶
*
* @return 吉/凶
*/
public String getLuckInXuanKong(){
public String getLuckInXuanKong() {
return LUCK_XUAN_KONG[index];
}
/**
* 获取奇门九星阴阳
*
* @return 阴/阳
*/
public String getYinYangInQiMen(){
public String getYinYangInQiMen() {
return YIN_YANG_QI_MEN[index];
}
/**
* 获取太乙九神类型
*
* @return 吉神/凶神/安神
*/
public String getTypeInTaiYi(){
public String getTypeInTaiYi() {
return TYPE_TAI_YI[index];
}
/**
* 获取八门(奇门遁甲)
*
* @return 八门
*/
public String getBaMenInQiMen(){
public String getBaMenInQiMen() {
return BA_MEN_QI_MEN[index];
}
/**
* 获取太乙九神歌诀
*
* @return 太乙九神歌诀
*/
public String getSongInTaiYi(){
public String getSongInTaiYi() {
return SONG_TAI_YI[index];
}
/**
* 获取九星序号,从0开始
*
* @return 序号
*/
public int getIndex(){
public int getIndex() {
return index;
}
@Override
public String toString(){
return getNumber()+getColor()+getWuXing()+getNameInBeiDou();
public String toString() {
return getNumber() + getColor() + getWuXing() + getNameInBeiDou();
}
/**
* 获取详细描述
*
* @return 详细描述
*/
public String toFullString(){
public String toFullString() {
StringBuilder s = new StringBuilder();
s.append(getNumber());
s.append(getColor());
@@ -215,7 +267,7 @@ public class NineStar {
s.append(getNameInQiMen());
s.append(" ");
s.append(getLuckInQiMen());
if(getBaMenInQiMen().length()>0) {
if (getBaMenInQiMen().length() > 0) {
s.append(" ");
s.append(getBaMenInQiMen());
s.append("门");

View File

@@ -278,7 +278,7 @@ public class Solar {
if (offsetYear < 0) {
offsetYear = offsetYear + 60;
}
int startYear = today.getYear() - offsetYear;
int startYear = lunar.getYear() - offsetYear;
int hour = 0;
String timeZhi = timeGanZhi.substring(1);
for (int i = 0, j = LunarUtil.ZHI.length; i < j; i++) {

View File

@@ -159,10 +159,11 @@ public class SolarWeek {
public int getIndex() {
Calendar c = ExactDate.fromYmd(year, month, 1);
int firstDayWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (firstDayWeek == 0) {
firstDayWeek = 7;
int offset = firstDayWeek - start;
if(offset < 0) {
offset += 7;
}
return (int) Math.ceil((day + firstDayWeek - start) / 7D);
return (int) Math.ceil((day + offset) / 7D);
}
/**

View File

@@ -149,6 +149,62 @@ public class Tao {
return TaoUtil.BA_HUI.containsKey(lunar.getDayInGanZhi());
}
/**
* 是否明戊日
*
* @return true/false
*/
public boolean isDayMingWu() {
return "戊".equals(lunar.getDayGan());
}
/**
* 是否暗戊日
*
* @return true/false
*/
public boolean isDayAnWu() {
return lunar.getDayZhi().equals(TaoUtil.AN_WU[Math.abs(getMonth()) - 1]);
}
/**
* 是否戊日
*
* @return true/false
*/
public boolean isDayWu() {
return isDayMingWu() || isDayAnWu();
}
/**
* 是否天赦日
*
* @return true/false
*/
public boolean isDayTianShe() {
boolean ret = false;
String mz = lunar.getMonthZhi();
String dgz = lunar.getDayInGanZhi();
if ("寅卯辰".contains(mz)) {
if ("戊寅".equals(dgz)) {
ret = true;
}
} else if ("巳午未".contains(mz)) {
if ("甲午".equals(dgz)) {
ret = true;
}
} else if ("申酉戌".contains(mz)) {
if ("戊申".equals(dgz)) {
ret = true;
}
} else if ("亥子丑".contains(mz)) {
if ("甲子".equals(dgz)) {
ret = true;
}
}
return ret;
}
@Override
public String toString() {
return String.format("%s年%s月%s", getYearInChinese(), getMonthInChinese(), getDayInChinese());

View File

@@ -62,10 +62,8 @@ public class Yun {
int startTimeZhiIndex = (start.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().substring(11, 16));
// 时辰差
int hourDiff = endTimeZhiIndex - startTimeZhiIndex;
Calendar endCalendar = ExactDate.fromYmd(end.getYear(), end.getMonth(), end.getDay());
Calendar startCalendar = ExactDate.fromYmd(start.getYear(), start.getMonth(), start.getDay());
// 天数差
int dayDiff = (int) ((endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / (1000 * 3600 * 24));
int dayDiff = ExactDate.getDaysBetween(start.getYear(), start.getMonth(), start.getDay(), end.getYear(), end.getMonth(), end.getDay());
if (hourDiff < 0) {
hourDiff += 12;
dayDiff--;

View File

@@ -261,4 +261,25 @@ public class FotoUtil {
put("12-30", Collections.nCopies(1, new FotoFestival("诸神下降,察访善恶", "犯者男女俱亡")));
}
};
/**
* 27星宿,佛教从印度传入中国,印度把28星宿改为27星宿,把牛宿(牛金牛)纳入了女宿(女土蝠)。
*/
public static final String[] XIU_27 = {"角", "亢", "氐", "房", "心", "尾", "箕", "斗", "女", "虚", "危", "室", "壁", "奎", "娄", "胃", "昴", "毕", "觜", "参", "井", "鬼", "柳", "星", "张", "翼", "轸"};
/**
* 每月初一的27星宿偏移
*/
private static final int[] XIU_OFFSET = {11, 13, 15, 17, 19, 21, 24, 0, 2, 4, 7, 9};
/**
* 获取27星宿
*
* @param month 佛历月
* @param day 佛历日
* @return 星宿
*/
public static String getXiu(int month, int day) {
return XIU_27[(XIU_OFFSET[Math.abs(month)-1] + day - 1) % XIU_27.length];
}
}

File diff suppressed because one or more lines are too long

View File

@@ -128,7 +128,7 @@ public class SolarUtil {
put("11-28", Collections.nCopies(1, "恩格斯诞辰纪念日"));
put("12-1", Collections.nCopies(1, "世界艾滋病日"));
put("12-12", Collections.nCopies(1, "西安事变纪念日"));
put("12-13", Collections.nCopies(1, "南京大屠杀纪念日"));
put("12-13", Collections.nCopies(1, "国家公祭日"));
put("12-26", Collections.nCopies(1, "毛泽东诞辰纪念日"));
}
};
@@ -146,6 +146,16 @@ public class SolarUtil {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
/**
* 获取某年有多少天(平年365天,闰年366天)
*
* @param year 年
* @return 天数
*/
public static int getDaysOfYear(int year) {
return isLeapYear(year) ? 366 : 365;
}
/**
* 获取某年某月有多少天
*
@@ -154,6 +164,9 @@ public class SolarUtil {
* @return 天数
*/
public static int getDaysOfMonth(int year, int month) {
if (1582 == year && 10 == month) {
return 21;
}
int m = month - 1;
int d = DAYS_OF_MONTH[m];
//公历闰年2月多一天
@@ -163,6 +176,26 @@ public class SolarUtil {
return d;
}
/**
* 获取某天为当年的第几天
*
* @param year 年
* @param month 月
* @param day 日
* @return 第几天
*/
public static int getDaysInYear(int year, int month, int day) {
int days = 0;
for (int i = 1; i < month; i++) {
days += getDaysOfMonth(year, i);
}
days += day;
if (1582 == year && 10 == month && day >= 15) {
days -= 10;
}
return days;
}
/**
* 获取某年某月有多少周
*

View File

@@ -17,7 +17,7 @@ public class TaoUtil {
private static final long serialVersionUID = 1;
{
put("1-1", Collections.nCopies(1, new TaoFestival("天腊之辰", "天腊,此日五帝会于束方九炁青天")));
put("1-1", Collections.nCopies(1, new TaoFestival("天腊之辰", "天腊,此日五帝会于东方九炁青天")));
put("1-3", Arrays.asList(new TaoFestival("郝真人圣诞"), new TaoFestival("孙真人圣诞")));
put("1-5", Collections.nCopies(1, new TaoFestival("孙祖清静元君诞")));
put("1-7", Collections.nCopies(1, new TaoFestival("举迁赏会", "此日上元赐福,天官同地水二官考校罪福")));
@@ -52,7 +52,7 @@ public class TaoUtil {
put("4-20", Collections.nCopies(1, new TaoFestival("眼光圣母娘娘诞")));
put("4-28", Collections.nCopies(1, new TaoFestival("神农先帝诞")));
put("5-1", Collections.nCopies(1, new TaoFestival("南极长生大帝圣诞")));
put("5-5", Arrays.asList(new TaoFestival("地腊之辰", "地腊,此日五帝会於南方三炁丹天"), new TaoFestival("南方雷祖圣诞"), new TaoFestival("地祗温元帅圣诞"), new TaoFestival("雷霆邓天君圣诞")));
put("5-5", Arrays.asList(new TaoFestival("地腊之辰", "地腊,此日五帝会于南方三炁丹天"), new TaoFestival("南方雷祖圣诞"), new TaoFestival("地祗温元帅圣诞"), new TaoFestival("雷霆邓天君圣诞")));
put("5-11", Collections.nCopies(1, new TaoFestival("城隍爷圣诞")));
put("5-13", Arrays.asList(new TaoFestival("关圣帝君降神"), new TaoFestival("关平太子圣诞")));
put("5-18", Collections.nCopies(1, new TaoFestival("张天师圣诞")));
@@ -94,7 +94,7 @@ public class TaoUtil {
put("9-22", Collections.nCopies(1, new TaoFestival("增福财神诞")));
put("9-23", Collections.nCopies(1, new TaoFestival("萨翁真君圣诞")));
put("9-28", Collections.nCopies(1, new TaoFestival("五显灵官马元帅圣诞")));
put("10-1", Arrays.asList(new TaoFestival("民岁腊之辰", "民岁腊,此日五帝会於北方五炁黑天"), new TaoFestival("东皇大帝圣诞")));
put("10-1", Arrays.asList(new TaoFestival("民岁腊之辰", "民岁腊,此日五帝会于北方五炁黑天"), new TaoFestival("东皇大帝圣诞")));
put("10-3", Collections.nCopies(1, new TaoFestival("三茅应化真君圣诞")));
put("10-6", Collections.nCopies(1, new TaoFestival("天曹诸司五岳五帝圣诞")));
put("10-15", Arrays.asList(new TaoFestival("下元水官大帝圣诞"), new TaoFestival("建生大会", "此日下元解厄,水官同天地二官考校罪福")));
@@ -105,7 +105,7 @@ public class TaoUtil {
put("11-9", Collections.nCopies(1, new TaoFestival("湘子韩祖圣诞")));
put("11-11", Collections.nCopies(1, new TaoFestival("太乙救苦天尊圣诞")));
put("11-26", Collections.nCopies(1, new TaoFestival("北方五道圣诞")));
put("12-8", Collections.nCopies(1, new TaoFestival("王侯腊之辰", "王侯腊,此日五帝会於上方玄都玉京")));
put("12-8", Collections.nCopies(1, new TaoFestival("王侯腊之辰", "王侯腊,此日五帝会于上方玄都玉京")));
put("12-16", Arrays.asList(new TaoFestival("南岳大帝圣诞"), new TaoFestival("福德正神诞")));
put("12-20", Collections.nCopies(1, new TaoFestival("鲁班先师圣诞")));
put("12-21", Collections.nCopies(1, new TaoFestival("天猷上帝圣诞")));
@@ -169,4 +169,9 @@ public class TaoUtil {
*/
public static final String[] WU_LA = {"1-1", "5-5", "7-7", "10-1", "12-8"};
/**
* 暗戊
*/
public static final String[] AN_WU = {"未", "戌", "辰", "寅", "午", "子", "酉", "申", "巳", "亥", "卯", "丑"};
}

View File

@@ -1,5 +1,6 @@
package sample;
import com.nlf.calendar.LunarMonth;
import com.nlf.calendar.Solar;
import com.nlf.calendar.SolarMonth;
import org.junit.Test;
@@ -10,11 +11,11 @@ import org.junit.Test;
public class MonthTest {
@Test
public void test(){
public void test() {
//下个月
SolarMonth month = new SolarMonth().next(1);
//遍历每一天
for(Solar d:month.getDays()){
for (Solar d : month.getDays()) {
//输出阳历信息
System.out.println(d.toFullString());
//输出阴历信息
@@ -23,4 +24,22 @@ public class MonthTest {
}
}
@Test
public void test1() {
LunarMonth month = LunarMonth.fromYm(2020, 1);
// 顺推
for (int i = 0; i < 60; i++) {
System.out.println(month.next(i).toString());
}
}
@Test
public void test2() {
LunarMonth month = LunarMonth.fromYm(2020, 1);
// 倒推
for (int i = 0; i < 60; i++) {
System.out.println(month.next(-i).toString());
}
}
}

View File

@@ -18,4 +18,14 @@ public class FotoTest {
Assert.assertEquals("二五六五年十月十四 (三元降) (四天王巡行)", foto.toFullString());
}
@Test
public void test1() {
Foto foto = Foto.fromLunar(Lunar.fromYmd(2020, 4, 13));
Assert.assertEquals("氐", foto.getXiu());
Assert.assertEquals("土", foto.getZheng());
Assert.assertEquals("貉", foto.getAnimal());
Assert.assertEquals("东", foto.getGong());
Assert.assertEquals("青龙", foto.getShou());
}
}

View File

@@ -186,4 +186,12 @@ public class JieQiTest {
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("大雪").toYmdHms());
}
@Test
public void test9() {
Solar solar = Solar.fromYmd(2021, 12, 21);
Assert.assertEquals("冬至", solar.getLunar().getJieQi());
Assert.assertEquals("", solar.getLunar().getJie());
Assert.assertEquals("冬至", solar.getLunar().getQi());
}
}

View File

@@ -5,6 +5,11 @@ import com.nlf.calendar.Solar;
import org.junit.Assert;
import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* 农历测试
*
@@ -159,13 +164,13 @@ public class LunarTest {
@Test
public void test23() {
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
Assert.assertEquals("五黄土玉衡", lunar.getYearNineStar().toString());
Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
}
@Test
public void test24() {
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
Assert.assertEquals("三碧木天玑", lunar.getYearNineStar().toString());
Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
}
@Test
@@ -387,4 +392,27 @@ public class LunarTest {
Assert.assertEquals("厕灶厨 外西南", lunar.getDayPositionTai());
}
@Test
public void test53() {
Solar solar = Solar.fromYmd(2021, 11, 27);
Lunar lunar = solar.getLunar();
Assert.assertEquals("[嫁娶, 祭祀, 祈福, 求嗣, 开光, 出行, 解除, 出火, 拆卸, 进人口, 入宅, 移徙, 安床, 栽种, 动土, 修造, 纳畜, 入殓, 安葬, 立碑, 除服, 成服]", lunar.getDayYi().toString());
}
@Test
public void test54() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
Date date = format.parse("1986-08-14");
Lunar lunar = new Lunar(date);
Assert.assertEquals("一九八六年七月初九", lunar.toString());
}
@Test
public void test55() {
Solar solar = new Solar(1986, 8, 14);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九八六年七月初九", lunar.toString());
}
}

View File

@@ -0,0 +1,74 @@
package test;
import com.nlf.calendar.SolarWeek;
import org.junit.Assert;
import org.junit.Test;
/**
* 阳历周测试
*
* @author 6tail
*/
public class SolarWeekTest {
@Test
public void test() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 1, 0);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test1() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 7, 0);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test2() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 8, 0);
Assert.assertEquals(2, week.getIndex());
}
@Test
public void test3() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 1, 1);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test4() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 2, 1);
Assert.assertEquals(2, week.getIndex());
}
@Test
public void test5() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 8, 1);
Assert.assertEquals(2, week.getIndex());
}
@Test
public void test6() {
SolarWeek week = SolarWeek.fromYmd(2021, 11, 1, 0);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test7() {
SolarWeek week = SolarWeek.fromYmd(2021, 11, 1, 1);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test8() {
SolarWeek week = SolarWeek.fromYmd(2021, 5, 2, 2);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test9() {
SolarWeek week = SolarWeek.fromYmd(2021, 5, 4, 2);
Assert.assertEquals(2, week.getIndex());
}
}

View File

@@ -75,4 +75,32 @@ public class WuHouTest {
Assert.assertEquals(solar.toString(),"蚯蚓结",lunar.getWuHou());
}
@Test
public void test10(){
Solar solar = new Solar(2021,12,21);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"冬至 初候",lunar.getHou());
}
@Test
public void test11(){
Solar solar = new Solar(2021,12,26);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"冬至 二候",lunar.getHou());
}
@Test
public void test12(){
Solar solar = new Solar(2021,12,31);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"冬至 三候",lunar.getHou());
}
@Test
public void test13(){
Solar solar = new Solar(2022,1,5);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"小寒 初候",lunar.getHou());
}
}

View File

@@ -61,4 +61,82 @@ public class YearTest {
Assert.assertEquals("三日得金",year.getDeJin());
}
@Test
public void test5(){
LunarYear year = new LunarYear(1864);
Assert.assertEquals("上元",year.getYuan());
}
@Test
public void test6(){
LunarYear year = new LunarYear(1923);
Assert.assertEquals("上元",year.getYuan());
}
@Test
public void test7(){
LunarYear year = new LunarYear(1924);
Assert.assertEquals("中元",year.getYuan());
}
@Test
public void test8(){
LunarYear year = new LunarYear(1983);
Assert.assertEquals("中元",year.getYuan());
}
@Test
public void test9(){
LunarYear year = new LunarYear(1984);
Assert.assertEquals("下元",year.getYuan());
}
@Test
public void test10(){
LunarYear year = new LunarYear(2043);
Assert.assertEquals("下元",year.getYuan());
}
@Test
public void test11(){
LunarYear year = new LunarYear(1864);
Assert.assertEquals("一运",year.getYun());
}
@Test
public void test12(){
LunarYear year = new LunarYear(1883);
Assert.assertEquals("一运",year.getYun());
}
@Test
public void test13(){
LunarYear year = new LunarYear(1884);
Assert.assertEquals("二运",year.getYun());
}
@Test
public void test14(){
LunarYear year = new LunarYear(1903);
Assert.assertEquals("二运",year.getYun());
}
@Test
public void test15(){
LunarYear year = new LunarYear(1904);
Assert.assertEquals("三运",year.getYun());
}
@Test
public void test16(){
LunarYear year = new LunarYear(1923);
Assert.assertEquals("三运",year.getYun());
}
@Test
public void test17(){
LunarYear year = new LunarYear(2004);
Assert.assertEquals("八运",year.getYun());
}
}