Skip to content

Commit

Permalink
v1.2.14 佛历新增27宿;修复宜忌重复的问题;修复获取气时缺冬至的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
6tail committed Dec 8, 2021
1 parent bab0529 commit e9ec0fc
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 7 deletions.
30 changes: 29 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.13</version>
<version>1.2.14</version>
</dependency>
```

Expand Down Expand Up @@ -54,3 +54,31 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
## 文档

请移步至 [http://6tail.cn/calendar/api.html](http://6tail.cn/calendar/api.html "http://6tail.cn/calendar/api.html")

## 更新日志

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

v1.2.13 新增道历Tao。

v1.2.12 修复星宿方位错误。

v1.2.11 修正胎神数据;增加福神流派。

v1.2.9 新增2022年法定假日。

v1.2.8 新增佛历Foto;更改Lunar中的getOtherFestivals方法为传统节日。

v1.2.7 修复儒略日转阳历秒数为60的错误。

v1.2.6 新增治水、分饼、耕田、得金、日禄;新增时辰LunarTime;新增获取当天的所有时辰。

v1.2.5 修复公元0至4年转阴历错误的问题。

v1.2.4 修复闰冬月、闰腊月的问题;修复日历不准的问题;修复物候错误;大运、小运、流年支持自定义轮数。

v1.2.3 修复除夕错误;代码优化。

v1.2.2 修正2016年国庆节数据;删除5月23日世界读书日;修复v1.2.0和v1.2.1的重大bug。

v1.2.0 支持0001到9999年。
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.13</version>
<version>1.2.14</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
93 changes: 93 additions & 0 deletions src/main/java/com/nlf/calendar/Foto.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,21 @@ public List<FotoFestival> getFestivals() {
return l;
}

/**
* 是否月斋
*
* @return true/false
*/
public boolean isMonthZhai() {
int m = getMonth();
return 1 == m || 5 == m || 9 == m;
}

/**
* 是否杨公忌
*
* @return true/false
*/
public boolean isDayYangGong() {
for (FotoFestival f : getFestivals()) {
if ("杨公忌".equals(f.getName())) {
Expand All @@ -97,11 +107,21 @@ public boolean isDayYangGong() {
return false;
}

/**
* 是否朔望斋
*
* @return true/false
*/
public boolean isDayZhaiShuoWang() {
int d = getDay();
return 1 == d || 15 == d;
}

/**
* 是否六斋日
*
* @return true/false
*/
public boolean isDayZhaiSix() {
int d = getDay();
if (8 == d || 14 == d || 15 == d || 23 == d || 29 == d || 30 == d) {
Expand All @@ -113,11 +133,21 @@ public boolean isDayZhaiSix() {
return false;
}

/**
* 是否十斋日
*
* @return true/false
*/
public boolean isDayZhaiTen() {
int d = getDay();
return 1 == d || 8 == d || 14 == d || 15 == d || 18 == d || 23 == d || 24 == d || 28 == d || 29 == d || 30 == d;
}

/**
* 是否观音斋
*
* @return true/false
*/
public boolean isDayZhaiGuanYin() {
String k = getMonth() + "-" + getDay();
for (String d : FotoUtil.DAY_ZHAI_GUAN_YIN) {
Expand All @@ -128,6 +158,69 @@ public boolean isDayZhaiGuanYin() {
return false;
}

/**
* 获取星宿
*
* @return 星宿
*/
public String getXiu() {
return FotoUtil.getXiu(getMonth(), getDay());
}

/**
* 获取宿吉凶
*
* @return 吉/凶
*/
public String getXiuLuck() {
return LunarUtil.XIU_LUCK.get(getXiu());
}

/**
* 获取宿歌诀
*
* @return 宿歌诀
*/
public String getXiuSong() {
return LunarUtil.XIU_SONG.get(getXiu());
}

/**
* 获取政
*
* @return 政
*/
public String getZheng() {
return LunarUtil.ZHENG.get(getXiu());
}

/**
* 获取动物
*
* @return 动物
*/
public String getAnimal() {
return LunarUtil.ANIMAL.get(getXiu());
}

/**
* 获取宫
*
* @return 宫
*/
public String getGong() {
return LunarUtil.GONG.get(getXiu());
}

/**
* 获取兽
*
* @return 兽
*/
public String getShou() {
return LunarUtil.SHOU.get(getGong());
}

@Override
public String toString() {
return getYearInChinese() + "年" + getMonthInChinese() + "月" + getDayInChinese();
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/nlf/calendar/Lunar.java
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,8 @@ protected String convertJieQi(String name){
*/
public String getJie() {
String jie = "";
for(int i=1,j=JIE_QI.length;i<j;i+=2){
String key = JIE_QI[i];
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()) {
jie = key;
Expand All @@ -860,8 +860,8 @@ public String getJie() {
*/
public String getQi() {
String qi = "";
for(int i=0,j=JIE_QI.length;i<j;i+=2){
String key = JIE_QI[i];
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()) {
qi = key;
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/com/nlf/calendar/util/FotoUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,25 @@ public class FotoUtil {
put("12-30", Collections.nCopies(1, new FotoFestival("诸神下降,察访善恶", "犯者男女俱亡")));
}
};

/**
* 27星宿,佛教从印度传入中国,印度把28星宿改为27星宿,把牛宿(牛金牛)纳入了女宿(女土蝠)。
*/
public static final String[] XIU_27 = {"角", "亢", "氐", "房", "心", "尾", "箕", "斗", "女", "虚", "危", "室", "壁", "奎", "娄", "胃", "昴", "毕", "觜", "参", "井", "鬼", "柳", "星", "张", "翼", "轸"};

/**
* 每月初一的27星宿偏移
*/
private static final int[] XIU_OFFSET = {11, 13, 15, 17, 19, 21, 24, 0, 2, 4, 7, 9};

/**
* 获取27星宿
*
* @param month 佛历月
* @param day 佛历日
* @return 星宿
*/
public static String getXiu(int month, int day) {
return XIU_27[(XIU_OFFSET[Math.abs(month)-1] + day - 1) % XIU_27.length];
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/nlf/calendar/util/LunarUtil.java

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions src/test/java/test/FotoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@ public void test() {
Assert.assertEquals("二五六五年十月十四 (三元降) (四天王巡行)", foto.toFullString());
}

@Test
public void test1() {
Foto foto = Foto.fromLunar(Lunar.fromYmd(2020, 4, 13));
Assert.assertEquals("氐", foto.getXiu());
Assert.assertEquals("土", foto.getZheng());
Assert.assertEquals("貉", foto.getAnimal());
Assert.assertEquals("东", foto.getGong());
Assert.assertEquals("青龙", foto.getShou());
}

}
8 changes: 8 additions & 0 deletions src/test/java/test/JieQiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,12 @@ public void test8() {
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("大雪").toYmdHms());
}

@Test
public void test9() {
Solar solar = Solar.fromYmd(2021, 12, 21);
Assert.assertEquals("冬至", solar.getLunar().getJieQi());
Assert.assertEquals("", solar.getLunar().getJie());
Assert.assertEquals("冬至", solar.getLunar().getQi());
}

}
7 changes: 7 additions & 0 deletions src/test/java/test/LunarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,11 @@ public void test52() {
Assert.assertEquals("厕灶厨 外西南", lunar.getDayPositionTai());
}

@Test
public void test53() {
Solar solar = Solar.fromYmd(2021, 11, 27);
Lunar lunar = solar.getLunar();
Assert.assertEquals("[嫁娶, 祭祀, 祈福, 求嗣, 开光, 出行, 解除, 出火, 拆卸, 进人口, 入宅, 移徙, 安床, 栽种, 动土, 修造, 纳畜, 入殓, 安葬, 立碑, 除服, 成服]", lunar.getDayYi().toString());
}

}

0 comments on commit e9ec0fc

Please sign in to comment.