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

Compare commits

..

10 Commits

24 changed files with 2123 additions and 197 deletions

View File

@@ -1,6 +1,6 @@
# lunar [![License](https://img.shields.io/badge/license-MIT-4EB1BA.svg?style=flat-square)](https://github.com/6tail/lunar-java/blob/master/LICENSE)
lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶、法定节假日及调休等。
lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)、道历、佛历工具,支持星座、儒略日、干支、生肖、节气、节日、彭祖百忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶、法定节假日及调休等。
> 支持java 1.5及以上版本。
@@ -10,35 +10,13 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
[English](https://github.com/6tail/lunar-java/blob/master/README_EN.md)
### 正式版本
### Maven
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.5</version>
</dependency>
```
### 快照版本
```xml
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
```
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.15</version>
</dependency>
```
@@ -76,3 +54,33 @@ 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

@@ -6,35 +6,13 @@ lunar is a calendar library for Solar and Chinese Lunar.
[简体中文](https://github.com/6tail/lunar-java/blob/master/README.md)
### Release
### Maven
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.5</version>
</dependency>
```
### Snapshot
```xml
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</snapshots>
</repository>
```
```xml
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.0-SNAPSHOT</version>
<version>1.2.15</version>
</dependency>
```

View File

@@ -7,7 +7,7 @@
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<packaging>jar</packaging>
<version>1.2.5</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>

View File

@@ -0,0 +1,240 @@
package com.nlf.calendar;
import com.nlf.calendar.util.FotoUtil;
import com.nlf.calendar.util.LunarUtil;
import java.util.ArrayList;
import java.util.List;
/**
* 佛历
*
* @author 6tail
*/
public class Foto {
public static final int DEAD_YEAR = -543;
/**
* 阴历
*/
private Lunar lunar;
public Foto(Lunar lunar) {
this.lunar = lunar;
}
public static Foto fromLunar(Lunar lunar) {
return new Foto(lunar);
}
public static Foto fromYmdHms(int year, int month, int day, int hour, int minute, int second) {
return Foto.fromLunar(Lunar.fromYmdHms(year + DEAD_YEAR - 1, month, day, hour, minute, second));
}
public static Foto fromYmd(int year, int month, int day) {
return fromYmdHms(year, month, day, 0, 0, 0);
}
public Lunar getLunar() {
return lunar;
}
public int getYear() {
int sy = lunar.getSolar().getYear();
int y = sy - DEAD_YEAR;
if (sy == lunar.getYear()) {
y++;
}
return y;
}
public int getMonth() {
return lunar.getMonth();
}
public int getDay() {
return lunar.getDay();
}
public String getYearInChinese() {
String y = getYear() + "";
StringBuilder s = new StringBuilder();
for (int i = 0, j = y.length(); i < j; i++) {
s.append(LunarUtil.NUMBER[y.charAt(i) - '0']);
}
return s.toString();
}
public String getMonthInChinese() {
return lunar.getMonthInChinese();
}
public String getDayInChinese() {
return lunar.getDayInChinese();
}
public List<FotoFestival> getFestivals() {
List<FotoFestival> l = new ArrayList<FotoFestival>();
List<FotoFestival> fs = FotoUtil.FESTIVAL.get(getMonth() + "-" + getDay());
if (null != fs) {
l.addAll(fs);
}
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())) {
return true;
}
}
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) {
return true;
} else if (28 == d) {
LunarMonth m = LunarMonth.fromYm(lunar.getYear(), getMonth());
return null != m && 30 != m.getDayCount();
}
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) {
if (k.equals(d)) {
return true;
}
}
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();
}
public String toFullString() {
StringBuilder s = new StringBuilder();
s.append(toString());
for (FotoFestival f : getFestivals()) {
s.append(" (");
s.append(f);
s.append(")");
}
return s.toString();
}
}

View File

@@ -0,0 +1,83 @@
package com.nlf.calendar;
/**
* 佛历因果犯忌
*
* @author 6tail
*/
public class FotoFestival {
/**
* 是日何日,如:雷斋日
*/
private String name;
/**
* 犯之因果,如:犯者夺纪
*/
private String result;
/**
* 是否每月同
*/
private boolean everyMonth;
/**
* 备注,如:宜先一日即戒
*/
private String remark;
public FotoFestival(String name, String result, boolean everyMonth, String remark) {
this.name = name;
this.result = null == result ? "" : result;
this.everyMonth = everyMonth;
this.remark = null == remark ? "" : remark;
}
public FotoFestival(String name) {
this(name, null);
}
public FotoFestival(String name, String result) {
this(name, result, false);
}
public FotoFestival(String name, String result, boolean everyMonth) {
this(name, result, everyMonth, null);
}
public String getName() {
return name;
}
public String getResult() {
return result;
}
public boolean isEveryMonth() {
return everyMonth;
}
public String getRemark() {
return remark;
}
@Override
public String toString() {
return name;
}
public String toFullString() {
StringBuilder s = new StringBuilder();
s.append(name);
if (null != result && result.length() > 0) {
s.append(" ");
s.append(result);
}
if (null != remark && remark.length() > 0) {
s.append(" ");
s.append(remark);
}
return s.toString();
}
}

View File

@@ -753,7 +753,7 @@ public class Lunar {
* @return 中文年,如二零零一
*/
public String getYearInChinese() {
String y = (year + "");
String y = year + "";
StringBuilder s = new StringBuilder();
for (int i = 0, j = y.length(); i < j; i++) {
s.append(LunarUtil.NUMBER[y.charAt(i) - '0']);
@@ -842,8 +842,8 @@ public class Lunar {
*/
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;
@@ -860,8 +860,8 @@ public class Lunar {
*/
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;
@@ -980,6 +980,9 @@ public class Lunar {
if (null != fs) {
l.addAll(fs);
}
if(solar.toYmd().equals(jieQi.get("清明").next(-1).toYmd())) {
l.add("寒食节");
}
return l;
}
@@ -1156,21 +1159,41 @@ public class Lunar {
}
/**
* 获取日福神方位
* 获取日福神方位(默认流派:2)
*
* @return 福神方位,如艮
*/
public String getDayPositionFu() {
return LunarUtil.POSITION_FU[dayGanIndex + 1];
return getDayPositionFu(2);
}
/**
* 获取日福神方位
*
* @param sect 流派,1或2
* @return 福神方位,如艮
*/
public String getDayPositionFu(int sect) {
return (1==sect?LunarUtil.POSITION_FU:LunarUtil.POSITION_FU_2)[dayGanIndex + 1];
}
/**
* 获取日福神方位描述(默认流派:2)
*
* @return 福神方位描述,如东北
*/
public String getDayPositionFuDesc() {
return getDayPositionFuDesc(2);
}
/**
* 获取日福神方位描述
*
* @param sect 流派,1或2
* @return 福神方位描述,如东北
*/
public String getDayPositionFuDesc() {
return LunarUtil.POSITION_DESC.get(getDayPositionFu());
public String getDayPositionFuDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getDayPositionFu(sect));
}
/**
@@ -1246,21 +1269,41 @@ public class Lunar {
}
/**
* 获取时辰福神方位
* 获取时辰福神方位,默认流派2
*
* @return 福神方位,如艮
*/
public String getTimePositionFu() {
return LunarUtil.POSITION_FU[timeGanIndex + 1];
return getTimePositionFu(2);
}
/**
* 获取时辰福神方位
*
* @param sect 流派,1或2
* @return 福神方位,如艮
*/
public String getTimePositionFu(int sect) {
return (1==sect?LunarUtil.POSITION_FU:LunarUtil.POSITION_FU_2)[timeGanIndex + 1];
}
/**
* 获取时辰福神方位描述,默认流派2
*
* @return 福神方位描述,如东北
*/
public String getTimePositionFuDesc() {
return getTimePositionFuDesc(2);
}
/**
* 获取时辰福神方位描述
*
* @param sect 流派,1或2
* @return 福神方位描述,如东北
*/
public String getTimePositionFuDesc() {
return LunarUtil.POSITION_DESC.get(getTimePositionFu());
public String getTimePositionFuDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getTimePositionFu(sect));
}
/**
@@ -1589,11 +1632,7 @@ public class Lunar {
* @return 逐日胎神方位
*/
public String getDayPositionTai() {
int offset = dayGanIndex - dayZhiIndex;
if (offset < 0) {
offset += 12;
}
return LunarUtil.POSITION_TAI_DAY[offset * 5 + dayGanIndex];
return LunarUtil.POSITION_TAI_DAY[LunarUtil.getJiaZiIndex(getDayInGanZhi())];
}
/**
@@ -1915,12 +1954,22 @@ public class Lunar {
* @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);
}
/**
@@ -1929,12 +1978,22 @@ public class Lunar {
* @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);
}
/**
@@ -1943,12 +2002,22 @@ public class Lunar {
* @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);
}
/**
@@ -1957,12 +2026,22 @@ public class Lunar {
* @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);
}
/**
@@ -1971,7 +2050,17 @@ public class Lunar {
* @return 节气
*/
public JieQi getNextJieQi() {
return getNearJieQi(true, null);
return getNextJieQi(false);
}
/**
* 获取下一节气(顺推的第一个节气)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getNextJieQi(boolean wholeDay) {
return getNearJieQi(true, null, wholeDay);
}
/**
@@ -1980,7 +2069,17 @@ public class Lunar {
* @return 节气
*/
public JieQi getPrevJieQi() {
return getNearJieQi(false, null);
return getPrevJieQi(false);
}
/**
* 获取上一节气(逆推的第一个节气)
*
* @param wholeDay 是否按天计
* @return 节气
*/
public JieQi getPrevJieQi(boolean wholeDay) {
return getNearJieQi(false, null, wholeDay);
}
/**
@@ -1988,9 +2087,10 @@ public class Lunar {
*
* @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>();
@@ -1998,7 +2098,7 @@ public class Lunar {
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) {
@@ -2007,22 +2107,34 @@ public class Lunar {
}
}
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;
}
}
}
}
@@ -2587,7 +2699,7 @@ public class Lunar {
*/
@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++) {
@@ -2604,4 +2716,75 @@ public class Lunar {
int days = (int) ((currentCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / MS_PER_DAY);
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 日禄
*/
public String getDayLu() {
String gan = LunarUtil.LU.get(getDayGan());
String zhi = LunarUtil.LU.get(getDayZhi());
String lu = gan + "命互禄";
if (null != zhi) {
lu += " " + zhi + "命进禄";
}
return lu;
}
/**
* 获取时辰
*
* @return 时辰
*/
public LunarTime getTime() {
return new LunarTime(year, month, day, hour, minute, second);
}
/**
* 获取当天的时辰列表
*
* @return 时辰列表
*/
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));
}
return l;
}
/**
* 获取佛历
*
* @return 佛历
*/
public Foto getFoto() {
return Foto.fromLunar(this);
}
/**
* 获取道历
*
* @return 佛历
*/
public Tao getTao() {
return Tao.fromLunar(this);
}
}

View File

@@ -0,0 +1,393 @@
package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
import java.util.List;
import java.util.Map;
/**
* 时辰
*
* @author 6tail
*/
public class LunarTime {
/**
* 天干下标,0-9
*/
private int ganIndex;
/**
* 地支下标,0-11
*/
private int zhiIndex;
/**
* 阴历
*/
private Lunar lunar;
public LunarTime(int lunarYear, int lunarMonth, int lunarDay, int hour, int minute, int second) {
this.lunar = Lunar.fromYmdHms(lunarYear, lunarMonth, lunarDay, hour, minute, second);
this.zhiIndex = LunarUtil.getTimeZhiIndex(String.format("%02d:%02d", hour, minute));
this.ganIndex = (lunar.getDayGanIndexExact() % 5 * 2 + zhiIndex) % 10;
}
public static LunarTime fromYmdHms(int lunarYear, int lunarMonth, int lunarDay, int hour, int minute, int second) {
return new LunarTime(lunarYear, lunarMonth, lunarDay, hour, minute, second);
}
public int getGanIndex() {
return ganIndex;
}
public int getZhiIndex() {
return zhiIndex;
}
/**
* 获取生肖
*
* @return 生肖,如虎
*/
public String getShengXiao() {
return LunarUtil.SHENGXIAO[zhiIndex + 1];
}
/**
* 获取地支
*
* @return 地支
*/
public String getZhi() {
return LunarUtil.ZHI[zhiIndex + 1];
}
/**
* 获取天干
*
* @return 天干
*/
public String getGan() {
return LunarUtil.GAN[ganIndex + 1];
}
/**
* 获取干支(时柱)
*
* @return 干支(时柱)
*/
public String getGanZhi() {
return getGan() + getZhi();
}
/**
* 获取喜神方位
*
* @return 喜神方位,如艮
*/
public String getPositionXi() {
return LunarUtil.POSITION_XI[ganIndex + 1];
}
/**
* 获取喜神方位描述
*
* @return 喜神方位描述,如东北
*/
public String getPositionXiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionXi());
}
/**
* 获取阳贵神方位
*
* @return 阳贵神方位,如艮
*/
public String getPositionYangGui() {
return LunarUtil.POSITION_YANG_GUI[ganIndex + 1];
}
/**
* 获取阳贵神方位描述
*
* @return 阳贵神方位描述,如东北
*/
public String getPositionYangGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYangGui());
}
/**
* 获取阴贵神方位
*
* @return 阴贵神方位,如艮
*/
public String getPositionYinGui() {
return LunarUtil.POSITION_YIN_GUI[ganIndex + 1];
}
/**
* 获取阴贵神方位描述
*
* @return 阴贵神方位描述,如东北
*/
public String getPositionYinGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYinGui());
}
/**
* 获取福神方位(默认流派:2)
*
* @return 福神方位,如艮
*/
public String getPositionFu() {
return getPositionFu(2);
}
/**
* 获取福神方位
*
* @param sect 流派,1或2
* @return 福神方位,如艮
*/
public String getPositionFu(int sect) {
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[ganIndex + 1];
}
/**
* 获取福神方位描述(默认流派:2)
*
* @return 福神方位描述,如东北
*/
public String getPositionFuDesc() {
return getPositionFuDesc(2);
}
/**
* 获取福神方位描述
*
* @param sect 流派,1或2
* @return 福神方位描述,如东北
*/
public String getPositionFuDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getPositionFu(sect));
}
/**
* 获取财神方位
*
* @return 财神方位,如艮
*/
public String getPositionCai() {
return LunarUtil.POSITION_CAI[ganIndex + 1];
}
/**
* 获取财神方位描述
*
* @return 财神方位描述,如东北
*/
public String getPositionCaiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionCai());
}
/**
* 获取纳音
*
* @return 纳音,如剑锋金
*/
public String getNaYin() {
return LunarUtil.NAYIN.get(getGanZhi());
}
/**
* 获取值时天神
*
* @return 值时天神
*/
public String getTianShen() {
String dayZhi = lunar.getDayZhiExact();
int offset = LunarUtil.ZHI_TIAN_SHEN_OFFSET.get(dayZhi);
return LunarUtil.TIAN_SHEN[(zhiIndex + offset) % 12 + 1];
}
/**
* 获取值时天神类型:黄道/黑道
*
* @return 值时天神类型:黄道/黑道
*/
public String getTianShenType() {
return LunarUtil.TIAN_SHEN_TYPE.get(getTianShen());
}
/**
* 获取值时天神吉凶
*
* @return 吉/凶
*/
public String getTianShenLuck() {
return LunarUtil.TIAN_SHEN_TYPE_LUCK.get(getTianShenType());
}
/**
* 获取时冲
*
* @return 时冲,如申
*/
public String getChong() {
return LunarUtil.CHONG[zhiIndex + 1];
}
/**
* 获取时煞
*
* @return 时煞,如北
*/
public String getSha() {
return LunarUtil.SHA.get(getZhi());
}
/**
* 获取时冲生肖
*
* @return 时冲生肖,如猴
*/
public String getChongShengXiao() {
String chong = getChong();
for (int i = 0, j = LunarUtil.ZHI.length; i < j; i++) {
if (LunarUtil.ZHI[i].equals(chong)) {
return LunarUtil.SHENGXIAO[i];
}
}
return "";
}
/**
* 获取时冲描述
*
* @return 时冲描述,如(壬申)猴
*/
public String getChongDesc() {
return "(" + getChongGan() + getChong() + ")" + getChongShengXiao();
}
/**
* 获取无情之克的时冲天干
*
* @return 无情之克的时冲天干,如甲
*/
public String getChongGan() {
return LunarUtil.CHONG_GAN[ganIndex + 1];
}
/**
* 获取有情之克的时冲天干
*
* @return 有情之克的时冲天干,如甲
*/
public String getChongGanTie() {
return LunarUtil.CHONG_GAN_TIE[ganIndex + 1];
}
/**
* 获取宜,如果没有,返回["无"]
*
* @return 宜
*/
public List<String> getYi() {
return LunarUtil.getTimeYi(lunar.getDayInGanZhiExact(), getGanZhi());
}
/**
* 获取忌,如果没有,返回["无"]
*
* @return 忌
*/
public List<String> getJi() {
return LunarUtil.getTimeJi(lunar.getDayInGanZhiExact(), getGanZhi());
}
/**
* 获取值时九星(时家紫白星歌诀:三元时白最为佳,冬至阳生顺莫差,孟日七宫仲一白,季日四绿发萌芽,每把时辰起甲子,本时星耀照光华,时星移入中宫去,顺飞八方逐细查。夏至阴生逆回首,孟归三碧季加六,仲在九宫时起甲,依然掌中逆轮跨。)
*
* @return 值时九星
*/
public NineStar getNineStar() {
//顺逆
String solarYmd = lunar.getSolar().toYmd();
Map<String, Solar> jieQi = lunar.getJieQiTable();
boolean asc = false;
if (solarYmd.compareTo(jieQi.get("冬至").toYmd()) >= 0 && solarYmd.compareTo(jieQi.get("夏至").toYmd()) < 0) {
asc = true;
}
int start = asc ? 7 : 3;
String dayZhi = lunar.getDayZhi();
if ("子午卯酉".contains(dayZhi)) {
start = asc ? 1 : 9;
} else if ("辰戌丑未".contains(dayZhi)) {
start = asc ? 4 : 6;
}
int index = asc ? start + zhiIndex - 1 : start - zhiIndex - 1;
if (index > 8) {
index -= 9;
}
if (index < 0) {
index += 9;
}
return new NineStar(index);
}
/**
* 获取所在旬
*
* @return 旬
*/
public String getXun() {
return LunarUtil.getXun(getGanZhi());
}
/**
* 获取值时空亡
*
* @return 空亡(旬空)
*/
public String getXunKong() {
return LunarUtil.getXunKong(getGanZhi());
}
/**
* 获取当前时辰的最早时分
*
* @return 时分,如:21:00
*/
public String getMinHm() {
int hour = lunar.getHour();
if (hour < 1) {
return "00:00";
} else if (hour > 22) {
return "23:00";
}
return String.format("%02d:00", hour % 2 == 0 ? hour - 1 : hour);
}
/**
* 获取当前时辰的最晚时分
*
* @return 时分,如:22:59
*/
public String getMaxHm() {
int hour = lunar.getHour();
if (hour < 1) {
return "00:59";
} else if (hour > 22) {
return "23:59";
}
return String.format("%02d:59", hour % 2 == 0 ? hour : hour + 1);
}
@Override
public String toString() {
return getGanZhi();
}
}

View File

@@ -1,5 +1,6 @@
package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
import com.nlf.calendar.util.ShouXingUtil;
import java.util.ArrayList;
@@ -14,6 +15,16 @@ import java.util.Map;
*/
public class LunarYear {
/**
* 元
*/
private static final String[] YUAN = {"下", "上", "中"};
/**
* 运
*/
private static final String[] YUN = {"七", "八", "九", "一", "二", "三", "四", "五", "六"};
/**
* 闰冬月年份
*/
@@ -211,6 +222,76 @@ public class LunarYear {
return 0;
}
/**
* 获取治水(正月第一个辰日是初几,就是几龙治水)
*
* @return 治水,如:二龙治水
*/
public String getZhiShui() {
int offset = 4 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
if (offset < 0) {
offset += 12;
}
return LunarUtil.NUMBER[offset+1] + "龙治水";
}
/**
* 获取分饼(正月第一个丙日是初几,就是几人分饼)
*
* @return 分饼,如:六人分饼
*/
public String getFenBing() {
int offset = 2 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
if (offset < 0) {
offset += 10;
}
return LunarUtil.NUMBER[offset+1] + "人分饼";
}
/**
* 获取耕田(正月第一个丑日是初几,就是几牛耕田)
*
* @return 耕田,如:六牛耕田
*/
public String getGengTian() {
int offset = 1 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayZhiIndex();
if (offset < 0) {
offset += 12;
}
return LunarUtil.NUMBER[offset+1] + "牛耕田";
}
/**
* 获取得金(正月第一个辛日是初几,就是几日得金)
*
* @return 得金,如:一日得金
*/
public String getDeJin() {
int offset = 7 - Solar.fromJulianDay(getMonth(1).getFirstJulianDay()).getLunar().getDayGanIndex();
if (offset < 0) {
offset += 10;
}
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 + "";

View File

@@ -156,6 +156,14 @@ public class Solar {
f -= minute;
f *= 60;
int second = (int) Math.round(f);
if (second > 59) {
second -= 60;
minute++;
}
if (minute > 59) {
minute -= 60;
hour++;
}
calendar = ExactDate.fromYmdHms(year, month, day, hour, minute, second);
this.year = year;

View File

@@ -0,0 +1,188 @@
package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
import com.nlf.calendar.util.TaoUtil;
import java.util.ArrayList;
import java.util.List;
/**
* 道历
*
* @author 6tail
*/
public class Tao {
public static final int BIRTH_YEAR = -2697;
/**
* 阴历
*/
private Lunar lunar;
public Tao(Lunar lunar) {
this.lunar = lunar;
}
public static Tao fromLunar(Lunar lunar) {
return new Tao(lunar);
}
public static Tao fromYmdHms(int year, int month, int day, int hour, int minute, int second) {
return Tao.fromLunar(Lunar.fromYmdHms(year + BIRTH_YEAR, month, day, hour, minute, second));
}
public static Tao fromYmd(int year, int month, int day) {
return fromYmdHms(year, month, day, 0, 0, 0);
}
public Lunar getLunar() {
return lunar;
}
public int getYear() {
return lunar.getYear() - BIRTH_YEAR;
}
public int getMonth() {
return lunar.getMonth();
}
public int getDay() {
return lunar.getDay();
}
public String getYearInChinese() {
String y = getYear() + "";
StringBuilder s = new StringBuilder();
for (int i = 0, j = y.length(); i < j; i++) {
s.append(LunarUtil.NUMBER[y.charAt(i) - '0']);
}
return s.toString();
}
public String getMonthInChinese() {
return lunar.getMonthInChinese();
}
public String getDayInChinese() {
return lunar.getDayInChinese();
}
public List<TaoFestival> getFestivals() {
List<TaoFestival> l = new ArrayList<TaoFestival>();
List<TaoFestival> fs = TaoUtil.FESTIVAL.get(getMonth() + "-" + getDay());
if (null != fs) {
l.addAll(fs);
}
String jq = lunar.getJieQi();
if ("冬至".equals(jq)) {
l.add(new TaoFestival("元始天尊圣诞"));
} else if ("夏至".equals(jq)) {
l.add(new TaoFestival("灵宝天尊圣诞"));
}
// 八节日
String f = TaoUtil.BA_JIE.get(jq);
if (null != f) {
l.add(new TaoFestival(f));
}
// 八会日
f = TaoUtil.BA_HUI.get(lunar.getDayInGanZhi());
if (null != f) {
l.add(new TaoFestival(f));
}
return l;
}
private boolean isDayIn(String[] days) {
String md = getMonth() + "-" + getDay();
for (String d : days) {
if (md.equals(d)) {
return true;
}
}
return false;
}
/**
* 是否三会日
*
* @return true/false
*/
public boolean isDaySanHui() {
return isDayIn(TaoUtil.SAN_HUI);
}
/**
* 是否三元日
*
* @return true/false
*/
public boolean isDaySanYuan() {
return isDayIn(TaoUtil.SAN_YUAN);
}
/**
* 是否八节日
*
* @return true/false
*/
public boolean isDayBaJie() {
return TaoUtil.BA_JIE.containsKey(lunar.getJieQi());
}
/**
* 是否五腊日
*
* @return true/false
*/
public boolean isDayWuLa() {
return isDayIn(TaoUtil.WU_LA);
}
/**
* 是否八会日
*
* @return true/false
*/
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());
}
public String toFullString() {
return String.format("道歷%s年,天運%s年,%s月,%s日。%s月%s日,%s時。", getYearInChinese(), lunar.getYearInGanZhi(), lunar.getMonthInGanZhi(), lunar.getDayInGanZhi(), getMonthInChinese(), getDayInChinese(), lunar.getTimeZhi());
}
}

View File

@@ -0,0 +1,52 @@
package com.nlf.calendar;
/**
* 道历节日
*
* @author 6tail
*/
public class TaoFestival {
/**
* 名称
*/
private String name;
/**
* 备注
*/
private String remark;
public TaoFestival(String name, String remark) {
this.name = name;
this.remark = null == remark ? "" : remark;
}
public TaoFestival(String name) {
this(name, null);
}
public String getName() {
return name;
}
public String getRemark() {
return remark;
}
@Override
public String toString() {
return name;
}
public String toFullString() {
StringBuilder s = new StringBuilder();
s.append(name);
if (null != remark && remark.length() > 0) {
s.append("[");
s.append(remark);
s.append("]");
}
return s.toString();
}
}

View File

@@ -0,0 +1,285 @@
package com.nlf.calendar.util;
import com.nlf.calendar.FotoFestival;
import java.util.*;
/**
* 佛历工具
*
* @author 6tail
*/
public class FotoUtil {
/**
* 观音斋日期
*/
public static final String[] DAY_ZHAI_GUAN_YIN = {"1-8", "2-7", "2-9", "2-19", "3-3", "3-6", "3-13", "4-22", "5-3", "5-17", "6-16", "6-18", "6-19", "6-23", "7-13", "8-16", "9-19", "9-23", "10-2", "11-19", "11-24", "12-25"};
private static final String DJ = "犯者夺纪";
private static final String JS = "犯者减寿";
private static final String SS = "犯者损寿";
private static final String XL = "犯者削禄夺纪";
private static final String JW = "犯者三年内夫妇俱亡";
private static final FotoFestival Y = new FotoFestival("杨公忌");
private static final FotoFestival T = new FotoFestival("四天王巡行", "", true);
private static final FotoFestival D = new FotoFestival("斗降", DJ, true);
private static final FotoFestival S = new FotoFestival("月朔", DJ, true);
private static final FotoFestival W = new FotoFestival("月望", DJ, true);
private static final FotoFestival H = new FotoFestival("月晦", JS, true);
private static final FotoFestival L = new FotoFestival("雷斋日", JS, true);
private static final FotoFestival J = new FotoFestival("九毒日", "犯者夭亡,奇祸不测");
private static final FotoFestival R = new FotoFestival("人神在阴", "犯者得病", true, "宜先一日即戒");
private static final FotoFestival M = new FotoFestival("司命奏事", JS, true, "如月小,即戒廿九");
private static final FotoFestival HH = new FotoFestival("月晦", JS, true, "如月小,即戒廿九");
/**
* 因果犯忌
*/
public static final Map<String, List<FotoFestival>> FESTIVAL = new HashMap<String, List<FotoFestival>>() {
private static final long serialVersionUID = 1L;
{
put("1-1", Arrays.asList(new FotoFestival("天腊,玉帝校世人神气禄命", XL), S));
put("1-3", Arrays.asList(new FotoFestival("万神都会", DJ), D));
put("1-5", Collections.nCopies(1, new FotoFestival("五虚忌")));
put("1-6", Arrays.asList(new FotoFestival("六耗忌"), L));
put("1-7", Collections.nCopies(1, new FotoFestival("上会日", SS)));
put("1-8", Arrays.asList(new FotoFestival("五殿阎罗天子诞", DJ), T));
put("1-9", Collections.nCopies(1, new FotoFestival("玉皇上帝诞", DJ)));
put("1-13", Collections.nCopies(1, Y));
put("1-14", Arrays.asList(new FotoFestival("三元降", JS), T));
put("1-15", Arrays.asList(new FotoFestival("三元降", JS), new FotoFestival("上元神会", DJ), W, T));
put("1-16", Collections.nCopies(1, new FotoFestival("三元降", JS)));
put("1-19", Collections.nCopies(1, new FotoFestival("长春真人诞")));
put("1-23", Arrays.asList(new FotoFestival("三尸神奏事"), T));
put("1-25", Arrays.asList(H, new FotoFestival("天地仓开日", "犯者损寿,子带疾")));
put("1-27", Collections.nCopies(1, D));
put("1-28", Collections.nCopies(1, R));
put("1-29", Collections.nCopies(1, T));
put("1-30", Arrays.asList(HH, M, T));
put("2-1", Arrays.asList(new FotoFestival("一殿秦广王诞", DJ), S));
put("2-2", Arrays.asList(new FotoFestival("万神都会", DJ), new FotoFestival("福德土地正神诞", "犯者得祸")));
put("2-3", Arrays.asList(new FotoFestival("文昌帝君诞", XL), D));
put("2-6", Arrays.asList(new FotoFestival("东华帝君诞"), L));
put("2-8", Arrays.asList(new FotoFestival("释迦牟尼佛出家", DJ), new FotoFestival("三殿宋帝王诞", DJ), new FotoFestival("张大帝诞", DJ), T));
put("2-11", Collections.nCopies(1, Y));
put("2-14", Collections.nCopies(1, T));
put("2-15", Arrays.asList(new FotoFestival("释迦牟尼佛涅槃", XL), new FotoFestival("太上老君诞", XL), new FotoFestival("月望", XL, true), T));
put("2-17", Collections.nCopies(1, new FotoFestival("东方杜将军诞")));
put("2-18", Arrays.asList(new FotoFestival("四殿五官王诞", XL), new FotoFestival("至圣先师孔子讳辰", XL)));
put("2-19", Collections.nCopies(1, new FotoFestival("观音大士诞", DJ)));
put("2-21", Collections.nCopies(1, new FotoFestival("普贤菩萨诞")));
put("2-23", Collections.nCopies(1, T));
put("2-25", Collections.nCopies(1, H));
put("2-27", Collections.nCopies(1, D));
put("2-28", Collections.nCopies(1, R));
put("2-29", Collections.nCopies(1, T));
put("2-30", Arrays.asList(HH, M, T));
put("3-1", Arrays.asList(new FotoFestival("二殿楚江王诞", DJ), S));
put("3-3", Arrays.asList(new FotoFestival("玄天上帝诞", DJ), D));
put("3-6", Collections.nCopies(1, L));
put("3-8", Arrays.asList(new FotoFestival("六殿卞城王诞", DJ), T));
put("3-9", Arrays.asList(new FotoFestival("牛鬼神出", "犯者产恶胎"), Y));
put("3-12", Collections.nCopies(1, new FotoFestival("中央五道诞")));
put("3-14", Collections.nCopies(1, T));
put("3-15", Arrays.asList(new FotoFestival("昊天上帝诞", DJ), new FotoFestival("玄坛诞", DJ), W, T));
put("3-16", Collections.nCopies(1, new FotoFestival("准提菩萨诞", DJ)));
put("3-19", Arrays.asList(new FotoFestival("中岳大帝诞"), new FotoFestival("后土娘娘诞"), new FotoFestival("三茅降")));
put("3-20", Arrays.asList(new FotoFestival("天地仓开日", SS), new FotoFestival("子孙娘娘诞")));
put("3-23", Collections.nCopies(1, T));
put("3-25", Collections.nCopies(1, H));
put("3-27", Arrays.asList(new FotoFestival("七殿泰山王诞"), D));
put("3-28", Arrays.asList(R, new FotoFestival("苍颉至圣先师诞", XL), new FotoFestival("东岳大帝诞")));
put("3-29", Collections.nCopies(1, T));
put("3-30", Arrays.asList(HH, M, T));
put("4-1", Arrays.asList(new FotoFestival("八殿都市王诞", DJ), S));
put("4-3", Collections.nCopies(1, D));
put("4-4", Arrays.asList(new FotoFestival("万神善会", "犯者失瘼夭胎"), new FotoFestival("文殊菩萨诞")));
put("4-6", Collections.nCopies(1, L));
put("4-7", Arrays.asList(new FotoFestival("南斗、北斗、西斗同降", JS), Y));
put("4-8", Arrays.asList(new FotoFestival("释迦牟尼佛诞", DJ), new FotoFestival("万神善会", "犯者失瘼夭胎"), new FotoFestival("善恶童子降", "犯者血死"), new FotoFestival("九殿平等王诞"), T));
put("4-14", Arrays.asList(new FotoFestival("纯阳祖师诞", JS), T));
put("4-15", Arrays.asList(W, new FotoFestival("钟离祖师诞"), T));
put("4-16", Collections.nCopies(1, new FotoFestival("天地仓开日", SS)));
put("4-17", Collections.nCopies(1, new FotoFestival("十殿转轮王诞", DJ)));
put("4-18", Arrays.asList(new FotoFestival("天地仓开日", SS), new FotoFestival("紫徽大帝诞", SS)));
put("4-20", Collections.nCopies(1, new FotoFestival("眼光圣母诞")));
put("4-23", Collections.nCopies(1, T));
put("4-25", Collections.nCopies(1, H));
put("4-27", Collections.nCopies(1, D));
put("4-28", Collections.nCopies(1, R));
put("4-29", Collections.nCopies(1, T));
put("4-30", Arrays.asList(HH, M, T));
put("5-1", Arrays.asList(new FotoFestival("南极长生大帝诞", DJ), S));
put("5-3", Collections.nCopies(1, D));
put("5-5", Arrays.asList(new FotoFestival("地腊", XL), new FotoFestival("五帝校定生人官爵", XL), J, Y));
put("5-6", Arrays.asList(J, L));
put("5-7", Collections.nCopies(1, J));
put("5-8", Arrays.asList(new FotoFestival("南方五道诞"), T));
put("5-11", Arrays.asList(new FotoFestival("天地仓开日", SS), new FotoFestival("天下都城隍诞")));
put("5-12", Collections.nCopies(1, new FotoFestival("炳灵公诞")));
put("5-13", Collections.nCopies(1, new FotoFestival("关圣降", XL)));
put("5-14", Arrays.asList(new FotoFestival("夜子时为天地交泰", JW), T));
put("5-15", Arrays.asList(W, J, T));
put("5-16", Arrays.asList(new FotoFestival("九毒日", JW), new FotoFestival("天地元气造化万物之辰", JW)));
put("5-17", Collections.nCopies(1, J));
put("5-18", Collections.nCopies(1, new FotoFestival("张天师诞")));
put("5-22", Collections.nCopies(1, new FotoFestival("孝娥神诞", DJ)));
put("5-23", Collections.nCopies(1, T));
put("5-25", Arrays.asList(J, H));
put("5-26", Collections.nCopies(1, J));
put("5-27", Arrays.asList(J, D));
put("5-28", Collections.nCopies(1, R));
put("5-29", Collections.nCopies(1, T));
put("5-30", Arrays.asList(HH, M, T));
put("6-1", Collections.nCopies(1, S));
put("6-3", Arrays.asList(new FotoFestival("韦驮菩萨圣诞"), D, Y));
put("6-5", Collections.nCopies(1, new FotoFestival("南赡部洲转大轮", SS)));
put("6-6", Arrays.asList(new FotoFestival("天地仓开日", SS), L));
put("6-8", Collections.nCopies(1, T));
put("6-10", Collections.nCopies(1, new FotoFestival("金粟如来诞")));
put("6-14", Collections.nCopies(1, T));
put("6-15", Arrays.asList(W, T));
put("6-19", Collections.nCopies(1, new FotoFestival("观世音菩萨成道", DJ)));
put("6-23", Arrays.asList(new FotoFestival("南方火神诞", "犯者遭回禄"), T));
put("6-24", Arrays.asList(new FotoFestival("雷祖诞", XL), new FotoFestival("关帝诞", XL)));
put("6-25", Collections.nCopies(1, H));
put("6-27", Collections.nCopies(1, D));
put("6-28", Collections.nCopies(1, R));
put("6-29", Collections.nCopies(1, T));
put("6-30", Arrays.asList(HH, M, T));
put("7-1", Arrays.asList(S, Y));
put("7-3", Collections.nCopies(1, D));
put("7-5", Collections.nCopies(1, new FotoFestival("中会日", SS, false, "一作初七")));
put("7-6", Collections.nCopies(1, L));
put("7-7", Arrays.asList(new FotoFestival("道德腊", XL), new FotoFestival("五帝校生人善恶", XL), new FotoFestival("魁星诞", XL)));
put("7-8", Collections.nCopies(1, T));
put("7-10", Collections.nCopies(1, new FotoFestival("阴毒日", "", false, "大忌")));
put("7-12", Collections.nCopies(1, new FotoFestival("长真谭真人诞")));
put("7-13", Collections.nCopies(1, new FotoFestival("大势至菩萨诞", JS)));
put("7-14", Arrays.asList(new FotoFestival("三元降", JS), T));
put("7-15", Arrays.asList(W, new FotoFestival("三元降", DJ), new FotoFestival("地官校籍", DJ), T));
put("7-16", Collections.nCopies(1, new FotoFestival("三元降", JS)));
put("7-18", Collections.nCopies(1, new FotoFestival("西王母诞", DJ)));
put("7-19", Collections.nCopies(1, new FotoFestival("太岁诞", DJ)));
put("7-22", Collections.nCopies(1, new FotoFestival("增福财神诞", XL)));
put("7-23", Collections.nCopies(1, T));
put("7-25", Collections.nCopies(1, H));
put("7-27", Collections.nCopies(1, D));
put("7-28", Collections.nCopies(1, R));
put("7-29", Arrays.asList(Y, T));
put("7-30", Arrays.asList(new FotoFestival("地藏菩萨诞", DJ), HH, M, T));
put("8-1", Arrays.asList(S, new FotoFestival("许真君诞")));
put("8-3", Arrays.asList(D, new FotoFestival("北斗诞", XL), new FotoFestival("司命灶君诞", "犯者遭回禄")));
put("8-5", Collections.nCopies(1, new FotoFestival("雷声大帝诞", DJ)));
put("8-6", Collections.nCopies(1, L));
put("8-8", Collections.nCopies(1, T));
put("8-10", Collections.nCopies(1, new FotoFestival("北斗大帝诞")));
put("8-12", Collections.nCopies(1, new FotoFestival("西方五道诞")));
put("8-14", Collections.nCopies(1, T));
put("8-15", Arrays.asList(W, new FotoFestival("太明朝元", "犯者暴亡", false, "宜焚香守夜"), T));
put("8-16", Collections.nCopies(1, new FotoFestival("天曹掠刷真君降", "犯者贫夭")));
put("8-18", Collections.nCopies(1, new FotoFestival("天人兴福之辰", "", false, "宜斋戒,存想吉事")));
put("8-23", Arrays.asList(new FotoFestival("汉恒候张显王诞"), T));
put("8-24", Collections.nCopies(1, new FotoFestival("灶君夫人诞")));
put("8-25", Collections.nCopies(1, H));
put("8-27", Arrays.asList(D, new FotoFestival("至圣先师孔子诞", XL), Y));
put("8-28", Arrays.asList(R, new FotoFestival("四天会事")));
put("8-29", Collections.nCopies(1, T));
put("8-30", Arrays.asList(new FotoFestival("诸神考校", "犯者夺算"), HH, M, T));
put("9-1", Arrays.asList(S, new FotoFestival("南斗诞", XL), new FotoFestival("北斗九星降世", DJ, false, "此九日俱宜斋戒")));
put("9-3", Arrays.asList(D, new FotoFestival("五瘟神诞")));
put("9-6", Collections.nCopies(1, L));
put("9-8", Collections.nCopies(1, T));
put("9-9", Arrays.asList(new FotoFestival("斗母诞", XL), new FotoFestival("酆都大帝诞"), new FotoFestival("玄天上帝飞升")));
put("9-10", Collections.nCopies(1, new FotoFestival("斗母降", DJ)));
put("9-11", Collections.nCopies(1, new FotoFestival("宜戒")));
put("9-13", Collections.nCopies(1, new FotoFestival("孟婆尊神诞")));
put("9-14", Collections.nCopies(1, T));
put("9-15", Arrays.asList(W, T));
put("9-17", Collections.nCopies(1, new FotoFestival("金龙四大王诞", "犯者遭水厄")));
put("9-19", Arrays.asList(new FotoFestival("日宫月宫会合", JS), new FotoFestival("观世音菩萨诞", JS)));
put("9-23", Collections.nCopies(1, T));
put("9-25", Arrays.asList(H, Y));
put("9-27", Collections.nCopies(1, D));
put("9-28", Collections.nCopies(1, R));
put("9-29", Collections.nCopies(1, T));
put("9-30", Arrays.asList(new FotoFestival("药师琉璃光佛诞", "犯者危疾"), HH, M, T));
put("10-1", Arrays.asList(S, new FotoFestival("民岁腊", DJ), new FotoFestival("四天王降", "犯者一年内死")));
put("10-3", Arrays.asList(D, new FotoFestival("三茅诞")));
put("10-5", Arrays.asList(new FotoFestival("下会日", JS), new FotoFestival("达摩祖师诞", JS)));
put("10-6", Arrays.asList(L, new FotoFestival("天曹考察", DJ)));
put("10-8", Arrays.asList(new FotoFestival("佛涅槃日", "", false, "大忌色欲"), T));
put("10-10", Collections.nCopies(1, new FotoFestival("四天王降", "犯者一年内死")));
put("10-11", Collections.nCopies(1, new FotoFestival("宜戒")));
put("10-14", Arrays.asList(new FotoFestival("三元降", JS), T));
put("10-15", Arrays.asList(W, new FotoFestival("三元降", DJ), new FotoFestival("下元水府校籍", DJ), T));
put("10-16", Arrays.asList(new FotoFestival("三元降", JS), T));
put("10-23", Arrays.asList(Y, T));
put("10-25", Collections.nCopies(1, H));
put("10-27", Arrays.asList(D, new FotoFestival("北极紫徽大帝降")));
put("10-28", Collections.nCopies(1, R));
put("10-29", Collections.nCopies(1, T));
put("10-30", Arrays.asList(HH, M, T));
put("11-1", Collections.nCopies(1, S));
put("11-3", Collections.nCopies(1, D));
put("11-4", Collections.nCopies(1, new FotoFestival("至圣先师孔子诞", XL)));
put("11-6", Collections.nCopies(1, new FotoFestival("西岳大帝诞")));
put("11-8", Collections.nCopies(1, T));
put("11-11", Arrays.asList(new FotoFestival("天地仓开日", DJ), new FotoFestival("太乙救苦天尊诞", DJ)));
put("11-14", Collections.nCopies(1, T));
put("11-15", Arrays.asList(new FotoFestival("月望", "上半夜犯男死 下半夜犯女死"), new FotoFestival("四天王巡行", "上半夜犯男死 下半夜犯女死")));
put("11-17", Collections.nCopies(1, new FotoFestival("阿弥陀佛诞")));
put("11-19", Collections.nCopies(1, new FotoFestival("太阳日宫诞", "犯者得奇祸")));
put("11-21", Collections.nCopies(1, Y));
put("11-23", Arrays.asList(new FotoFestival("张仙诞", "犯者绝嗣"), T));
put("11-25", Arrays.asList(new FotoFestival("掠刷大夫降", "犯者遭大凶"), H));
put("11-26", Collections.nCopies(1, new FotoFestival("北方五道诞")));
put("11-27", Collections.nCopies(1, D));
put("11-28", Collections.nCopies(1, R));
put("11-29", Collections.nCopies(1, T));
put("11-30", Arrays.asList(HH, M, T));
put("12-1", Collections.nCopies(1, S));
put("12-3", Collections.nCopies(1, D));
put("12-6", Arrays.asList(new FotoFestival("天地仓开日", JS), L));
put("12-7", Collections.nCopies(1, new FotoFestival("掠刷大夫降", "犯者得恶疾")));
put("12-8", Arrays.asList(new FotoFestival("王侯腊", DJ), new FotoFestival("释迦如来成佛之辰"), T, new FotoFestival("初旬内戊日,亦名王侯腊", DJ)));
put("12-12", Collections.nCopies(1, new FotoFestival("太素三元君朝真")));
put("12-14", Collections.nCopies(1, T));
put("12-15", Arrays.asList(W, T));
put("12-16", Collections.nCopies(1, new FotoFestival("南岳大帝诞")));
put("12-19", Collections.nCopies(1, Y));
put("12-20", Collections.nCopies(1, new FotoFestival("天地交道", "犯者促寿")));
put("12-21", Collections.nCopies(1, new FotoFestival("天猷上帝诞")));
put("12-23", Arrays.asList(new FotoFestival("五岳诞降"), T));
put("12-24", Collections.nCopies(1, new FotoFestival("司今朝天奏人善恶", "犯者得大祸")));
put("12-25", Arrays.asList(new FotoFestival("三清玉帝同降,考察善恶", "犯者得奇祸"), H));
put("12-27", Collections.nCopies(1, D));
put("12-28", Collections.nCopies(1, R));
put("12-29", Arrays.asList(new FotoFestival("华严菩萨诞"), T));
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];
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -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, "毛泽东诞辰纪念日"));
}
};

View File

@@ -0,0 +1,177 @@
package com.nlf.calendar.util;
import com.nlf.calendar.TaoFestival;
import java.util.*;
/**
* 道历工具
*
* @author 6tail
*/
public class TaoUtil {
/**
* 日期对应的节日
*/
public static final Map<String, List<TaoFestival>> FESTIVAL = new HashMap<String, List<TaoFestival>>() {
private static final long serialVersionUID = 1;
{
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("举迁赏会", "此日上元赐福,天官同地水二官考校罪福")));
put("1-9", Collections.nCopies(1, new TaoFestival("玉皇上帝圣诞")));
put("1-13", Collections.nCopies(1, new TaoFestival("关圣帝君飞升")));
put("1-15", Arrays.asList(new TaoFestival("上元天官圣诞"), new TaoFestival("老祖天师圣诞")));
put("1-19", Collections.nCopies(1, new TaoFestival("长春邱真人(邱处机)圣诞")));
put("1-28", Collections.nCopies(1, new TaoFestival("许真君(许逊天师)圣诞")));
put("2-1", Arrays.asList(new TaoFestival("勾陈天皇大帝圣诞"), new TaoFestival("长春刘真人(刘渊然)圣诞")));
put("2-2", Arrays.asList(new TaoFestival("土地正神诞"), new TaoFestival("姜太公圣诞")));
put("2-3", Collections.nCopies(1, new TaoFestival("文昌梓潼帝君圣诞")));
put("2-6", Collections.nCopies(1, new TaoFestival("东华帝君圣诞")));
put("2-13", Collections.nCopies(1, new TaoFestival("度人无量葛真君圣诞")));
put("2-15", Collections.nCopies(1, new TaoFestival("太清道德天尊(太上老君)圣诞")));
put("2-19", Collections.nCopies(1, new TaoFestival("慈航真人圣诞")));
put("3-1", Collections.nCopies(1, new TaoFestival("谭祖(谭处端)长真真人圣诞")));
put("3-3", Collections.nCopies(1, new TaoFestival("玄天上帝圣诞")));
put("3-6", Collections.nCopies(1, new TaoFestival("眼光娘娘圣诞")));
put("3-15", Arrays.asList(new TaoFestival("天师张大真人圣诞"), new TaoFestival("财神赵公元帅圣诞")));
put("3-16", Arrays.asList(new TaoFestival("三茅真君得道之辰"), new TaoFestival("中岳大帝圣诞")));
put("3-18", Arrays.asList(new TaoFestival("王祖(王处一)玉阳真人圣诞"), new TaoFestival("后土娘娘圣诞")));
put("3-19", Collections.nCopies(1, new TaoFestival("太阳星君圣诞")));
put("3-20", Collections.nCopies(1, new TaoFestival("子孙娘娘圣诞")));
put("3-23", Collections.nCopies(1, new TaoFestival("天后妈祖圣诞")));
put("3-26", Collections.nCopies(1, new TaoFestival("鬼谷先师诞")));
put("3-28", Collections.nCopies(1, new TaoFestival("东岳大帝圣诞")));
put("4-1", Collections.nCopies(1, new TaoFestival("长生谭真君成道之辰")));
put("4-10", Collections.nCopies(1, new TaoFestival("何仙姑圣诞")));
put("4-14", Collections.nCopies(1, new TaoFestival("吕祖纯阳祖师圣诞")));
put("4-15", Collections.nCopies(1, new TaoFestival("钟离祖师圣诞")));
put("4-18", Arrays.asList(new TaoFestival("北极紫微大帝圣诞"), new TaoFestival("泰山圣母碧霞元君诞"), new TaoFestival("华佗神医先师诞")));
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-11", Collections.nCopies(1, new TaoFestival("城隍爷圣诞")));
put("5-13", Arrays.asList(new TaoFestival("关圣帝君降神"), new TaoFestival("关平太子圣诞")));
put("5-18", Collections.nCopies(1, new TaoFestival("张天师圣诞")));
put("5-20", Collections.nCopies(1, new TaoFestival("马祖丹阳真人圣诞")));
put("5-29", Collections.nCopies(1, new TaoFestival("紫青白祖师圣诞")));
put("6-1", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
put("6-2", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
put("6-3", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
put("6-4", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
put("6-5", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
put("6-6", Collections.nCopies(1, new TaoFestival("南斗星君下降")));
put("6-10", Collections.nCopies(1, new TaoFestival("刘海蟾祖师圣诞")));
put("6-15", Collections.nCopies(1, new TaoFestival("灵官王天君圣诞")));
put("6-19", Collections.nCopies(1, new TaoFestival("慈航(观音)成道日")));
put("6-23", Collections.nCopies(1, new TaoFestival("火神圣诞")));
put("6-24", Arrays.asList(new TaoFestival("南极大帝中方雷祖圣诞"), new TaoFestival("关圣帝君圣诞")));
put("6-26", Collections.nCopies(1, new TaoFestival("二郎真君圣诞")));
put("7-7", Arrays.asList(new TaoFestival("道德腊之辰", "道德腊,此日五帝会于西方七炁素天"), new TaoFestival("庆生中会", "此日中元赦罪,地官同天水二官考校罪福")));
put("7-12", Collections.nCopies(1, new TaoFestival("西方雷祖圣诞")));
put("7-15", Collections.nCopies(1, new TaoFestival("中元地官大帝圣诞")));
put("7-18", Collections.nCopies(1, new TaoFestival("王母娘娘圣诞")));
put("7-20", Collections.nCopies(1, new TaoFestival("刘祖(刘处玄)长生真人圣诞")));
put("7-22", Collections.nCopies(1, new TaoFestival("财帛星君文财神增福相公李诡祖圣诞")));
put("7-26", Collections.nCopies(1, new TaoFestival("张三丰祖师圣诞")));
put("8-1", Collections.nCopies(1, new TaoFestival("许真君飞升日")));
put("8-3", Collections.nCopies(1, new TaoFestival("九天司命灶君诞")));
put("8-5", Collections.nCopies(1, new TaoFestival("北方雷祖圣诞")));
put("8-10", Collections.nCopies(1, new TaoFestival("北岳大帝诞辰")));
put("8-15", Collections.nCopies(1, new TaoFestival("太阴星君诞")));
put("9-1", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-2", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-3", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-4", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-5", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-6", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-7", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-8", Collections.nCopies(1, new TaoFestival("北斗九皇降世之辰")));
put("9-9", Arrays.asList(new TaoFestival("北斗九皇降世之辰"), new TaoFestival("斗姥元君圣诞"), new TaoFestival("重阳帝君圣诞"), new TaoFestival("玄天上帝飞升"), new TaoFestival("酆都大帝圣诞")));
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-3", Collections.nCopies(1, new TaoFestival("三茅应化真君圣诞")));
put("10-6", Collections.nCopies(1, new TaoFestival("天曹诸司五岳五帝圣诞")));
put("10-15", Arrays.asList(new TaoFestival("下元水官大帝圣诞"), new TaoFestival("建生大会", "此日下元解厄,水官同天地二官考校罪福")));
put("10-18", Collections.nCopies(1, new TaoFestival("地母娘娘圣诞")));
put("10-19", Collections.nCopies(1, new TaoFestival("长春邱真君飞升")));
put("10-20", Collections.nCopies(1, new TaoFestival("虚靖天师(即三十代天师弘悟张真人)诞")));
put("11-6", Collections.nCopies(1, new TaoFestival("西岳大帝圣诞")));
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-16", Arrays.asList(new TaoFestival("南岳大帝圣诞"), new TaoFestival("福德正神诞")));
put("12-20", Collections.nCopies(1, new TaoFestival("鲁班先师圣诞")));
put("12-21", Collections.nCopies(1, new TaoFestival("天猷上帝圣诞")));
put("12-22", Collections.nCopies(1, new TaoFestival("重阳祖师圣诞")));
put("12-23", Collections.nCopies(1, new TaoFestival("祭灶王", "最适宜谢旧年太岁,开启拜新年太岁")));
put("12-25", Arrays.asList(new TaoFestival("玉帝巡天"), new TaoFestival("天神下降")));
put("12-29", Collections.nCopies(1, new TaoFestival("清静孙真君(孙不二)成道")));
}
};
/**
* 八会日
*/
public static final Map<String, String> BA_HUI = new HashMap<String, String>() {
private static final long serialVersionUID = 1;
{
put("丙午", "天会");
put("壬午", "地会");
put("壬子", "人会");
put("庚午", "日会");
put("庚申", "月会");
put("辛酉", "星辰会");
put("甲辰", "五行会");
put("甲戌", "四时会");
}
};
/**
* 八节日
*/
public static final Map<String, String> BA_JIE = new HashMap<String, String>() {
private static final long serialVersionUID = 1;
{
put("立春", "东北方度仙上圣天尊同梵炁始青天君下降");
put("春分", "东方玉宝星上天尊同青帝九炁天君下降");
put("立夏", "东南方好生度命天尊同梵炁始丹天君下降");
put("夏至", "南方玄真万福天尊同赤帝三炁天君下降");
put("立秋", "西南方太灵虚皇天尊同梵炁始素天君下降");
put("秋分", "西方太妙至极天尊同白帝七炁天君下降");
put("立冬", "西北方无量太华天尊同梵炁始玄天君下降");
put("冬至", "北方玄上玉宸天尊同黑帝五炁天君下降");
}
};
/**
* 三会日
*/
public static final String[] SAN_HUI = {"1-7", "7-7", "10-15"};
/**
* 三元日
*/
public static final String[] SAN_YUAN = {"1-15", "7-15", "10-15"};
/**
* 五腊日
*/
public static final String[] WU_LA = {"1-1", "5-5", "7-7", "10-1", "12-8"};
/**
* 暗戊
*/
public static final String[] AN_WU = {"未", "戌", "辰", "寅", "午", "子", "酉", "申", "巳", "亥", "卯", "丑"};
}

View File

@@ -108,6 +108,15 @@ public class BaZiTestNew {
}
}
@Test
public void testBazi2Solar3() {
List<Solar> l = Solar.fromBaZi("辛丑", "丁酉", "丙寅", "戊戌");
// [2021-09-15 20:00:00 星期三 处女座, 1961-09-30 20:00:00 星期六 天秤座]
for (Solar solar : l) {
System.out.println(solar.toFullString());
}
}
@Test
public void testBaziShiShenZhi() {
Solar solar = new Solar(2020, 1, 1, 22, 35, 0);

View File

@@ -0,0 +1,31 @@
package test;
import com.nlf.calendar.Foto;
import com.nlf.calendar.Lunar;
import org.junit.Assert;
import org.junit.Test;
/**
* 佛历测试
*
* @author 6tail
*/
public class FotoTest {
@Test
public void test() {
Foto foto = Foto.fromLunar(Lunar.fromYmd(2021, 10, 14));
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());
}
}

View File

@@ -173,4 +173,25 @@ public class JieQiTest {
Assert.assertEquals("冬至", lunar.getPrevQi().getName());
Assert.assertEquals("冬至", lunar.getPrevJieQi().getName());
}
@Test
public void test7() {
Lunar lunar = Lunar.fromYmd(2012, 9, 1);
Assert.assertEquals("2012-09-07 13:29:00", lunar.getJieQiTable().get("白露").toYmdHms());
}
@Test
public void test8() {
Lunar lunar = Lunar.fromYmd(2050, 12, 1);
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());
}
}

View File

@@ -16,7 +16,7 @@ public class LunarTest {
public void test() {
Lunar date = new Lunar(2019, 3, 27, 0, 0, 0);
Assert.assertEquals("二〇一九年三月廿七", date.toString());
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 (七殿泰山王诞) 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[坎](正北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]", date.toFullString());
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[艮](东北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]", date.toFullString());
Assert.assertEquals("2019-05-01", date.getSolar().toString());
Assert.assertEquals("2019-05-01 00:00:00 星期三 (劳动节) 金牛座", date.getSolar().toFullString());
}
@@ -331,4 +331,67 @@ public class LunarTest {
Assert.assertEquals("猴", lunar.getYearShengXiao());
}
@Test
public void test45() {
Solar solar = Solar.fromYmd(1946, 9, 30);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九四六年九月初六", lunar.toString());
}
@Test
public void test46() {
Solar solar = Solar.fromYmd(1946, 9, 29);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九四六年九月初五", lunar.toString());
}
@Test
public void test47() {
Solar solar = Solar.fromYmd(2017, 2, 15);
Lunar lunar = solar.getLunar();
Assert.assertEquals("子命互禄 辛命进禄", lunar.getDayLu());
}
@Test
public void test48() {
Solar solar = Solar.fromYmd(2021, 11, 13);
Lunar lunar = solar.getLunar();
Assert.assertEquals("碓磨厕 外东南", lunar.getDayPositionTai());
}
@Test
public void test49() {
Solar solar = Solar.fromYmd(2021, 11, 12);
Lunar lunar = solar.getLunar();
Assert.assertEquals("占门碓 外东南", lunar.getDayPositionTai());
}
@Test
public void test50() {
Solar solar = Solar.fromYmd(2021, 11, 13);
Lunar lunar = solar.getLunar();
Assert.assertEquals("西南", lunar.getDayPositionFuDesc());
}
@Test
public void test51() {
Solar solar = Solar.fromYmd(2021, 11, 12);
Lunar lunar = solar.getLunar();
Assert.assertEquals("正北", lunar.getDayPositionFuDesc());
}
@Test
public void test52() {
Solar solar = Solar.fromYmd(2011, 11, 12);
Lunar lunar = solar.getLunar();
Assert.assertEquals("厕灶厨 外西南", lunar.getDayPositionTai());
}
@Test
public void test53() {
Solar solar = Solar.fromYmd(2021, 11, 27);
Lunar lunar = solar.getLunar();
Assert.assertEquals("[嫁娶, 祭祀, 祈福, 求嗣, 开光, 出行, 解除, 出火, 拆卸, 进人口, 入宅, 移徙, 安床, 栽种, 动土, 修造, 纳畜, 入殓, 安葬, 立碑, 除服, 成服]", lunar.getDayYi().toString());
}
}

View File

@@ -18,7 +18,7 @@ public class SolarTest {
Assert.assertEquals("2019-05-01",date.toString());
Assert.assertEquals("2019-05-01 00:00:00 星期三 (劳动节) 金牛座",date.toFullString());
Assert.assertEquals("二〇一九年三月廿七",date.getLunar().toString());
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 (七殿泰山王诞) 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[坎](正北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]",date.getLunar().toFullString());
Assert.assertEquals("二〇一九年三月廿七 己亥(猪)年 戊辰(龙)月 戊戌(狗)日 子(鼠)时 纳音[平地木 大林木 平地木 桑柘木] 星期三 西方白虎 星宿[参水猿](吉) 彭祖百忌[戊不受田田主不祥 戌不吃犬作怪上床] 喜神方位[巽](东南) 阳贵神方位[艮](东北) 阴贵神方位[坤](西南) 福神方位[艮](东北) 财神方位[坎](正北) 冲[(壬辰)龙] 煞[北]",date.getLunar().toFullString());
}
@Test

View File

@@ -0,0 +1,31 @@
package test;
import com.nlf.calendar.Lunar;
import com.nlf.calendar.Tao;
import org.junit.Assert;
import org.junit.Test;
/**
* 道历测试
*
* @author 6tail
*/
public class TaoTest {
@Test
public void test() {
Tao tao = Tao.fromLunar(Lunar.fromYmdHms(2021, 10, 17, 18, 0, 0));
Assert.assertEquals("四七一八年十月十七", tao.toString());
Assert.assertEquals("道歷四七一八年,天運辛丑年,己亥月,癸酉日。十月十七日,酉時。", tao.toFullString());
}
@Test
public void test1() {
Tao tao = Tao.fromYmd(4718, 10, 18);
Assert.assertEquals("[地母娘娘圣诞, 四时会]", tao.getFestivals().toString());
tao = Lunar.fromYmd(2021, 10, 18).getTao();
Assert.assertEquals("[地母娘娘圣诞, 四时会]", tao.getFestivals().toString());
}
}

View File

@@ -75,4 +75,32 @@ public class WuHouTest {
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());
}
}

View File

@@ -1,5 +1,6 @@
package test;
import com.nlf.calendar.LunarYear;
import com.nlf.calendar.SolarYear;
import org.junit.Assert;
import org.junit.Test;
@@ -21,4 +22,121 @@ public class YearTest {
Assert.assertEquals("2020年",year.next(1).toFullString());
}
@Test
public void test1(){
LunarYear year = new LunarYear(2017);
Assert.assertEquals("二龙治水",year.getZhiShui());
year = new LunarYear(2018);
Assert.assertEquals("二龙治水",year.getZhiShui());
year = new LunarYear(2019);
Assert.assertEquals("八龙治水",year.getZhiShui());
year = new LunarYear(5);
Assert.assertEquals("三龙治水",year.getZhiShui());
}
@Test
public void test2(){
LunarYear year = new LunarYear(2017);
Assert.assertEquals("二人分饼",year.getFenBing());
year = new LunarYear(2018);
Assert.assertEquals("八人分饼",year.getFenBing());
year = new LunarYear(5);
Assert.assertEquals("一人分饼",year.getFenBing());
}
@Test
public void test3(){
LunarYear year = new LunarYear(2021);
Assert.assertEquals("十一牛耕田",year.getGengTian());
}
@Test
public void test4(){
LunarYear year = new LunarYear(2018);
Assert.assertEquals("三日得金",year.getDeJin());
}
@Test
public void test5(){
LunarYear year = new LunarYear(1864);
Assert.assertEquals("上元",year.getYuan());
}
@Test
public void test6(){
LunarYear year = new LunarYear(1923);
Assert.assertEquals("上元",year.getYuan());
}
@Test
public void test7(){
LunarYear year = new LunarYear(1924);
Assert.assertEquals("中元",year.getYuan());
}
@Test
public void test8(){
LunarYear year = new LunarYear(1983);
Assert.assertEquals("中元",year.getYuan());
}
@Test
public void test9(){
LunarYear year = new LunarYear(1984);
Assert.assertEquals("下元",year.getYuan());
}
@Test
public void test10(){
LunarYear year = new LunarYear(2043);
Assert.assertEquals("下元",year.getYuan());
}
@Test
public void test11(){
LunarYear year = new LunarYear(1864);
Assert.assertEquals("一运",year.getYun());
}
@Test
public void test12(){
LunarYear year = new LunarYear(1883);
Assert.assertEquals("一运",year.getYun());
}
@Test
public void test13(){
LunarYear year = new LunarYear(1884);
Assert.assertEquals("二运",year.getYun());
}
@Test
public void test14(){
LunarYear year = new LunarYear(1903);
Assert.assertEquals("二运",year.getYun());
}
@Test
public void test15(){
LunarYear year = new LunarYear(1904);
Assert.assertEquals("三运",year.getYun());
}
@Test
public void test16(){
LunarYear year = new LunarYear(1923);
Assert.assertEquals("三运",year.getYun());
}
@Test
public void test17(){
LunarYear year = new LunarYear(2004);
Assert.assertEquals("八运",year.getYun());
}
}