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

Compare commits

...

9 Commits

22 changed files with 1680 additions and 337 deletions

View File

@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.14</version>
<version>1.2.21</version>
</dependency>
```
@@ -54,31 +54,3 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
## 文档
请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
## 更新日志
v1.2.14 佛历新增27宿;修复宜忌重复的问题;修复获取气时缺冬至的问题。
v1.2.13 新增道历Tao。
v1.2.12 修复星宿方位错误。
v1.2.11 修正胎神数据;增加福神流派。
v1.2.9 新增2022年法定假日。
v1.2.8 新增佛历Foto;更改Lunar中的getOtherFestivals方法为传统节日。
v1.2.7 修复儒略日转阳历秒数为60的错误。
v1.2.6 新增治水、分饼、耕田、得金、日禄;新增时辰LunarTime;新增获取当天的所有时辰。
v1.2.5 修复公元0至4年转阴历错误的问题。
v1.2.4 修复闰冬月、闰腊月的问题;修复日历不准的问题;修复物候错误;大运、小运、流年支持自定义轮数。
v1.2.3 修复除夕错误;代码优化。
v1.2.2 修正2016年国庆节数据;删除5月23日世界读书日;修复v1.2.0和v1.2.1的重大bug。
v1.2.0 支持0001到9999年。

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.21</version>
</dependency>
```

View File

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

@@ -556,13 +556,24 @@ public class EightChar {
}
/**
* 获取运
* 使用默认流派1获取运
*
* @param gender 性别:1男,0女
* @return 运
*/
public Yun getYun(int gender) {
return new Yun(this, gender);
return getYun(gender, 1);
}
/**
* 获取运
*
* @param gender 性别:1男,0女
* @param sect 流派,1按天数和时辰数计算,3天1年,1天4个月,1时辰10天;2按分钟数计算
* @return 运
*/
public Yun getYun(int gender, int sect) {
return new Yun(this, gender, sect);
}
/**

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));
}
}

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

@@ -155,14 +155,29 @@ public class SolarWeek {
*
* @return 周序号,从1开始
*/
@SuppressWarnings("MagicConstant")
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);
}
/**
* 获取当前日期是在当年第几周
*
* @return 周序号,从1开始
*/
public int getIndexInYear() {
Calendar c = ExactDate.fromYmd(year, 1, 1);
int firstDayWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
int offset = firstDayWeek - start;
if(offset < 0) {
offset += 7;
}
return (int) Math.ceil((SolarUtil.getDaysInYear(year, month, day) + offset) / 7D);
}
/**
@@ -227,7 +242,6 @@ public class SolarWeek {
*
* @return 本周第一天的阳历日期
*/
@SuppressWarnings("MagicConstant")
public Solar getFirstDay() {
Calendar c = ExactDate.fromYmd(year, month, day);
int week = c.get(Calendar.DAY_OF_WEEK) - 1;
@@ -259,6 +273,7 @@ public class SolarWeek {
*
* @return 本周的阳历日期列表
*/
@SuppressWarnings("all")
public List<Solar> getDays() {
Solar firstDay = getFirstDay();
List<Solar> l = new ArrayList<Solar>();

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

@@ -15,25 +15,50 @@ public class Yun {
* 性别(1男,0女)
*/
private int gender;
/**
* 起运年数
*/
private int startYear;
/**
* 起运月数
*/
private int startMonth;
/**
* 起运天数
*/
private int startDay;
/**
* 起运小时数
*/
private int startHour;
/**
* 是否顺推
*/
private boolean forward;
private Lunar lunar;
/**
* 使用默认流派1初始化运
* @param eightChar 八字
* @param gender 性别,1男,0女
*/
public Yun(EightChar eightChar, int gender) {
this(eightChar, gender, 1);
}
/**
* 初始化运
* @param eightChar 八字
* @param gender 性别,1男,0女
* @param sect 流派,1按天数和时辰数计算,3天1年,1天4个月,1时辰10天;2按分钟数计算
*/
public Yun(EightChar eightChar, int gender, int sect) {
this.lunar = eightChar.getLunar();
this.gender = gender;
// 阳
@@ -41,14 +66,13 @@ public class Yun {
// 男
boolean man = 1 == gender;
forward = (yang && man) || (!yang && !man);
computeStart();
computeStart(sect);
}
/**
* 起运计算
*/
@SuppressWarnings("MagicConstant")
private void computeStart() {
private void computeStart(int sect) {
// 上节
JieQi prev = lunar.getPrevJie();
// 下节
@@ -58,26 +82,46 @@ public class Yun {
// 阳男阴女顺推,阴男阳女逆推
Solar start = forward ? current : prev.getSolar();
Solar end = forward ? next.getSolar() : current;
int endTimeZhiIndex = (end.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(end.toYmdHms().substring(11, 16));
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));
if (hourDiff < 0) {
hourDiff += 12;
dayDiff--;
int year;
int month;
int day;
int hour = 0;
if (2 == sect) {
long minutes = (end.getCalendar().getTimeInMillis() - start.getCalendar().getTimeInMillis()) / 60000;
long y = minutes / 4320;
minutes -= y * 4320;
long m = minutes / 360;
minutes -= m * 360;
long d = minutes / 12;
minutes -= d * 12;
long h = minutes * 2;
year = (int)y;
month = (int)m;
day = (int)d;
hour = (int)h;
} else {
int endTimeZhiIndex = (end.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(end.toYmdHms().substring(11, 16));
int startTimeZhiIndex = (start.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().substring(11, 16));
// 时辰差
int hourDiff = endTimeZhiIndex - startTimeZhiIndex;
// 天数差
int dayDiff = ExactDate.getDaysBetween(start.getYear(), start.getMonth(), start.getDay(), end.getYear(), end.getMonth(), end.getDay());
if (hourDiff < 0) {
hourDiff += 12;
dayDiff--;
}
int monthDiff = hourDiff * 10 / 30;
month = dayDiff * 4 + monthDiff;
day = hourDiff * 10 - monthDiff * 30;
year = month / 12;
month = month - year * 12;
}
int monthDiff = hourDiff * 10 / 30;
int month = dayDiff * 4 + monthDiff;
int day = hourDiff * 10 - monthDiff * 30;
int year = month / 12;
month = month - year * 12;
this.startYear = year;
this.startMonth = month;
this.startDay = day;
this.startHour = hour;
}
/**
@@ -116,6 +160,15 @@ public class Yun {
return startDay;
}
/**
* 获取起运小时数
*
* @return 起运小时数
*/
public int getStartHour() {
return startHour;
}
/**
* 是否顺推
*
@@ -134,13 +187,13 @@ public class Yun {
*
* @return 阳历日期
*/
@SuppressWarnings("MagicConstant")
public Solar getStartSolar() {
Solar birth = lunar.getSolar();
Calendar c = ExactDate.fromYmd(birth.getYear(), birth.getMonth(), birth.getDay());
Calendar c = ExactDate.fromYmdHms(birth.getYear(), birth.getMonth(), birth.getDay(), birth.getHour(), birth.getMinute(), birth.getSecond());
c.add(Calendar.YEAR, startYear);
c.add(Calendar.MONTH, startMonth);
c.add(Calendar.DATE, startDay);
c.add(Calendar.HOUR, startHour);
return Solar.fromCalendar(c);
}

View File

@@ -17,6 +17,8 @@ public class LunarUtil{
public static final String[] XUN_KONG = {"戌亥","申酉","午未","辰巳","寅卯","子丑"};
/** 六曜 */
public static final String[] LIU_YAO = {"先胜","友引","先负","佛灭","大安","赤口"};
/** 候 */
public static final String[] HOU = {"初候", "二候", "三候"};
/** 物候 */
public static final String[] WU_HOU = {"蚯蚓结","麋角解","水泉动","雁北乡","鹊始巢","雉始雊","鸡始乳","征鸟厉疾","水泽腹坚","东风解冻","蛰虫始振","鱼陟负冰","獭祭鱼","候雁北","草木萌动","桃始华","仓庚鸣","鹰化为鸠","玄鸟至","雷乃发声","始电","桐始华","田鼠化为鴽","虹始见","萍始生","鸣鸠拂奇羽","戴胜降于桑","蝼蝈鸣","蚯蚓出","王瓜生","苦菜秀","靡草死","麦秋至","螳螂生","鵙始鸣","反舌无声","鹿角解","蜩始鸣","半夏生","温风至","蟋蟀居壁","鹰始挚","腐草为萤","土润溽暑","大雨行时","凉风至","白露降","寒蝉鸣","鹰乃祭鸟","天地始肃","禾乃登","鸿雁来","玄鸟归","群鸟养羞","雷始收声","蛰虫坯户","水始涸","鸿雁来宾","雀入大水为蛤","菊有黄花","豺乃祭兽","草木黄落","蛰虫咸俯","水始冰","地始冻","雉入大水为蜃","虹藏不见","天气上升地气下降","闭塞而成冬","鹖鴠不鸣","虎始交","荔挺出"};
/** 天干 */
@@ -33,6 +35,12 @@ public class LunarUtil{
public static final String[] POSITION_FU_2 = {"","坎","坤","乾","巽","艮","坎","坤","乾","巽","艮"};
/** 财神方位,《财神方位歌》:甲乙东北是财神,丙丁向在西南寻,戊己正北坐方位, 庚辛正东去安身,壬癸原来正南坐,便是财神方位真。 */
public static final String[] POSITION_CAI = {"","艮","艮","坤","坤","坎","坎","震","震","离","离"};
/** 年太岁方位 */
public static final String[] POSITION_TAI_SUI_YEAR = {"坎","艮","艮","震","巽","巽","离","坤","坤","兑","坎","坎"};
/** 天干方位 */
public static final String[] POSITION_GAN = {"震","震","离","离","中","中","兑","兑","坎","坎"};
/** 地支方位 */
public static final String[] POSITION_ZHI = {"坎","中","震","震","中","离","离","中","兑","兑","中","坎"};
/** 逐日胎神方位 */
public static final String[] POSITION_TAI_DAY = {"占门碓 外东南","碓磨厕 外东南","厨灶炉 外正南","仓库门 外正南","房床栖 外正南","占门床 外正南","占碓磨 外正南","厕灶厨 外西南","仓库炉 外西南","房床门 外西南","门碓栖 外西南","碓磨床 外西南","厨灶碓 外西南","仓库厕 外正西","房床炉 外正西","占大门 外正西","碓磨栖 外正西","厨房床 外正西","仓库碓 外西北","房床厕 外西北","占门炉 外西北","门碓磨 外西北","厨灶栖 外西北","仓库床 外西北","房床碓 外正北","占门厕 外正北","碓磨炉 外正北","厨灶门 外正北","仓库栖 外正北","占房床 房内北","占门碓 房内北","碓磨厕 房内北","厨灶炉 房内北","门仓库 房内北","床房栖 房内中","占门床 房内中","占碓磨 房内南","厨磨厕 房内南","仓库炉 房内南","房床门 房内西","门碓栖 房内东","碓磨床 房内东","厨灶碓 房内东","仓库厕 房内东","房床炉 房内中","占大门 外东北","碓磨栖 外东北","厨灶床 外东北","仓库碓 外东北","房床厕 外东北","占门炉 外东北","门碓磨 外正东","厨灶栖 外正东","仓库床 外正东","房床碓 外正东","占门厕 外正东","碓磨炉 外东南","厨灶门 外东南","仓库栖 外东南","占房床 外东南"};
/** 逐月胎神方位 */
@@ -1132,8 +1140,8 @@ public class LunarUtil{
}
}
if(matched) {
String ys = left.substring(left.indexOf(':') + 1);
ys = ys.substring(0, ys.indexOf(','));
String ys = left.substring(left.indexOf(":") + 1);
ys = ys.substring(0, ys.indexOf(","));
for (int i = 0, j = ys.length(); i < j; i += 2) {
String m = ys.substring(i, i + 2);
l.add(YI_JI[Integer.parseInt(m,16)]);

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

@@ -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
@@ -394,4 +399,29 @@ public class LunarTest {
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());
}
@Test
public void test56() {
Solar solar = new Solar(2022, 4, 5);
Lunar lunar = solar.getLunar();
Assert.assertEquals("甲辰", lunar.getMonthInGanZhi());
Assert.assertEquals("癸卯", lunar.getMonthInGanZhiExact());
Assert.assertEquals(4, lunar.getDayJi().size());
}
}

View File

@@ -0,0 +1,86 @@
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());
}
@Test
public void test10() {
SolarWeek week = SolarWeek.fromYmd(2022, 3, 6, 0);
Assert.assertEquals(11, week.getIndexInYear());
}
@Test
public void test11() {
SolarWeek week = SolarWeek.fromYmd(2022, 3, 6, 1);
Assert.assertEquals(10, week.getIndexInYear());
}
}

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());
}
}

View File

@@ -53,4 +53,34 @@ public class YunTest {
Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
}
@Test
public void test4() {
Solar solar = new Solar(2022, 3, 9, 20, 51, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(1);
Assert.assertEquals("起运阳历", "2030-12-19", yun.getStartSolar().toYmd());
}
@Test
public void test5() {
Solar solar = new Solar(2022, 3, 9, 20, 51, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(1, 2);
Assert.assertEquals("起运年数", 8, yun.getStartYear());
Assert.assertEquals("起运月数", 9, yun.getStartMonth());
Assert.assertEquals("起运天数", 2, yun.getStartDay());
Assert.assertEquals("起运阳历", "2030-12-12", yun.getStartSolar().toYmd());
}
@Test
public void test6() {
Solar solar = new Solar(2018, 6, 11, 9, 30, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(0, 2);
Assert.assertEquals("起运阳历", "2020-03-21", yun.getStartSolar().toYmd());
}
}