1
0
mirror of synced 2026-10-10 00:39:52 +08:00

Compare commits

...

5 Commits

14 changed files with 427 additions and 190 deletions

View File

@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.18</version>
<version>1.2.21</version>
</dependency>
```
@@ -54,33 +54,3 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
## 文档
请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")
## 更新日志
v1.2.15 南京大XX纪念日更改为国家公祭日;新增初候、二候、三候;新增三元九运;新增道历戊日。
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.18</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.18</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

@@ -285,11 +285,11 @@ public class Lunar {
}
}
yearGanIndexByLiChun = (g<0?g+10:g)%10;
yearZhiIndexByLiChun = (z<0?z+12:z)%12;
yearGanIndexByLiChun = (g < 0 ? g + 10 : g) % 10;
yearZhiIndexByLiChun = (z < 0 ? z + 12 : z) % 12;
yearGanIndexExact = (gExact<0?gExact+10:gExact)%10;
yearZhiIndexExact = (zExact<0?zExact+12:zExact)%12;
yearGanIndexExact = (gExact < 0 ? gExact + 10 : gExact) % 10;
yearZhiIndexExact = (zExact < 0 ? zExact + 12 : zExact) % 12;
}
/**
@@ -304,7 +304,7 @@ public class Lunar {
//序号:大雪以前-3,大雪到小寒之间-2,小寒到立春之间-1,立春之后0
int index = -3;
for (int i=0;i<size;i+=2) {
for (int i = 0; i < size; i += 2) {
end = jieQi.get(JIE_QI_IN_USE[i]);
String symd = null == start ? ymd : start.toYmd();
if (ymd.compareTo(symd) >= 0 && ymd.compareTo(end.toYmd()) < 0) {
@@ -315,13 +315,13 @@ public class Lunar {
}
//干偏移值(以立春当天起算)
int offset = (((yearGanIndexByLiChun+(index<0?1:0)) % 5 + 1) * 2) % 10;
monthGanIndex = ((index<0?index+10:index) + offset) % 10;
monthZhiIndex = ((index<0?index+12:index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
int offset = (((yearGanIndexByLiChun + (index < 0 ? 1 : 0)) % 5 + 1) * 2) % 10;
monthGanIndex = ((index < 0 ? index + 10 : index) + offset) % 10;
monthZhiIndex = ((index < 0 ? index + 12 : index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
start = null;
index = -3;
for (int i=0;i<size;i+=2) {
for (int i = 0; i < size; i += 2) {
end = jieQi.get(JIE_QI_IN_USE[i]);
String stime = null == start ? time : start.toYmdHms();
if (time.compareTo(stime) >= 0 && time.compareTo(end.toYmdHms()) < 0) {
@@ -332,9 +332,9 @@ public class Lunar {
}
//干偏移值(以立春交接时刻起算)
offset = (((yearGanIndexExact+(index<0?1:0)) % 5 + 1) * 2) % 10;
monthGanIndexExact = ((index<0?index+10:index) + offset) % 10;
monthZhiIndexExact = ((index<0?index+12:index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
offset = (((yearGanIndexExact + (index < 0 ? 1 : 0)) % 5 + 1) * 2) % 10;
monthGanIndexExact = ((index < 0 ? index + 10 : index) + offset) % 10;
monthZhiIndexExact = ((index < 0 ? index + 12 : index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
}
/**
@@ -807,17 +807,17 @@ public class Lunar {
return LunarUtil.SEASON[Math.abs(month)];
}
protected String convertJieQi(String name){
protected String convertJieQi(String name) {
String jq = name;
if("DONG_ZHI".equals(jq)){
if ("DONG_ZHI".equals(jq)) {
jq = "冬至";
}else if("DA_HAN".equals(jq)){
} else if ("DA_HAN".equals(jq)) {
jq = "大寒";
}else if("XIAO_HAN".equals(jq)){
} else if ("XIAO_HAN".equals(jq)) {
jq = "小寒";
}else if("LI_CHUN".equals(jq)){
} else if ("LI_CHUN".equals(jq)) {
jq = "立春";
}else if("DA_XUE".equals(jq)){
} else if ("DA_XUE".equals(jq)) {
jq = "大雪";
} else if ("YU_SHUI".equals(jq)) {
jq = "雨水";
@@ -833,7 +833,7 @@ public class Lunar {
* @return 节令
*/
public String getJie() {
for(int i=0, j=JIE_QI_IN_USE.length; i<j; i+=2){
for (int i = 0, j = JIE_QI_IN_USE.length; i < j; i += 2) {
String key = JIE_QI_IN_USE[i];
Solar d = jieQi.get(key);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
@@ -849,7 +849,7 @@ public class Lunar {
* @return 气令
*/
public String getQi() {
for(int i=1, j=JIE_QI_IN_USE.length; i<j; i+=2){
for (int i = 1, j = JIE_QI_IN_USE.length; i < j; i += 2) {
String key = JIE_QI_IN_USE[i];
Solar d = jieQi.get(key);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
@@ -968,7 +968,7 @@ public class Lunar {
if (null != fs) {
l.addAll(fs);
}
if(solar.toYmd().equals(jieQi.get("清明").next(-1).toYmd())) {
if (solar.toYmd().equals(jieQi.get("清明").next(-1).toYmd())) {
l.add("寒食节");
}
return l;
@@ -995,7 +995,7 @@ public class Lunar {
/**
* 获取日喜神方位
*
* @return 喜神方位,如艮
* @return 方位,如艮
* @deprecated 使用getDayPositionXi
*/
public String getPositionXi() {
@@ -1005,7 +1005,7 @@ public class Lunar {
/**
* 获取喜神方位描述
*
* @return 喜神方位描述,如东北
* @return 方位描述,如东北
* @deprecated 使用getDayPositionXiDesc
*/
public String getPositionXiDesc() {
@@ -1025,7 +1025,7 @@ public class Lunar {
/**
* 获取阳贵神方位描述
*
* @return 阳贵神方位描述,如东北
* @return 方位描述,如东北
* @deprecated 使用getDayPositionYangGuiDesc
*/
public String getPositionYangGuiDesc() {
@@ -1035,7 +1035,7 @@ public class Lunar {
/**
* 获取阴贵神方位
*
* @return 阴贵神方位,如艮
* @return 方位,如艮
* @deprecated 使用getDayPositionYinGui
*/
public String getPositionYinGui() {
@@ -1055,7 +1055,7 @@ public class Lunar {
/**
* 获取福神方位
*
* @return 福神方位,如艮
* @return 方位,如艮
* @deprecated 使用getDayPositionFu
*/
public String getPositionFu() {
@@ -1065,7 +1065,7 @@ public class Lunar {
/**
* 获取福神方位描述
*
* @return 福神方位描述,如东北
* @return 方位描述,如东北
* @deprecated 使用getDayPositionFuDesc
*/
public String getPositionFuDesc() {
@@ -1075,7 +1075,7 @@ public class Lunar {
/**
* 获取财神方位
*
* @return 财神方位,如艮
* @return 方位,如艮
* @deprecated 使用getDayPositionCai
*/
public String getPositionCai() {
@@ -1085,7 +1085,7 @@ public class Lunar {
/**
* 获取财神方位描述
*
* @return 财神方位描述,如东北
* @return 方位描述,如东北
* @deprecated 使用getDayPositionCaiDesc
*/
public String getPositionCaiDesc() {
@@ -1095,7 +1095,7 @@ public class Lunar {
/**
* 获取日喜神方位
*
* @return 喜神方位,如艮
* @return 方位,如艮
*/
public String getDayPositionXi() {
return LunarUtil.POSITION_XI[dayGanIndex + 1];
@@ -1104,7 +1104,7 @@ public class Lunar {
/**
* 获取日喜神方位描述
*
* @return 喜神方位描述,如东北
* @return 方位描述,如东北
*/
public String getDayPositionXiDesc() {
return LunarUtil.POSITION_DESC.get(getDayPositionXi());
@@ -1113,7 +1113,7 @@ public class Lunar {
/**
* 获取日阳贵神方位
*
* @return 阳贵神方位,如艮
* @return 方位,如艮
*/
public String getDayPositionYangGui() {
return LunarUtil.POSITION_YANG_GUI[dayGanIndex + 1];
@@ -1122,7 +1122,7 @@ public class Lunar {
/**
* 获取日阳贵神方位描述
*
* @return 阳贵神方位描述,如东北
* @return 方位描述,如东北
*/
public String getDayPositionYangGuiDesc() {
return LunarUtil.POSITION_DESC.get(getDayPositionYangGui());
@@ -1140,7 +1140,7 @@ public class Lunar {
/**
* 获取日阴贵神方位描述
*
* @return 阴贵神方位描述,如东北
* @return 方位描述,如东北
*/
public String getDayPositionYinGuiDesc() {
return LunarUtil.POSITION_DESC.get(getDayPositionYinGui());
@@ -1159,16 +1159,16 @@ public class Lunar {
* 获取日福神方位
*
* @param sect 流派,1或2
* @return 福神方位,如艮
* @return 方位,如艮
*/
public String getDayPositionFu(int sect) {
return (1==sect?LunarUtil.POSITION_FU:LunarUtil.POSITION_FU_2)[dayGanIndex + 1];
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[dayGanIndex + 1];
}
/**
* 获取日福神方位描述(默认流派:2)
*
* @return 福神方位描述,如东北
* @return 方位描述,如东北
*/
public String getDayPositionFuDesc() {
return getDayPositionFuDesc(2);
@@ -1178,7 +1178,7 @@ public class Lunar {
* 获取日福神方位描述
*
* @param sect 流派,1或2
* @return 福神方位描述,如东北
* @return 方位描述,如东北
*/
public String getDayPositionFuDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getDayPositionFu(sect));
@@ -1187,7 +1187,7 @@ public class Lunar {
/**
* 获取日财神方位
*
* @return 财神方位,如艮
* @return 方位,如艮
*/
public String getDayPositionCai() {
return LunarUtil.POSITION_CAI[dayGanIndex + 1];
@@ -1196,7 +1196,7 @@ public class Lunar {
/**
* 获取日财神方位描述
*
* @return 财神方位描述,如东北
* @return 方位描述,如东北
*/
public String getDayPositionCaiDesc() {
return LunarUtil.POSITION_DESC.get(getDayPositionCai());
@@ -1205,7 +1205,7 @@ public class Lunar {
/**
* 获取年太岁方位(默认流派2新年以立春零点起算)
*
* @return 太岁方位,如艮
* @return 方位,如艮
*/
public String getYearPositionTaiSui() {
return getYearPositionTaiSui(2);
@@ -1215,7 +1215,7 @@ public class Lunar {
* 获取年太岁方位
*
* @param sect 流派:2为新年以立春零点起算;1为新年以正月初一起算;3为新年以立春节气交接的时刻起算
* @return 太岁方位,如艮
* @return 方位,如艮
*/
public String getYearPositionTaiSui(int sect) {
int yearZhiIndex;
@@ -1235,7 +1235,7 @@ public class Lunar {
/**
* 获取年太岁方位描述(默认流派2新年以立春零点起算)
*
* @return 太岁方位描述,如东北
* @return 方位描述,如东北
*/
public String getYearPositionTaiSuiDesc() {
return getYearPositionTaiSuiDesc(2);
@@ -1245,32 +1245,27 @@ public class Lunar {
* 获取年太岁方位描述
*
* @param sect 流派:2为新年以立春零点起算;1为新年以正月初一起算;3为新年以立春节气交接的时刻起算
* @return 太岁方位描述,如东北
* @return 方位描述,如东北
*/
public String getYearPositionTaiSuiDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getYearPositionTaiSui(sect));
}
protected String getMonthPositionTaiSui(int monthZhiIndex, int monthGanIndex){
protected String getMonthPositionTaiSui(int monthZhiIndex, int monthGanIndex) {
String p;
int m = monthZhiIndex - LunarUtil.BASE_MONTH_ZHI_INDEX;
if (m < 0) {
m += 12;
}
switch(m) {
m = m % 4;
switch (m) {
case 0:
case 4:
case 8:
p = "艮";
break;
case 2:
case 6:
case 10:
p = "坤";
break;
case 3:
case 7:
case 11:
p = "巽";
break;
default:
@@ -1328,7 +1323,7 @@ public class Lunar {
return LunarUtil.POSITION_DESC.get(getMonthPositionTaiSui(sect));
}
protected String getDayPositionTaiSui(String dayInGanZhi, int yearZhiIndex){
protected String getDayPositionTaiSui(String dayInGanZhi, int yearZhiIndex) {
String p;
if ("甲子,乙丑,丙寅,丁卯,戊辰,已巳".contains(dayInGanZhi)) {
p = "震";
@@ -1340,7 +1335,7 @@ public class Lunar {
p = "兑";
} else if ("壬子,癸丑,甲寅,乙卯,丙辰,丁巳".contains(dayInGanZhi)) {
p = "坎";
} else{
} else {
p = LunarUtil.POSITION_TAI_SUI_YEAR[yearZhiIndex];
}
return p;
@@ -1469,7 +1464,7 @@ public class Lunar {
* @return 福神方位,如艮
*/
public String getTimePositionFu(int sect) {
return (1==sect?LunarUtil.POSITION_FU:LunarUtil.POSITION_FU_2)[timeGanIndex + 1];
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[timeGanIndex + 1];
}
/**
@@ -1833,21 +1828,41 @@ public class Lunar {
}
/**
* 获取每日宜,如果没有,返回["无"]
* 使用默认流派1(以节交接当天起算月)获取每日宜,如果没有,返回["无"]
*
* @return 宜
*/
public List<String> getDayYi() {
return LunarUtil.getDayYi(getMonthInGanZhiExact(), getDayInGanZhi());
return getDayYi(1);
}
/**
* 获取每日宜,如果没有,返回["无"]
*
* @param sect 流派,1以节交接当天起算月,2以节交接时刻起算月
* @return 宜
*/
public List<String> getDayYi(int sect) {
return LunarUtil.getDayYi(2 == sect ? getMonthInGanZhiExact() : getMonthInGanZhi(), getDayInGanZhi());
}
/**
* 使用默认流派1(以节交接当天起算月)获取每日忌,如果没有,返回["无"]
*
* @return 忌
*/
public List<String> getDayJi() {
return getDayJi(1);
}
/**
* 获取每日忌,如果没有,返回["无"]
*
* @param sect 流派,1以节交接当天起算月,2以节交接时刻起算月
* @return 忌
*/
public List<String> getDayJi() {
return LunarUtil.getDayJi(getMonthInGanZhiExact(), getDayInGanZhi());
public List<String> getDayJi(int sect) {
return LunarUtil.getDayJi(2 == sect ? getMonthInGanZhiExact() : getMonthInGanZhi(), getDayInGanZhi());
}
/**
@@ -2023,7 +2038,7 @@ public class Lunar {
}
int yuan = ((this.year + yearOffset + 2696) / 60) % 3;
int offset = (62 + yuan * 3 - index) % 9;
if(0 == offset){
if (0 == offset) {
offset = 9;
}
return NineStar.fromIndex(offset - 1);
@@ -2032,7 +2047,7 @@ public class Lunar {
/**
* 获取值年九星(默认流派2新年以立春零点起算。流年紫白星起例歌诀:年上吉星论甲子,逐年星逆中宫起;上中下作三元汇,一上四中七下兑。)
*
* @return 值年九星
* @return 九星
*/
public NineStar getYearNineStar() {
return getYearNineStar(2);
@@ -2042,7 +2057,7 @@ public class Lunar {
* 获取值年九星(流年紫白星起例歌诀:年上吉星论甲子,逐年星逆中宫起;上中下作三元汇,一上四中七下兑。)
*
* @param sect 流派:2为新年以立春零点起算;1为新年以正月初一起算;3为新年以立春节气交接的时刻起算
* @return 值年九星
* @return 九星
*/
public NineStar getYearNineStar(int sect) {
String yearInGanZhi;
@@ -2061,7 +2076,7 @@ public class Lunar {
protected NineStar getMonthNineStar(int yearZhiIndex, int monthZhiIndex) {
int index = yearZhiIndex % 3;
int n = 27 - (index * 3);
int n = 27 - index * 3;
if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX) {
n -= 3;
}
@@ -2072,7 +2087,7 @@ public class Lunar {
/**
* 获取值月九星(流派2新的一月以节交接当天零点起算。月紫白星歌诀:子午卯酉八白起,寅申巳亥二黑求,辰戌丑未五黄中。)
*
* @return 值月九星
* @return 九星
*/
public NineStar getMonthNineStar() {
return getMonthNineStar(2);
@@ -2082,7 +2097,7 @@ public class Lunar {
* 获取值月九星(月紫白星歌诀:子午卯酉八白起,寅申巳亥二黑求,辰戌丑未五黄中。)
*
* @param sect 流派:2为新的一月以节交接当天零点起算;3为新的一月以节交接准确时刻起算
* @return 值月九星
* @return 九星
*/
public NineStar getMonthNineStar(int sect) {
int yearZhiIndex;
@@ -2106,7 +2121,7 @@ public class Lunar {
/**
* 获取值日九星(日家紫白星歌诀:日家白法不难求,二十四气六宫周;冬至雨水及谷雨,阳顺一七四中游;夏至处暑霜降后,九三六星逆行求。)
*
* @return 值日九星
* @return 九星
*/
public NineStar getDayNineStar() {
String solarYmd = solar.toYmd();
@@ -2119,19 +2134,19 @@ public class Lunar {
Solar solarShunBai;
Solar solarShunBai2;
Solar solarNiZi;
if (dongZhiIndex>29) {
if (dongZhiIndex > 29) {
solarShunBai = dongZhi.next(60 - dongZhiIndex);
} else {
solarShunBai = dongZhi.next(-dongZhiIndex);
}
String solarShunBaiYmd = solarShunBai.toYmd();
if (dongZhiIndex2>29) {
if (dongZhiIndex2 > 29) {
solarShunBai2 = dongZhi2.next(60 - dongZhiIndex2);
} else {
solarShunBai2 = dongZhi2.next(-dongZhiIndex2);
}
String solarShunBaiYmd2 = solarShunBai2.toYmd();
if (xiaZhiIndex>29) {
if (xiaZhiIndex > 29) {
solarNiZi = xiaZhi.next(60 - xiaZhiIndex);
} else {
solarNiZi = xiaZhi.next(-xiaZhiIndex);
@@ -2140,7 +2155,7 @@ public class Lunar {
int offset = 0;
if (solarYmd.compareTo(solarShunBaiYmd) >= 0 && solarYmd.compareTo(solarNiZiYmd) < 0) {
offset = ExactDate.getDaysBetween(solarShunBai.getCalendar(), this.getSolar().getCalendar()) % 9;
} else if (solarYmd.compareTo(solarNiZiYmd) >= 0 && solarYmd.compareTo(solarShunBaiYmd2) < 0){
} else if (solarYmd.compareTo(solarNiZiYmd) >= 0 && solarYmd.compareTo(solarShunBaiYmd2) < 0) {
offset = 8 - (ExactDate.getDaysBetween(solarNiZi.getCalendar(), this.getSolar().getCalendar()) % 9);
} else if (solarYmd.compareTo(solarShunBaiYmd2) >= 0) {
offset = ExactDate.getDaysBetween(solarShunBai2.getCalendar(), this.getSolar().getCalendar()) % 9;
@@ -2153,7 +2168,7 @@ public class Lunar {
/**
* 获取值时九星(时家紫白星歌诀:三元时白最为佳,冬至阳生顺莫差,孟日七宫仲一白,季日四绿发萌芽,每把时辰起甲子,本时星耀照光华,时星移入中宫去,顺飞八方逐细查。夏至阴生逆回首,孟归三碧季加六,仲在九宫时起甲,依然掌中逆轮跨。)
*
* @return 值时九星
* @return 九星
*/
public NineStar getTimeNineStar() {
String solarYmd = solar.toYmd();
@@ -2199,10 +2214,10 @@ public class Lunar {
* @return 节气
*/
public JieQi getNextJie(boolean wholeDay) {
int l = JIE_QI_IN_USE.length/2;
int l = JIE_QI_IN_USE.length / 2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2];
for (int i = 0; i < l; i++) {
conditions[i] = JIE_QI_IN_USE[i * 2];
}
return getNearJieQi(true, conditions, wholeDay);
}
@@ -2223,10 +2238,10 @@ public class Lunar {
* @return 节气
*/
public JieQi getPrevJie(boolean wholeDay) {
int l = JIE_QI_IN_USE.length/2;
int l = JIE_QI_IN_USE.length / 2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2];
for (int i = 0; i < l; i++) {
conditions[i] = JIE_QI_IN_USE[i * 2];
}
return getNearJieQi(false, conditions, wholeDay);
}
@@ -2247,10 +2262,10 @@ public class Lunar {
* @return 节气
*/
public JieQi getNextQi(boolean wholeDay) {
int l = JIE_QI_IN_USE.length/2;
int l = JIE_QI_IN_USE.length / 2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2+1];
for (int i = 0; i < l; i++) {
conditions[i] = JIE_QI_IN_USE[i * 2 + 1];
}
return getNearJieQi(true, conditions, wholeDay);
}
@@ -2271,10 +2286,10 @@ public class Lunar {
* @return 节气
*/
public JieQi getPrevQi(boolean wholeDay) {
int l = JIE_QI_IN_USE.length/2;
int l = JIE_QI_IN_USE.length / 2;
String[] conditions = new String[l];
for(int i=0;i<l;i++){
conditions[i] = JIE_QI_IN_USE[i*2+1];
for (int i = 0; i < l; i++) {
conditions[i] = JIE_QI_IN_USE[i * 2 + 1];
}
return getNearJieQi(false, conditions, wholeDay);
}
@@ -2322,7 +2337,7 @@ public class Lunar {
*
* @param forward 是否顺推,true为顺推,false为逆推
* @param conditions 过滤条件,如果设置过滤条件,仅返回匹配该名称的
* @param wholeDay 是否按天计
* @param wholeDay 是否按天计
* @return 节气
*/
protected JieQi getNearJieQi(boolean forward, String[] conditions, boolean wholeDay) {
@@ -2415,7 +2430,7 @@ public class Lunar {
* @return 节气对象
*/
public JieQi getCurrentJie() {
for(int i=0, j=JIE_QI_IN_USE.length; i<j; i+=2){
for (int i = 0, j = JIE_QI_IN_USE.length; i < j; i += 2) {
String key = JIE_QI_IN_USE[i];
Solar d = jieQi.get(key);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
@@ -2431,7 +2446,7 @@ public class Lunar {
* @return 节气对象
*/
public JieQi getCurrentQi() {
for(int i=1, j=JIE_QI_IN_USE.length; i<j; i+=2){
for (int i = 1, j = JIE_QI_IN_USE.length; i < j; i += 2) {
String key = JIE_QI_IN_USE[i];
Solar d = jieQi.get(key);
if (d.getYear() == solar.getYear() && d.getMonth() == solar.getMonth() && d.getDay() == solar.getDay()) {
@@ -2958,12 +2973,8 @@ public class Lunar {
break;
}
}
Calendar currentCalendar = ExactDate.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay());
Solar startSolar = jieQi.getSolar();
Calendar startCalendar = ExactDate.fromYmd(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay());
int days = ExactDate.getDaysBetween(startCalendar, currentCalendar);
int days = ExactDate.getDaysBetween(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay(), solar.getYear(), solar.getMonth(), solar.getDay());
return LunarUtil.WU_HOU[(offset * 3 + days / 5) % LunarUtil.WU_HOU.length];
}
@@ -2974,14 +2985,19 @@ public class Lunar {
*/
public String getHou() {
JieQi jieQi = getPrevJieQi(true);
String name = jieQi.getName();
Solar startSolar = jieQi.getSolar();
int days = ExactDate.getDaysBetween(startSolar.getYear(), startSolar.getMonth(), startSolar.getDay(), solar.getYear(), solar.getMonth(), solar.getDay());
return String.format("%s %s", name, LunarUtil.HOU[(days / 5) % LunarUtil.HOU.length]);
int max = LunarUtil.HOU.length - 1;
int offset = days / 5;
if (offset > max) {
offset = max;
}
return String.format("%s %s", jieQi.getName(), LunarUtil.HOU[offset]);
}
/**
* 获取日禄
*
* @return 日禄
*/
public String getDayLu() {
@@ -3011,8 +3027,8 @@ public class Lunar {
public List<LunarTime> getTimes() {
List<LunarTime> l = new ArrayList<LunarTime>();
l.add(new LunarTime(year, month, day, 0, 0, 0));
for(int i = 0; i < 12; i++){
l.add(new LunarTime(year, month, day, (i+1)*2-1, 0, 0));
for (int i = 0; i < 12; i++) {
l.add(new LunarTime(year, month, day, (i + 1) * 2 - 1, 0, 0));
}
return l;
}

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,6 +95,7 @@ public class LunarMonth {
/**
* 获取初一的儒略日
*
* @return 初一的儒略日
*/
public double getFirstJulianDay() {
@@ -96,27 +105,21 @@ public class LunarMonth {
/**
* 获取太岁方位
*
* @return 太岁方位,如艮
* @return 方位,如艮
*/
public String getPositionTaiSui() {
String p;
int m = Math.abs(month);
switch(m) {
int m = Math.abs(month) % 4;
switch (m) {
case 0:
p = "巽";
break;
case 1:
case 5:
case 9:
p = "艮";
break;
case 3:
case 7:
case 11:
p = "坤";
break;
case 4:
case 8:
case 12:
p = "巽";
break;
default:
p = LunarUtil.POSITION_GAN[Solar.fromJulianDay(this.getFirstJulianDay()).getLunar().getMonthGanIndex()];
}
@@ -126,7 +129,7 @@ public class LunarMonth {
/**
* 获取太岁方位描述
*
* @return 太岁方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionTaiSuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionTaiSui());
@@ -141,7 +144,7 @@ public class LunarMonth {
int index = LunarYear.fromYear(year).getZhiIndex() % 3;
int m = Math.abs(month);
int monthZhiIndex = (13 + m) % 12;
int n = 27 - (index * 3);
int n = 27 - index * 3;
if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX) {
n -= 3;
}
@@ -153,4 +156,72 @@ public class LunarMonth {
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

@@ -457,7 +457,7 @@ public class LunarYear {
int index = LunarUtil.getJiaZiIndex(getGanZhi()) + 1;
int yuan = ((this.year + 2696) / 60) % 3;
int offset = (62 + yuan * 3 - index) % 9;
if(0 == offset){
if (0 == offset) {
offset = 9;
}
return NineStar.fromIndex(offset - 1);
@@ -466,7 +466,7 @@ public class LunarYear {
/**
* 获取喜神方位
*
* @return 喜神方位,如艮
* @return 方位,如艮
*/
public String getPositionXi() {
return LunarUtil.POSITION_XI[ganIndex + 1];
@@ -475,7 +475,7 @@ public class LunarYear {
/**
* 获取喜神方位描述
*
* @return 喜神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionXiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionXi());
@@ -484,7 +484,7 @@ public class LunarYear {
/**
* 获取阳贵神方位
*
* @return 阳贵神方位,如艮
* @return 方位,如艮
*/
public String getPositionYangGui() {
return LunarUtil.POSITION_YANG_GUI[ganIndex + 1];
@@ -493,7 +493,7 @@ public class LunarYear {
/**
* 获取阳贵神方位描述
*
* @return 阳贵神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionYangGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYangGui());
@@ -502,7 +502,7 @@ public class LunarYear {
/**
* 获取阴贵神方位
*
* @return 阴贵神方位,如艮
* @return 方位,如艮
*/
public String getPositionYinGui() {
return LunarUtil.POSITION_YIN_GUI[ganIndex + 1];
@@ -511,7 +511,7 @@ public class LunarYear {
/**
* 获取阴贵神方位描述
*
* @return 阴贵神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionYinGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYinGui());
@@ -520,7 +520,7 @@ public class LunarYear {
/**
* 获取福神方位(默认流派:2)
*
* @return 福神方位,如艮
* @return 方位,如艮
*/
public String getPositionFu() {
return getPositionFu(2);
@@ -530,7 +530,7 @@ public class LunarYear {
* 获取福神方位
*
* @param sect 流派,1或2
* @return 福神方位,如艮
* @return 方位,如艮
*/
public String getPositionFu(int sect) {
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[ganIndex + 1];
@@ -539,7 +539,7 @@ public class LunarYear {
/**
* 获取福神方位描述(默认流派:2)
*
* @return 福神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionFuDesc() {
return getPositionFuDesc(2);
@@ -549,7 +549,7 @@ public class LunarYear {
* 获取福神方位描述
*
* @param sect 流派,1或2
* @return 福神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionFuDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getPositionFu(sect));
@@ -567,7 +567,7 @@ public class LunarYear {
/**
* 获取财神方位描述
*
* @return 财神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionCaiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionCai());
@@ -576,7 +576,7 @@ public class LunarYear {
/**
* 获取太岁方位
*
* @return 太岁方位,如艮
* @return 方位,如艮
*/
public String getPositionTaiSui() {
return LunarUtil.POSITION_TAI_SUI_YEAR[zhiIndex];
@@ -585,7 +585,7 @@ public class LunarYear {
/**
* 获取太岁方位描述
*
* @return 太岁方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionTaiSuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionTaiSui());
@@ -600,4 +600,13 @@ public class LunarYear {
return year + "年";
}
/**
* 获取往后推几年的阴历年,如果要往前推,则年数用负数
*
* @param n 年数
* @return 阴历年
*/
public LunarYear next(int n) {
return LunarYear.fromYear(year + n);
}
}

View File

@@ -155,7 +155,6 @@ 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;
@@ -166,6 +165,21 @@ public class SolarWeek {
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);
}
/**
* 周推移
*
@@ -228,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;
@@ -260,6 +273,7 @@ public class SolarWeek {
*
* @return 本周的阳历日期列表
*/
@SuppressWarnings("all")
public List<Solar> getDays() {
Solar firstDay = getFirstDay();
List<Solar> l = new ArrayList<Solar>();

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,24 +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;
// 天数差
int dayDiff = ExactDate.getDaysBetween(start.getYear(), start.getMonth(), start.getDay(), end.getYear(), end.getMonth(), end.getDay());
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;
}
/**
@@ -114,6 +160,15 @@ public class Yun {
return startDay;
}
/**
* 获取起运小时数
*
* @return 起运小时数
*/
public int getStartHour() {
return startHour;
}
/**
* 是否顺推
*
@@ -132,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,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("天猷上帝圣诞")));

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;
/**
* 农历测试
*
@@ -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

@@ -71,4 +71,16 @@ public class SolarWeekTest {
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

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