From dffee267c06262129306aaa5a0d35b06e1730998 Mon Sep 17 00:00:00 2001
From: 6tail <6tail@6tail.cn>
Date: Sun, 23 May 2021 14:20:17 +0800
Subject: [PATCH] =?UTF-8?q?v1.2.2=20=E4=BF=AE=E6=AD=A32016=E5=B9=B4?=
=?UTF-8?q?=E5=9B=BD=E5=BA=86=E8=8A=82=E6=95=B0=E6=8D=AE=EF=BC=9B=E5=88=A0?=
=?UTF-8?q?=E9=99=A45=E6=9C=8823=E6=97=A5=E4=B8=96=E7=95=8C=E8=AF=BB?=
=?UTF-8?q?=E4=B9=A6=E6=97=A5=EF=BC=9B=E4=BF=AE=E5=A4=8Dv1.2.0=E5=92=8Cv1.?=
=?UTF-8?q?2.1=E7=9A=84=E9=87=8D=E5=A4=A7bug=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
README.md | 2 +-
README_EN.md | 2 +-
pom.xml | 2 +-
src/main/java/com/nlf/calendar/JieQi.java | 18 +-
src/main/java/com/nlf/calendar/Lunar.java | 260 +++++++-----------
src/main/java/com/nlf/calendar/LunarYear.java | 4 +-
.../com/nlf/calendar/util/HolidayUtil.java | 2 +-
.../java/com/nlf/calendar/util/LunarUtil.java | 4 -
.../java/com/nlf/calendar/util/SolarUtil.java | 1 -
src/test/java/test/BaZiTest.java | 10 +
src/test/java/test/GanZhiTest.java | 35 ++-
src/test/java/test/HolidayTest.java | 9 +
src/test/java/test/LunarTest.java | 61 ++++
src/test/java/test/YunTest.java | 29 ++
14 files changed, 250 insertions(+), 189 deletions(-)
diff --git a/README.md b/README.md
index 6ad2ca0..6fe0ec2 100644
--- a/README.md
+++ b/README.md
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
cn.6tail
lunar
- 1.2.1
+ 1.2.2
```
diff --git a/README_EN.md b/README_EN.md
index 17135c6..3bc864e 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.1
+ 1.2.2
```
diff --git a/pom.xml b/pom.xml
index 764130d..29ffaf8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
cn.6tail
lunar
jar
- 1.2.1
+ 1.2.2
${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/JieQi.java b/src/main/java/com/nlf/calendar/JieQi.java
index 6cdf424..e66d304 100644
--- a/src/main/java/com/nlf/calendar/JieQi.java
+++ b/src/main/java/com/nlf/calendar/JieQi.java
@@ -1,7 +1,5 @@
package com.nlf.calendar;
-import com.nlf.calendar.util.LunarUtil;
-
/**
* 节气
*
@@ -48,15 +46,13 @@ public String getName() {
*/
public void setName(String name) {
this.name = name;
- for(String key: LunarUtil.JIE){
- if(key.equals(name)){
- this.jie = true;
- return;
- }
- }
- for(String key: LunarUtil.QI){
- if(key.equals(name)){
- this.qi = true;
+ for(int i=0,j=Lunar.JIE_QI.length;i= 0) {
g++;
z++;
@@ -310,91 +285,59 @@ private void computeYear() {
}
}
- if (g < 0) {
- g += 10;
- }
- if (g >= 10) {
- g -= 10;
- }
- if (z < 0) {
- z += 12;
- }
- if (z >= 12) {
- z -= 12;
- }
- if (gExact < 0) {
- gExact += 10;
- }
- if (gExact >= 10) {
- gExact -= 10;
- }
- if (zExact < 0) {
- zExact += 12;
- }
- if (zExact >= 12) {
- zExact -= 12;
- }
-
- yearGanIndexByLiChun = g;
- yearZhiIndexByLiChun = z;
+ yearGanIndexByLiChun = (g<0?g+10:g)%10;
+ yearZhiIndexByLiChun = (z<0?z+12:z)%12;
- yearGanIndexExact = gExact;
- yearZhiIndexExact = zExact;
+ yearGanIndexExact = (gExact<0?gExact+10:gExact)%10;
+ yearZhiIndexExact = (zExact<0?zExact+12:zExact)%12;
}
/**
- * 干支纪月计算
+ * 计算干支纪月
*/
private void computeMonth() {
Solar start = null;
Solar end;
- //干偏移值(以立春当天起算)
- int gOffset = ((yearGanIndexByLiChun % 5 + 1) * 2) % 10;
- //干偏移值(以立春交接时刻起算)
- int gOffsetExact = ((yearGanIndexExact % 5 + 1) * 2) % 10;
- //序号:大雪到小寒之间-2,小寒到立春之间-1,立春之后0
- int index = -2;
- for (String jie : LunarUtil.JIE) {
- end = jieQi.get(jie);
+ //序号:大雪以前-3,大雪到小寒之间-2,小寒到立春之间-1,立春之后0
+ int index = -3;
+ for (int i=0,j=JIE_QI_IN_USE.length;i= 0 && ymd.compareTo(eymd) < 0) {
+ if (ymd.compareTo(symd) >= 0 && ymd.compareTo(end.toYmd()) < 0) {
break;
}
start = end;
index++;
}
- if (index < 0) {
- index += 12;
- }
-
- monthGanIndex = (index + gOffset) % 10;
- monthZhiIndex = (index + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
- //序号:大雪到小寒之间-2,小寒到立春之间-1,立春之后0
- int indexExact = -2;
- for (String jie : LunarUtil.JIE) {
- end = jieQi.get(jie);
+ //干偏移值(以立春当天起算)
+ int gOffset = (((yearGanIndexByLiChun+(index<0?1:0)) % 5 + 1) * 2) % 10;
+ monthGanIndex = ((index<0?index+10:index) + gOffset) % 10;
+ monthZhiIndex = ((index<0?index+12:index) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
+
+ int indexExact = -3;
+ start = null;
+ for (int i=0,j=JIE_QI_IN_USE.length;i= 0 && time.compareTo(etime) < 0) {
+ if (time.compareTo(stime) >= 0 && time.compareTo(end.toYmdHms()) < 0) {
break;
}
start = end;
indexExact++;
}
- if (indexExact < 0) {
- indexExact += 12;
- }
- monthGanIndexExact = (indexExact + gOffsetExact) % 10;
- monthZhiIndexExact = (indexExact + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
+
+ //干偏移值(以立春交接时刻起算)
+ int gOffsetExact = (((yearGanIndexExact+(indexExact<0?1:0)) % 5 + 1) * 2) % 10;
+ monthGanIndexExact = ((indexExact<0?indexExact+10:indexExact) + gOffsetExact) % 10;
+ monthZhiIndexExact = ((indexExact<0?indexExact+12:indexExact) + LunarUtil.BASE_MONTH_ZHI_INDEX) % 12;
}
/**
- * 干支纪日计算
+ * 计算干支纪日
*/
private void computeDay() {
Solar noon = Solar.fromYmdHms(solar.getYear(), solar.getMonth(), solar.getDay(), 12, 0, 0);
@@ -427,7 +370,7 @@ private void computeDay() {
}
/**
- * 干支纪时计算
+ * 计算干支纪时
*/
private void computeTime() {
String hm = (hour < 10 ? "0" : "") + hour + ":" + (minute < 10 ? "0" : "") + minute;
@@ -436,7 +379,7 @@ private void computeTime() {
}
/**
- * 星期计算
+ * 计算星期
*/
private void computeWeek() {
this.weekIndex = solar.getWeek();
@@ -863,29 +806,40 @@ public String getSeason() {
return LunarUtil.SEASON[Math.abs(month)];
}
+ protected String convertJieQi(String name){
+ String jq = name;
+ if("DONG_ZHI".equals(jq)){
+ jq = "冬至";
+ }else if("DA_HAN".equals(jq)){
+ jq = "大寒";
+ }else if("XIAO_HAN".equals(jq)){
+ jq = "小寒";
+ }else if("LI_CHUN".equals(jq)){
+ jq = "立春";
+ }else if("DA_XUE".equals(jq)){
+ jq = "大雪";
+ }
+ return jq;
+ }
+
/**
* 获取节令
*
* @return 节令
*/
public String getJie() {
- for (String jie : LunarUtil.JIE) {
- Solar d = jieQi.get(jie);
+ String jie = "";
+ for(int i=0,j=JIE_QI.length;i getJieQiTable() {
* @return 节气
*/
public JieQi getNextJie() {
- return getNearJieQi(true, LunarUtil.JIE);
+ int l = JIE_QI_IN_USE.length/2;
+ String[] conditions = new String[l];
+ for(int i=0;i entry : jieQi.entrySet()) {
- String jq = entry.getKey();
- if (JIE_QI_APPEND.equals(jq)) {
- jq = JIE_QI_FIRST;
- }
- if (JIE_QI_PREPEND.equals(jq)) {
- jq = JIE_QI_LAST;
- }
- if (JIE_APPEND_SOLAR_FIRST.equals(jq)) {
- jq = JIE_SOLAR_FIRST;
- }
- if (QI_APPEND_SOLAR_SECOND.equals(jq)) {
- jq = QI_SOLAR_SECOND;
- }
+ String jq = convertJieQi(entry.getKey());
if (filter) {
if (!filters.contains(jq)) {
continue;
@@ -2077,16 +2034,7 @@ public String getJieQi() {
break;
}
}
- if (JIE_QI_APPEND.equals(name)) {
- name = JIE_QI_FIRST;
- } else if (JIE_QI_PREPEND.equals(name)) {
- name = JIE_QI_LAST;
- } else if (JIE_APPEND_SOLAR_FIRST.equals(name)) {
- name = JIE_SOLAR_FIRST;
- } else if (QI_APPEND_SOLAR_SECOND.equals(name)) {
- name = QI_SOLAR_SECOND;
- }
- return name;
+ return convertJieQi(name);
}
/**
@@ -2528,11 +2476,11 @@ public String getTimeXunKong() {
@SuppressWarnings("MagicConstant")
public ShuJiu getShuJiu() {
Calendar currentCalendar = ExactDate.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay());
- Solar start = jieQi.get(JIE_QI_APPEND);
+ Solar start = jieQi.get("DONG_ZHI");
Calendar startCalendar = ExactDate.fromYmd(start.getYear(), start.getMonth(), start.getDay());
if (currentCalendar.compareTo(startCalendar) < 0) {
- start = jieQi.get(JIE_QI_FIRST);
+ start = jieQi.get("冬至");
startCalendar = ExactDate.fromYmd(start.getYear(), start.getMonth(), start.getDay());
}
diff --git a/src/main/java/com/nlf/calendar/LunarYear.java b/src/main/java/com/nlf/calendar/LunarYear.java
index 3d1d766..f197e22 100644
--- a/src/main/java/com/nlf/calendar/LunarYear.java
+++ b/src/main/java/com/nlf/calendar/LunarYear.java
@@ -51,12 +51,12 @@ private void compute() {
// 节气(中午12点)
double[] jq = new double[25];
// 合朔,即每月初一(中午12点)
- double[] hs = new double[15];
+ double[] hs = new double[16];
// 每月天数
int[] dayCounts = new int[hs.length - 1];
int year = this.year - 2000;
- // 从上年的大雪到下年的大寒
+ // 从上年的大雪到下年的立春
for (int i = 0, j = Lunar.JIE_QI_IN_USE.length; i < j; i++) {
// 精确的节气
double t = 36525 * ShouXingUtil.saLonT((year + (17 + i) * 15d / 360) * ShouXingUtil.PI_2);
diff --git a/src/main/java/com/nlf/calendar/util/HolidayUtil.java b/src/main/java/com/nlf/calendar/util/HolidayUtil.java
index 42f9a2f..728faaf 100644
--- a/src/main/java/com/nlf/calendar/util/HolidayUtil.java
+++ b/src/main/java/com/nlf/calendar/util/HolidayUtil.java
@@ -20,7 +20,7 @@ public class HolidayUtil {
/** 默认节假日名称(元旦0,春节1,清明2,劳动3,端午4,中秋5,国庆6,国庆中秋7,抗战胜利日8) */
public static final String[] NAMES = {"元旦节","春节","清明节","劳动节","端午节","中秋节","国庆节","国庆中秋","抗战胜利日"};
/** 默认节假日数据,日期YYYYMMDD+名称下标+是否调休+对应节日YYYYMMDD */
- private static final String DATA = "200112290020020101200112300020020101200201010120020101200201020120020101200201030120020101200202091020020212200202101020020212200202121120020212200202131120020212200202141120020212200202151120020212200202161120020212200202171120020212200202181120020212200204273020020501200204283020020501200205013120020501200205023120020501200205033120020501200205043120020501200205053120020501200205063120020501200205073120021001200209286020021001200209296020021001200210016120021001200210026120021001200210036120021001200210046120021001200210056120021001200210066120021001200210076120021001200301010120030101200302011120030201200302021120030201200302031120030201200302041120030201200302051120030201200302061120030201200302071120030201200302081020030201200302091020030201200304263020030501200304273020030501200305013120030501200305023120030501200305033120030501200305043120030501200305053120030501200305063120030501200305073120031001200309276020031001200309286020031001200310016120031001200310026120031001200310036120031001200310046120031001200310056120031001200310066120031001200310076120031001200401010120040101200401171020040122200401181020040122200401221120040122200401231120040122200401241120040122200401251120040122200401261120040122200401271120040122200401281120040122200405013120040501200405023120040501200405033120040501200405043120040501200405053120040501200405063120040501200405073120041001200405083020040501200405093020040501200410016120041001200410026120041001200410036120041001200410046120041001200410056120041001200410066120041001200410076120041001200410096020041001200410106020041001200501010120050101200501020120050101200501030120050101200502051020050209200502061020050209200502091120050209200502101120050209200502111120050209200502121120050209200502131120050209200502141120050209200502151120050209200504303020050501200505013120050501200505023120050501200505033120050501200505043120050501200505053120050501200505063120050501200505073120051001200505083020050501200510016120051001200510026120051001200510036120051001200510046120051001200510056120051001200510066120051001200510076120051001200510086020051001200510096020051001200512310020060101200601010120060101200601020120060101200601030120060101200601281020060129200601291120060129200601301120060129200601311120060129200602011120060129200602021120060129200602031120060129200602041120060129200602051020060129200604293020060501200604303020060501200605013120060501200605023120060501200605033120060501200605043120060501200605053120060501200605063120060501200605073120061001200609306020061001200610016120061001200610026120061001200610036120061001200610046120061001200610056120061001200610066120061001200610076120061001200610086020061001200612300020070101200612310020070101200701010120070101200701020120070101200701030120070101200702171020070218200702181120070218200702191120070218200702201120070218200702211120070218200702221120070218200702231120070218200702241120070218200702251020070218200704283020070501200704293020070501200705013120070501200705023120070501200705033120070501200705043120070501200705053120070501200705063120070501200705073120070501200709296020071001200709306020071001200710016120071001200710026120071001200710036120071001200710046120071001200710056120071001200710066120071001200710076120071001200712290020080101200712300120080101200712310120080101200801010120080101200802021020080206200802031020080206200802061120080206200802071120080206200802081120080206200802091120080206200802101120080206200802111120080206200802121120080206200804042120080404200804052120080404200804062120080404200805013120080501200805023120080501200805033120080501200805043020080501200806074120080608200806084120080608200806094120080608200809135120080914200809145120080914200809155120080914200809276020081001200809286020081001200809296120081001200809306120081001200810016120081001200810026120081001200810036120081001200810046120081001200810056120081001200901010120090101200901020120090101200901030120090101200901040020090101200901241020090125200901251120090125200901261120090125200901271120090125200901281120090125200901291120090125200901301120090125200901311120090125200902011020090125200904042120090404200904052120090404200904062120090404200905013120090501200905023120090501200905033120090501200905284120090528200905294120090528200905304120090528200905314020090528200909276020091001200910016120091001200910026120091001200910036120091001200910046120091001200910055120091003200910065120091003200910075120091003200910085120091003200910105020091003201001010120100101201001020120100101201001030120100101201002131120100213201002141120100213201002151120100213201002161120100213201002171120100213201002181120100213201002191120100213201002201020100213201002211020100213201004032120100405201004042120100405201004052120100405201005013120100501201005023120100501201005033120100501201006124020100616201006134020100616201006144120100616201006154120100616201006164120100616201009195020100922201009225120100922201009235120100922201009245120100922201009255020100922201009266020101001201010016120101001201010026120101001201010036120101001201010046120101001201010056120101001201010066120101001201010076120101001201010096020101001201101010120110101201101020120110101201101030120110101201101301020110203201102021120110203201102031120110203201102041120110203201102051120110203201102061120110203201102071120110203201102081120110203201102121020110203201104022020110405201104032120110405201104042120110405201104052120110405201104303120110501201105013120110501201105023120110501201106044120110606201106054120110606201106064120110606201109105120110912201109115120110912201109125120110912201110016120111001201110026120111001201110036120111001201110046120111001201110056120111001201110066120111001201110076120111001201110086020111001201110096020111001201112310020120101201201010120120101201201020120120101201201030120120101201201211020120123201201221120120123201201231120120123201201241120120123201201251120120123201201261120120123201201271120120123201201281120120123201201291020120123201203312020120404201204012020120404201204022120120404201204032120120404201204042120120404201204283020120501201204293120120501201204303120120501201205013120120501201205023020120501201206224120120623201206234120120623201206244120120623201209295020120930201209305120120930201210016120121001201210026120121001201210036120121001201210046120121001201210056120121001201210066120121001201210076120121001201210086020121001201301010120130101201301020120130101201301030120130101201301050020130101201301060020130101201302091120130210201302101120130210201302111120130210201302121120130210201302131120130210201302141120130210201302151120130210201302161020130210201302171020130210201304042120130404201304052120130404201304062120130404201304273020130501201304283020130501201304293120130501201304303120130501201305013120130501201306084020130612201306094020130612201306104120130612201306114120130612201306124120130612201309195120130919201309205120130919201309215120130919201309225020130919201309296020131001201310016120131001201310026120131001201310036120131001201310046120131001201310056120131001201310066120131001201310076120131001201401010120140101201401261020140131201401311120140131201402011120140131201402021120140131201402031120140131201402041120140131201402051120140131201402061120140131201402081020140131201404052120140405201404062120140405201404072120140405201405013120140501201405023120140501201405033120140501201405043020140501201405314120140602201406014120140602201406024120140602201409065120140908201409075120140908201409085120140908201409286020141001201410016120141001201410026120141001201410036120141001201410046120141004201410056120141001201410066120141001201410076120141001201410116020141001201501010120150101201501020120150101201501030120150101201501040020150101201502151020150219201502181120150219201502191120150219201502201120150219201502211120150219201502221120150219201502231120150219201502241120150219201502281020150219201504042120150405201504052120150405201504062120150405201505013120150501201505023120150501201505033120150501201506204120150620201506214120150620201506224120150620201509038120150903201509048120150903201509058120150903201509068020150903201509265120150927201509275120150927201510016120151001201510026120151001201510036120151001201510046120151004201510056120151001201510066120151001201510076120151001201510106020151001201601010120160101201601020120160101201601030120160101201602061020160208201602071120160208201602081120160208201602091120160208201602101120160208201602111120160208201602121120160208201602131120160208201602141020160208201604022120160404201604032120160404201604042120160404201604303120160501201605013120160501201605023120160501201606094120160609201606104120160609201606114120160609201606124020160609201609155120160915201609165120160915201609175120160915201609185020160915201610016120161001201610026120161001201610036120161001201610046120161004201610056120161001201610066120161001201610076120161001201610086020161001201610096020161001201612310120170101201701010120170101201701020120170101201701221020170128201701271120170128201701281120170128201701291120170128201701301120170128201701311120170128201702011120170128201702021120170128201702041020170128201704012020170404201704022120170404201704032120170404201704042120170404201704293120170501201704303120170501201705013120170501201705274020170530201705284120170530201705294120170530201705304120170530201709306020171001201710016120171001201710026120171001201710036120171001201710045120171004201710056120171001201710066120171001201710076120171001201710086120171001201712300120180101201712310120180101201801010120180101201802111020180216201802151120180216201802161120180216201802171120180216201802181120180216201802191120180216201802201120180216201802211120180216201802241020180216201804052120180405201804062120180405201804072120180405201804082020180405201804283020180501201804293120180501201804303120180501201805013120180501201806164120180618201806174120180618201806184120180618201809225120180924201809235120180924201809245120180924201809296020181001201809306020181001201810016120181001201810026120181001201810036120181001201810046120181001201810056120181001201810066120181001201810076120181001201812290020190101201812300120190101201812310120190101201901010120190101201902021020190205201902031020190205201902041120190205201902051120190205201902061120190205201902071120190205201902081120190205201902091120190205201902101120190205201904052120190405201904062120190405201904072120190405201904283020190501201905013120190501201905023120190501201905033120190501201905043120190501201905053020190501201906074120190607201906084120190607201906094120190607201909135120190913201909145120190913201909155120190913201909296020191001201910016120191001201910026120191001201910036120191001201910046120191001201910056120191001201910066120191001201910076120191001201910126020191001202001010120200101202001191020200125202001241120200125202001251120200125202001261120200125202001271120200125202001281120200125202001291120200125202001301120200125202001311120200125202002011120200125202002021120200125202004042120200404202004052120200404202004062120200404202004263020200501202005013120200501202005023120200501202005033120200501202005043120200501202005053120200501202005093020200501202006254120200625202006264120200625202006274120200625202006284020200625202009277020201001202010017120201001202010026120201001202010036120201001202010046120201001202010056120201001202010066120201001202010076120201001202010086120201001202010106020201001202101010120210101202101020120210101202101030120210101202102071020210212202102111120210212202102121120210212202102131120210212202102141120210212202102151120210212202102161120210212202102171120210212202102201020210212202104032120210404202104042120210404202104052120210404202104253020210501202105013120210501202105023120210501202105033120210501202105043120210501202105053120210501202105083020210501202106124120210614202106134120210614202106144120210614202109185020210921202109195120210921202109205120210921202109215120210921202109266020211001202110016120211001202110026120211001202110036120211001202110046120211001202110056120211001202110066120211001202110076120211001202110096020211001";
+ private static final String DATA = "200112290020020101200112300020020101200201010120020101200201020120020101200201030120020101200202091020020212200202101020020212200202121120020212200202131120020212200202141120020212200202151120020212200202161120020212200202171120020212200202181120020212200204273020020501200204283020020501200205013120020501200205023120020501200205033120020501200205043120020501200205053120020501200205063120020501200205073120021001200209286020021001200209296020021001200210016120021001200210026120021001200210036120021001200210046120021001200210056120021001200210066120021001200210076120021001200301010120030101200302011120030201200302021120030201200302031120030201200302041120030201200302051120030201200302061120030201200302071120030201200302081020030201200302091020030201200304263020030501200304273020030501200305013120030501200305023120030501200305033120030501200305043120030501200305053120030501200305063120030501200305073120031001200309276020031001200309286020031001200310016120031001200310026120031001200310036120031001200310046120031001200310056120031001200310066120031001200310076120031001200401010120040101200401171020040122200401181020040122200401221120040122200401231120040122200401241120040122200401251120040122200401261120040122200401271120040122200401281120040122200405013120040501200405023120040501200405033120040501200405043120040501200405053120040501200405063120040501200405073120041001200405083020040501200405093020040501200410016120041001200410026120041001200410036120041001200410046120041001200410056120041001200410066120041001200410076120041001200410096020041001200410106020041001200501010120050101200501020120050101200501030120050101200502051020050209200502061020050209200502091120050209200502101120050209200502111120050209200502121120050209200502131120050209200502141120050209200502151120050209200504303020050501200505013120050501200505023120050501200505033120050501200505043120050501200505053120050501200505063120050501200505073120051001200505083020050501200510016120051001200510026120051001200510036120051001200510046120051001200510056120051001200510066120051001200510076120051001200510086020051001200510096020051001200512310020060101200601010120060101200601020120060101200601030120060101200601281020060129200601291120060129200601301120060129200601311120060129200602011120060129200602021120060129200602031120060129200602041120060129200602051020060129200604293020060501200604303020060501200605013120060501200605023120060501200605033120060501200605043120060501200605053120060501200605063120060501200605073120061001200609306020061001200610016120061001200610026120061001200610036120061001200610046120061001200610056120061001200610066120061001200610076120061001200610086020061001200612300020070101200612310020070101200701010120070101200701020120070101200701030120070101200702171020070218200702181120070218200702191120070218200702201120070218200702211120070218200702221120070218200702231120070218200702241120070218200702251020070218200704283020070501200704293020070501200705013120070501200705023120070501200705033120070501200705043120070501200705053120070501200705063120070501200705073120070501200709296020071001200709306020071001200710016120071001200710026120071001200710036120071001200710046120071001200710056120071001200710066120071001200710076120071001200712290020080101200712300120080101200712310120080101200801010120080101200802021020080206200802031020080206200802061120080206200802071120080206200802081120080206200802091120080206200802101120080206200802111120080206200802121120080206200804042120080404200804052120080404200804062120080404200805013120080501200805023120080501200805033120080501200805043020080501200806074120080608200806084120080608200806094120080608200809135120080914200809145120080914200809155120080914200809276020081001200809286020081001200809296120081001200809306120081001200810016120081001200810026120081001200810036120081001200810046120081001200810056120081001200901010120090101200901020120090101200901030120090101200901040020090101200901241020090125200901251120090125200901261120090125200901271120090125200901281120090125200901291120090125200901301120090125200901311120090125200902011020090125200904042120090404200904052120090404200904062120090404200905013120090501200905023120090501200905033120090501200905284120090528200905294120090528200905304120090528200905314020090528200909276020091001200910016120091001200910026120091001200910036120091001200910046120091001200910055120091003200910065120091003200910075120091003200910085120091003200910105020091003201001010120100101201001020120100101201001030120100101201002131120100213201002141120100213201002151120100213201002161120100213201002171120100213201002181120100213201002191120100213201002201020100213201002211020100213201004032120100405201004042120100405201004052120100405201005013120100501201005023120100501201005033120100501201006124020100616201006134020100616201006144120100616201006154120100616201006164120100616201009195020100922201009225120100922201009235120100922201009245120100922201009255020100922201009266020101001201010016120101001201010026120101001201010036120101001201010046120101001201010056120101001201010066120101001201010076120101001201010096020101001201101010120110101201101020120110101201101030120110101201101301020110203201102021120110203201102031120110203201102041120110203201102051120110203201102061120110203201102071120110203201102081120110203201102121020110203201104022020110405201104032120110405201104042120110405201104052120110405201104303120110501201105013120110501201105023120110501201106044120110606201106054120110606201106064120110606201109105120110912201109115120110912201109125120110912201110016120111001201110026120111001201110036120111001201110046120111001201110056120111001201110066120111001201110076120111001201110086020111001201110096020111001201112310020120101201201010120120101201201020120120101201201030120120101201201211020120123201201221120120123201201231120120123201201241120120123201201251120120123201201261120120123201201271120120123201201281120120123201201291020120123201203312020120404201204012020120404201204022120120404201204032120120404201204042120120404201204283020120501201204293120120501201204303120120501201205013120120501201205023020120501201206224120120623201206234120120623201206244120120623201209295020120930201209305120120930201210016120121001201210026120121001201210036120121001201210046120121001201210056120121001201210066120121001201210076120121001201210086020121001201301010120130101201301020120130101201301030120130101201301050020130101201301060020130101201302091120130210201302101120130210201302111120130210201302121120130210201302131120130210201302141120130210201302151120130210201302161020130210201302171020130210201304042120130404201304052120130404201304062120130404201304273020130501201304283020130501201304293120130501201304303120130501201305013120130501201306084020130612201306094020130612201306104120130612201306114120130612201306124120130612201309195120130919201309205120130919201309215120130919201309225020130919201309296020131001201310016120131001201310026120131001201310036120131001201310046120131001201310056120131001201310066120131001201310076120131001201401010120140101201401261020140131201401311120140131201402011120140131201402021120140131201402031120140131201402041120140131201402051120140131201402061120140131201402081020140131201404052120140405201404062120140405201404072120140405201405013120140501201405023120140501201405033120140501201405043020140501201405314120140602201406014120140602201406024120140602201409065120140908201409075120140908201409085120140908201409286020141001201410016120141001201410026120141001201410036120141001201410046120141004201410056120141001201410066120141001201410076120141001201410116020141001201501010120150101201501020120150101201501030120150101201501040020150101201502151020150219201502181120150219201502191120150219201502201120150219201502211120150219201502221120150219201502231120150219201502241120150219201502281020150219201504042120150405201504052120150405201504062120150405201505013120150501201505023120150501201505033120150501201506204120150620201506214120150620201506224120150620201509038120150903201509048120150903201509058120150903201509068020150903201509265120150927201509275120150927201510016120151001201510026120151001201510036120151001201510046120151004201510056120151001201510066120151001201510076120151001201510106020151001201601010120160101201601020120160101201601030120160101201602061020160208201602071120160208201602081120160208201602091120160208201602101120160208201602111120160208201602121120160208201602131120160208201602141020160208201604022120160404201604032120160404201604042120160404201604303120160501201605013120160501201605023120160501201606094120160609201606104120160609201606114120160609201606124020160609201609155120160915201609165120160915201609175120160915201609185020160915201610016120161001201610026120161001201610036120161001201610046120161001201610056120161001201610066120161001201610076120161001201610086020161001201610096020161001201612310120170101201701010120170101201701020120170101201701221020170128201701271120170128201701281120170128201701291120170128201701301120170128201701311120170128201702011120170128201702021120170128201702041020170128201704012020170404201704022120170404201704032120170404201704042120170404201704293120170501201704303120170501201705013120170501201705274020170530201705284120170530201705294120170530201705304120170530201709306020171001201710016120171001201710026120171001201710036120171001201710045120171004201710056120171001201710066120171001201710076120171001201710086120171001201712300120180101201712310120180101201801010120180101201802111020180216201802151120180216201802161120180216201802171120180216201802181120180216201802191120180216201802201120180216201802211120180216201802241020180216201804052120180405201804062120180405201804072120180405201804082020180405201804283020180501201804293120180501201804303120180501201805013120180501201806164120180618201806174120180618201806184120180618201809225120180924201809235120180924201809245120180924201809296020181001201809306020181001201810016120181001201810026120181001201810036120181001201810046120181001201810056120181001201810066120181001201810076120181001201812290020190101201812300120190101201812310120190101201901010120190101201902021020190205201902031020190205201902041120190205201902051120190205201902061120190205201902071120190205201902081120190205201902091120190205201902101120190205201904052120190405201904062120190405201904072120190405201904283020190501201905013120190501201905023120190501201905033120190501201905043120190501201905053020190501201906074120190607201906084120190607201906094120190607201909135120190913201909145120190913201909155120190913201909296020191001201910016120191001201910026120191001201910036120191001201910046120191001201910056120191001201910066120191001201910076120191001201910126020191001202001010120200101202001191020200125202001241120200125202001251120200125202001261120200125202001271120200125202001281120200125202001291120200125202001301120200125202001311120200125202002011120200125202002021120200125202004042120200404202004052120200404202004062120200404202004263020200501202005013120200501202005023120200501202005033120200501202005043120200501202005053120200501202005093020200501202006254120200625202006264120200625202006274120200625202006284020200625202009277020201001202010017120201001202010026120201001202010036120201001202010046120201001202010056120201001202010066120201001202010076120201001202010086120201001202010106020201001202101010120210101202101020120210101202101030120210101202102071020210212202102111120210212202102121120210212202102131120210212202102141120210212202102151120210212202102161120210212202102171120210212202102201020210212202104032120210404202104042120210404202104052120210404202104253020210501202105013120210501202105023120210501202105033120210501202105043120210501202105053120210501202105083020210501202106124120210614202106134120210614202106144120210614202109185020210921202109195120210921202109205120210921202109215120210921202109266020211001202110016120211001202110026120211001202110036120211001202110046120211001202110056120211001202110066120211001202110076120211001202110096020211001";
/** 使用的节假日名称 */
private static String[] NAMES_IN_USE = NAMES;
diff --git a/src/main/java/com/nlf/calendar/util/LunarUtil.java b/src/main/java/com/nlf/calendar/util/LunarUtil.java
index bcf25d8..2a41fe7 100644
--- a/src/main/java/com/nlf/calendar/util/LunarUtil.java
+++ b/src/main/java/com/nlf/calendar/util/LunarUtil.java
@@ -112,10 +112,6 @@ public class LunarUtil{
public static final String[] SEASON = {"","孟春","仲春","季春","孟夏","仲夏","季夏","孟秋","仲秋","季秋","孟冬","仲冬","季冬"};
/** 生肖 */
public static final String[] SHENGXIAO = {"","鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"};
- /** 气 */
- public static final String[] QI = {"大寒","雨水","春分","谷雨","小满","夏至","大暑","处暑","秋分","霜降","小雪","冬至"};
- /** 节 */
- public static final String[] JIE = {"小寒","立春","惊蛰","清明","立夏","芒种","小暑","立秋","白露","寒露","立冬","大雪"};
/** 日 */
public static final String[] DAY = {"","初一","初二","初三","初四","初五","初六","初七","初八","初九","初十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十","廿一","廿二","廿三","廿四","廿五","廿六","廿七","廿八","廿九","三十"};
/** 月相,朔月也叫新月,望月也叫满月 */
diff --git a/src/main/java/com/nlf/calendar/util/SolarUtil.java b/src/main/java/com/nlf/calendar/util/SolarUtil.java
index 2dbf92f..5c712e8 100644
--- a/src/main/java/com/nlf/calendar/util/SolarUtil.java
+++ b/src/main/java/com/nlf/calendar/util/SolarUtil.java
@@ -97,7 +97,6 @@ public class SolarUtil {
put("5-5", Collections.nCopies(1, "马克思诞辰纪念日"));
put("5-8", Collections.nCopies(1, "世界红十字日"));
put("5-11", Collections.nCopies(1, "世界肥胖日"));
- put("5-23", Collections.nCopies(1, "世界读书日"));
put("5-27", Collections.nCopies(1, "上海解放日"));
put("5-31", Collections.nCopies(1, "世界无烟日"));
put("6-5", Collections.nCopies(1, "世界环境日"));
diff --git a/src/test/java/test/BaZiTest.java b/src/test/java/test/BaZiTest.java
index 31570f4..d38dba9 100644
--- a/src/test/java/test/BaZiTest.java
+++ b/src/test/java/test/BaZiTest.java
@@ -57,6 +57,16 @@ public void testGanZhi2() {
Assert.assertEquals("时柱", "辛亥", eightChar.getTime());
}
+ @Test
+ public void testGanZhi3(){
+ Lunar lunar = new Lunar(2019,12,12,11,22,0);
+ EightChar eightChar = lunar.getEightChar();
+ Assert.assertEquals("年柱", "己亥", eightChar.getYear());
+ Assert.assertEquals("月柱", "丁丑", eightChar.getMonth());
+ Assert.assertEquals("日柱", "戊申", eightChar.getDay());
+ Assert.assertEquals("时柱", "戊午", eightChar.getTime());
+ }
+
@Test
public void testHideGan() {
Solar solar = new Solar(2005, 12, 23, 8, 37, 0);
diff --git a/src/test/java/test/GanZhiTest.java b/src/test/java/test/GanZhiTest.java
index 482519d..9de27e5 100644
--- a/src/test/java/test/GanZhiTest.java
+++ b/src/test/java/test/GanZhiTest.java
@@ -73,17 +73,6 @@ public void test(){
Assert.assertEquals("丁丑",lunar.getMonthInGanZhi());
Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
-
- solar = new Solar(2020,2,4,13,22,0);
- lunar = solar.getLunar();
- Assert.assertEquals("庚子",lunar.getYearInGanZhi());
- Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
- Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
-
- Assert.assertEquals("戊寅",lunar.getMonthInGanZhi());
- Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
-
-
solar = new Solar(2020,2,4,18,22,0);
lunar = solar.getLunar();
Assert.assertEquals("庚子",lunar.getYearInGanZhi());
@@ -320,4 +309,28 @@ public void test16() {
Assert.assertEquals("戊辰",lunar.getYearInGanZhiExact());
}
+ @Test
+ public void test17() {
+ Solar solar = new Solar(2019, 2, 8, 13, 22, 0);
+ Lunar lunar = solar.getLunar();
+ Assert.assertEquals("己亥", lunar.getYearInGanZhi());
+ Assert.assertEquals("己亥", lunar.getYearInGanZhiByLiChun());
+ Assert.assertEquals("己亥", lunar.getYearInGanZhiExact());
+
+ Assert.assertEquals("丙寅", lunar.getMonthInGanZhi());
+ Assert.assertEquals("丙寅", lunar.getMonthInGanZhiExact());
+ }
+
+ @Test
+ public void test18() {
+ Solar solar = new Solar(2020,2,4,13,22,0);
+ Lunar lunar = solar.getLunar();
+ Assert.assertEquals("庚子",lunar.getYearInGanZhi());
+ Assert.assertEquals("庚子",lunar.getYearInGanZhiByLiChun());
+ Assert.assertEquals("己亥",lunar.getYearInGanZhiExact());
+
+ Assert.assertEquals("戊寅",lunar.getMonthInGanZhi());
+ Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
+ }
+
}
diff --git a/src/test/java/test/HolidayTest.java b/src/test/java/test/HolidayTest.java
index c6ca34a..bf571e7 100644
--- a/src/test/java/test/HolidayTest.java
+++ b/src/test/java/test/HolidayTest.java
@@ -1,5 +1,6 @@
package test;
+import com.nlf.calendar.Holiday;
import com.nlf.calendar.Solar;
import com.nlf.calendar.util.HolidayUtil;
import org.junit.Assert;
@@ -116,4 +117,12 @@ public void test() {
Assert.assertEquals("2021-11-11 结婚纪念日 2021-11-11", HolidayUtil.getHoliday("2021-11-11") + "");
Assert.assertEquals("2021-12-01 她的生日 2021-12-01", HolidayUtil.getHoliday("2021-12-01") + "");
}
+
+ @Test
+ public void test1() {
+ Holiday holiday = HolidayUtil.getHoliday(2016,10,4);
+ Assert.assertNotNull(holiday);
+ Assert.assertNotNull(holiday.getTarget());
+ Assert.assertEquals("2016-10-01",holiday.getTarget());
+ }
}
diff --git a/src/test/java/test/LunarTest.java b/src/test/java/test/LunarTest.java
index 475e4a0..e4fcd3d 100644
--- a/src/test/java/test/LunarTest.java
+++ b/src/test/java/test/LunarTest.java
@@ -64,6 +64,67 @@ public void test7(){
Assert.assertEquals("2020-05-24",lunar.getSolar().toString());
}
+ @Test
+ public void test8(){
+ Lunar lunar = new Lunar(2020,12,10,13,0,0);
+ Assert.assertEquals("二〇二〇年腊月初十",lunar.toString());
+ Assert.assertEquals("2021-01-22",lunar.getSolar().toString());
+ }
+
+ @Test
+ public void test9(){
+ Lunar lunar = new Lunar(1500,1,1,12,0,0);
+ Assert.assertEquals("1500-01-31",lunar.getSolar().toString());
+ }
+
+ @Test
+ public void test10(){
+ Lunar lunar = new Lunar(1500,12,29,12,0,0);
+ Assert.assertEquals("1501-01-18",lunar.getSolar().toString());
+ }
+
+ @Test
+ public void test11(){
+ Solar solar = new Solar(1500,1,1,12,0,0);
+ Assert.assertEquals("一四九九年腊月初一",solar.getLunar().toString());
+ }
+
+ @Test
+ public void test12(){
+ Solar solar = new Solar(1500,12,31,12,0,0);
+ Assert.assertEquals("一五〇〇年腊月十一",solar.getLunar().toString());
+ }
+
+ @Test
+ public void test13(){
+ Solar solar = new Solar(1582,10,4,12,0,0);
+ Assert.assertEquals("一五八二年九月十八",solar.getLunar().toString());
+ }
+
+ @Test
+ public void test14(){
+ Solar solar = new Solar(1582,10,15,12,0,0);
+ Assert.assertEquals("一五八二年九月十九",solar.getLunar().toString());
+ }
+
+ @Test
+ public void test15(){
+ Lunar lunar = new Lunar(1582,9,18,12,0,0);
+ Assert.assertEquals("1582-10-04",lunar.getSolar().toString());
+ }
+
+ @Test
+ public void test16(){
+ Lunar lunar = new Lunar(1582,9,19,12,0,0);
+ Assert.assertEquals("1582-10-15",lunar.getSolar().toString());
+ }
+
+ @Test
+ public void test17(){
+ Lunar lunar = new Lunar(2019,12,12,11,22,0);
+ Assert.assertEquals("2020-01-06",lunar.getSolar().toString());
+ }
+
@Test
public void testNext(){
Solar solar = new Solar(2020,1,10,12,0,0);
diff --git a/src/test/java/test/YunTest.java b/src/test/java/test/YunTest.java
index 9142ef2..8acf117 100644
--- a/src/test/java/test/YunTest.java
+++ b/src/test/java/test/YunTest.java
@@ -24,4 +24,33 @@ public void test1() {
Assert.assertEquals("起运阳历", "1989-02-18", yun.getStartSolar().toYmd());
}
+ @Test
+ public void test2() {
+ Lunar lunar = new Lunar(2019, 12, 12, 11, 22, 0);
+ System.out.println(lunar.getMonth());
+ System.out.println(lunar.toFullString());
+ System.out.println(lunar.getSolar().toFullString());
+ EightChar eightChar = lunar.getEightChar();
+ Yun yun = eightChar.getYun(1);
+ Assert.assertEquals("起运年数", 0, yun.getStartYear());
+ Assert.assertEquals("起运月数", 1, yun.getStartMonth());
+ Assert.assertEquals("起运天数", 0, yun.getStartDay());
+ Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
+ }
+
+ @Test
+ public void test3() {
+ Solar solar = new Solar(2020, 1, 6, 11, 22, 0);
+ Lunar lunar = solar.getLunar();
+ System.out.println(lunar.getMonth());
+ System.out.println(lunar.toFullString());
+ System.out.println(lunar.getSolar().toFullString());
+ EightChar eightChar = lunar.getEightChar();
+ Yun yun = eightChar.getYun(1);
+ Assert.assertEquals("起运年数", 0, yun.getStartYear());
+ Assert.assertEquals("起运月数", 1, yun.getStartMonth());
+ Assert.assertEquals("起运天数", 0, yun.getStartDay());
+ Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
+ }
+
}