From 1a15531fb4ab45274e4fdd167b67a1b0914013de Mon Sep 17 00:00:00 2001
From: 6tail <6tail@6tail.cn>
Date: Wed, 16 Feb 2022 20:11:13 +0800
Subject: [PATCH] =?UTF-8?q?v1.2.19=20=E6=96=B0=E5=A2=9E=E9=98=B4=E5=8E=86?=
=?UTF-8?q?=E5=B9=B4=E3=80=81=E9=98=B4=E5=8E=86=E6=9C=88=E7=9A=84=E6=8E=A8?=
=?UTF-8?q?=E7=A7=BB=EF=BC=9B=E4=BF=AE=E5=A4=8D=E4=B8=89=E5=80=99=E9=94=99?=
=?UTF-8?q?=E8=AF=AF=EF=BC=9B=E4=BF=AE=E5=A4=8D=E9=81=93=E5=8E=86=E8=8A=82?=
=?UTF-8?q?=E6=97=A5=E9=94=99=E5=88=AB=E5=AD=97=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 32 +---
README_EN.md | 2 +-
pom.xml | 2 +-
src/main/java/com/nlf/calendar/Lunar.java | 178 +++++++++---------
.../java/com/nlf/calendar/LunarMonth.java | 109 +++++++++--
src/main/java/com/nlf/calendar/LunarYear.java | 37 ++--
.../java/com/nlf/calendar/util/TaoUtil.java | 8 +-
src/test/java/sample/MonthTest.java | 23 ++-
src/test/java/test/LunarTest.java | 21 +++
9 files changed, 249 insertions(+), 163 deletions(-)
diff --git a/README.md b/README.md
index 611cfbf..885851b 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
cn.6tail
lunar
- 1.2.18
+ 1.2.19
```
@@ -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年。
diff --git a/README_EN.md b/README_EN.md
index 238d238..edfcfa6 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
cn.6tail
lunar
- 1.2.18
+ 1.2.19
```
diff --git a/pom.xml b/pom.xml
index 4a620f5..5a9f981 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
cn.6tail
lunar
jar
- 1.2.18
+ 1.2.19
${project.groupId}:${project.artifactId}
https://github.com/6tail/lunar-java
a calendar library for Solar and Chinese Lunar
diff --git a/src/main/java/com/nlf/calendar/Lunar.java b/src/main/java/com/nlf/calendar/Lunar.java
index d84a4c4..de1eb8a 100644
--- a/src/main/java/com/nlf/calendar/Lunar.java
+++ b/src/main/java/com/nlf/calendar/Lunar.java
@@ -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= 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= 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; i29) {
+ 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 +2135,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 +2148,7 @@ public class Lunar {
/**
* 获取值时九星(时家紫白星歌诀:三元时白最为佳,冬至阳生顺莫差,孟日七宫仲一白,季日四绿发萌芽,每把时辰起甲子,本时星耀照光华,时星移入中宫去,顺飞八方逐细查。夏至阴生逆回首,孟归三碧季加六,仲在九宫时起甲,依然掌中逆轮跨。)
*
- * @return 值时九星
+ * @return 九星
*/
public NineStar getTimeNineStar() {
String solarYmd = solar.toYmd();
@@ -2199,10 +2194,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 max) {
+ offset = max;
+ }
+ return String.format("%s %s", jieQi.getName(), LunarUtil.HOU[offset]);
}
/**
* 获取日禄
+ *
* @return 日禄
*/
public String getDayLu() {
@@ -3011,8 +3007,8 @@ public class Lunar {
public List getTimes() {
List l = new ArrayList();
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;
}
diff --git a/src/main/java/com/nlf/calendar/LunarMonth.java b/src/main/java/com/nlf/calendar/LunarMonth.java
index f2b7186..94eaf50 100644
--- a/src/main/java/com/nlf/calendar/LunarMonth.java
+++ b/src/main/java/com/nlf/calendar/LunarMonth.java
@@ -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 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 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);
+ }
+ }
+
}
diff --git a/src/main/java/com/nlf/calendar/LunarYear.java b/src/main/java/com/nlf/calendar/LunarYear.java
index 17ac6c0..4c430b9 100644
--- a/src/main/java/com/nlf/calendar/LunarYear.java
+++ b/src/main/java/com/nlf/calendar/LunarYear.java
@@ -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);
+ }
}
diff --git a/src/main/java/com/nlf/calendar/util/TaoUtil.java b/src/main/java/com/nlf/calendar/util/TaoUtil.java
index 63537c7..1f6510d 100644
--- a/src/main/java/com/nlf/calendar/util/TaoUtil.java
+++ b/src/main/java/com/nlf/calendar/util/TaoUtil.java
@@ -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("天猷上帝圣诞")));
diff --git a/src/test/java/sample/MonthTest.java b/src/test/java/sample/MonthTest.java
index 53b5589..e0ea9af 100644
--- a/src/test/java/sample/MonthTest.java
+++ b/src/test/java/sample/MonthTest.java
@@ -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());
+ }
+ }
+
}
diff --git a/src/test/java/test/LunarTest.java b/src/test/java/test/LunarTest.java
index 437f602..1f90405 100644
--- a/src/test/java/test/LunarTest.java
+++ b/src/test/java/test/LunarTest.java
@@ -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,20 @@ 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());
+ }
+
}