Skip to content

Commit

Permalink
v1.2.15 南京大XX纪念日更改为国家公祭日;新增初候、二候、三候;新增三元九运;新增道历戊日。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Dec 22, 2021
1 parent e9ec0fc commit c91bcc5
Show file tree
Hide file tree
Showing 11 changed files with 274 additions and 16 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.14</version>
<version>1.2.15</version>
</dependency>
```

Expand Down Expand Up @@ -57,6 +57,8 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)

## 更新日志

v1.2.15 南京大XX纪念日更改为国家公祭日;新增初候、二候、三候;新增三元九运;新增道历戊日。

v1.2.14 佛历新增27宿;修复宜忌重复的问题;修复获取气时缺冬至的问题。

v1.2.13 新增道历Tao。
Expand Down
2 changes: 1 addition & 1 deletion README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.13</version>
<version>1.2.15</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.2.14</version>
<version>1.2.15</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>
Expand Down
112 changes: 100 additions & 12 deletions src/main/java/com/nlf/calendar/Lunar.java
Original file line number Diff line number Diff line change
Expand Up @@ -1954,12 +1954,22 @@ public Map<String, Solar> getJieQiTable() {
* @return 节气
*/
public JieQi getNextJie() {
return getNextJie(false);
}

/**
* 获取下一节令(顺推的第一个节令)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getNextJie(boolean wholeDay) {
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];
}
return getNearJieQi(true, conditions);
return getNearJieQi(true, conditions, wholeDay);
}

/**
Expand All @@ -1968,12 +1978,22 @@ public JieQi getNextJie() {
* @return 节气
*/
public JieQi getPrevJie() {
return getPrevJie(false);
}

/**
* 获取上一节令(逆推的第一个节令)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getPrevJie(boolean wholeDay) {
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];
}
return getNearJieQi(false, conditions);
return getNearJieQi(false, conditions, wholeDay);
}

/**
Expand All @@ -1982,12 +2002,22 @@ public JieQi getPrevJie() {
* @return 节气
*/
public JieQi getNextQi() {
return getNextQi(false);
}

/**
* 获取下一气令(顺推的第一个气令)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getNextQi(boolean wholeDay) {
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];
}
return getNearJieQi(true, conditions);
return getNearJieQi(true, conditions, wholeDay);
}

/**
Expand All @@ -1996,12 +2026,22 @@ public JieQi getNextQi() {
* @return 节气
*/
public JieQi getPrevQi() {
return getPrevQi(false);
}

/**
* 获取上一气令(逆推的第一个气令)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getPrevQi(boolean wholeDay) {
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];
}
return getNearJieQi(false, conditions);
return getNearJieQi(false, conditions, wholeDay);
}

/**
Expand All @@ -2010,7 +2050,17 @@ public JieQi getPrevQi() {
* @return 节气
*/
public JieQi getNextJieQi() {
return getNearJieQi(true, null);
return getNextJieQi(false);
}

/**
* 获取下一节气(顺推的第一个节气)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getNextJieQi(boolean wholeDay) {
return getNearJieQi(true, null, wholeDay);
}

/**
Expand All @@ -2019,25 +2069,36 @@ public JieQi getNextJieQi() {
* @return 节气
*/
public JieQi getPrevJieQi() {
return getNearJieQi(false, null);
return getPrevJieQi(false);
}

/**
* 获取上一节气(逆推的第一个节气)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getPrevJieQi(boolean wholeDay) {
return getNearJieQi(false, null, wholeDay);
}

/**
* 获取最近的节气,如果未找到匹配的,返回null
*
* @param forward 是否顺推,true为顺推,false为逆推
* @param conditions 过滤条件,如果设置过滤条件,仅返回匹配该名称的
* @param wholeDay 是否按天计
* @return 节气
*/
protected JieQi getNearJieQi(boolean forward, String[] conditions) {
protected JieQi getNearJieQi(boolean forward, String[] conditions, boolean wholeDay) {
String name = null;
Solar near = null;
Set<String> filters = new HashSet<String>();
if (null != conditions) {
Collections.addAll(filters, conditions);
}
boolean filter = !filters.isEmpty();
String today = solar.toYmdHms();
String today = wholeDay ? solar.toYmd() : solar.toYmdHms();
for (Map.Entry<String, Solar> entry : jieQi.entrySet()) {
String jq = convertJieQi(entry.getKey());
if (filter) {
Expand All @@ -2046,22 +2107,34 @@ protected JieQi getNearJieQi(boolean forward, String[] conditions) {
}
}
Solar solar = entry.getValue();
String day = solar.toYmdHms();
String day = wholeDay ? solar.toYmd() : solar.toYmdHms();
if (forward) {
if (day.compareTo(today) < 0) {
continue;
}
if (null == near || day.compareTo(near.toYmdHms()) < 0) {
if (null == near) {
name = jq;
near = solar;
} else {
String nearDay = wholeDay ? near.toYmd() : near.toYmdHms();
if (day.compareTo(nearDay) < 0) {
name = jq;
near = solar;
}
}
} else {
if (day.compareTo(today) > 0) {
continue;
}
if (null == near || day.compareTo(near.toYmdHms()) > 0) {
if (null == near) {
name = jq;
near = solar;
} else {
String nearDay = wholeDay ? near.toYmd() : near.toYmdHms();
if (day.compareTo(nearDay) > 0) {
name = jq;
near = solar;
}
}
}
}
Expand Down Expand Up @@ -2626,7 +2699,7 @@ public String getLiuYao() {
*/
@SuppressWarnings("MagicConstant")
public String getWuHou() {
JieQi jieQi = getPrevJieQi();
JieQi jieQi = getPrevJieQi(true);
String name = jieQi.getName();
int offset = 0;
for (int i = 0, j = JIE_QI.length; i < j; i++) {
Expand All @@ -2644,6 +2717,21 @@ public String getWuHou() {
return LunarUtil.WU_HOU[(offset * 3 + days / 5) % LunarUtil.WU_HOU.length];
}

/**
* 获取候
*
* @return 候
*/
public String getHou() {
JieQi jieQi = getPrevJieQi(true);
String name = jieQi.getName();
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 = (int) ((currentCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / MS_PER_DAY);
return String.format("%s %s", name, LunarUtil.HOU[(days / 5) % LunarUtil.HOU.length]);
}

/**
* 获取日禄
* @return 日禄
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/com/nlf/calendar/LunarYear.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
*/
public class LunarYear {

/**
* 元
*/
private static final String[] YUAN = {"下", "上", "中"};

/**
* 运
*/
private static final String[] YUN = {"七", "八", "九", "一", "二", "三", "四", "五", "六"};

/**
* 闰冬月年份
*/
Expand Down Expand Up @@ -264,6 +274,24 @@ public String getDeJin() {
return LunarUtil.NUMBER[offset+1] + "日得金";
}

/**
* 获取三元
*
* @return 元
*/
public String getYuan() {
return YUAN[((year + 2696) / 60) % 3] + "元";
}

/**
* 获取九运
*
* @return 运
*/
public String getYun() {
return YUN[((year + 2696) / 20) % 9] + "运";
}

@Override
public String toString() {
return year + "";
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/nlf/calendar/Tao.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,33 @@ public boolean isDayBaHui() {
return TaoUtil.BA_HUI.containsKey(lunar.getDayInGanZhi());
}

/**
* 是否明戊日
*
* @return true/false
*/
public boolean isDayMingWu() {
return "戊".equals(lunar.getDayGan());
}

/**
* 是否暗戊日
*
* @return true/false
*/
public boolean isDayAnWu() {
return lunar.getDayZhi().equals(TaoUtil.AN_WU[Math.abs(getMonth()) - 1]);
}

/**
* 是否戊日
*
* @return true/false
*/
public boolean isDayWu() {
return isDayMingWu() || isDayAnWu();
}

@Override
public String toString() {
return String.format("%s年%s月%s", getYearInChinese(), getMonthInChinese(), getDayInChinese());
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/nlf/calendar/util/LunarUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class LunarUtil{
public static final String[] XUN_KONG = {"戌亥","申酉","午未","辰巳","寅卯","子丑"};
/** 六曜 */
public static final String[] LIU_YAO = {"先胜","友引","先负","佛灭","大安","赤口"};
/** 候 */
public static final String[] HOU = {"初候", "二候", "三候"};
/** 物候 */
public static final String[] WU_HOU = {"蚯蚓结","麋角解","水泉动","雁北乡","鹊始巢","雉始雊","鸡始乳","征鸟厉疾","水泽腹坚","东风解冻","蛰虫始振","鱼陟负冰","獭祭鱼","候雁北","草木萌动","桃始华","仓庚鸣","鹰化为鸠","玄鸟至","雷乃发声","始电","桐始华","田鼠化为鴽","虹始见","萍始生","鸣鸠拂奇羽","戴胜降于桑","蝼蝈鸣","蚯蚓出","王瓜生","苦菜秀","靡草死","麦秋至","螳螂生","鵙始鸣","反舌无声","鹿角解","蜩始鸣","半夏生","温风至","蟋蟀居壁","鹰始挚","腐草为萤","土润溽暑","大雨行时","凉风至","白露降","寒蝉鸣","鹰乃祭鸟","天地始肃","禾乃登","鸿雁来","玄鸟归","群鸟养羞","雷始收声","蛰虫坯户","水始涸","鸿雁来宾","雀入大水为蛤","菊有黄花","豺乃祭兽","草木黄落","蛰虫咸俯","水始冰","地始冻","雉入大水为蜃","虹藏不见","天气上升地气下降","闭塞而成冬","鹖鴠不鸣","虎始交","荔挺出"};
/** 天干 */
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nlf/calendar/util/SolarUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class SolarUtil {
put("11-28", Collections.nCopies(1, "恩格斯诞辰纪念日"));
put("12-1", Collections.nCopies(1, "世界艾滋病日"));
put("12-12", Collections.nCopies(1, "西安事变纪念日"));
put("12-13", Collections.nCopies(1, "南京大屠杀纪念日"));
put("12-13", Collections.nCopies(1, "国家公祭日"));
put("12-26", Collections.nCopies(1, "毛泽东诞辰纪念日"));
}
};
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/com/nlf/calendar/util/TaoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,9 @@ public class TaoUtil {
*/
public static final String[] WU_LA = {"1-1", "5-5", "7-7", "10-1", "12-8"};

/**
* 暗戊
*/
public static final String[] AN_WU = {"未", "戌", "辰", "寅", "午", "子", "酉", "申", "巳", "亥", "卯", "丑"};

}
28 changes: 28 additions & 0 deletions src/test/java/test/WuHouTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,32 @@ public void test9(){
Assert.assertEquals(solar.toString(),"蚯蚓结",lunar.getWuHou());
}

@Test
public void test10(){
Solar solar = new Solar(2021,12,21);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"冬至 初候",lunar.getHou());
}

@Test
public void test11(){
Solar solar = new Solar(2021,12,26);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"冬至 二候",lunar.getHou());
}

@Test
public void test12(){
Solar solar = new Solar(2021,12,31);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"冬至 三候",lunar.getHou());
}

@Test
public void test13(){
Solar solar = new Solar(2022,1,5);
Lunar lunar = solar.getLunar();
Assert.assertEquals(solar.toString(),"小寒 初候",lunar.getHou());
}

}
Loading

0 comments on commit c91bcc5

Please sign in to comment.