Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
513084bde2 | ||
|
|
df6d310b8b | ||
|
|
b0984c52f9 | ||
|
|
d9dcbc4e2a | ||
|
|
85cf35f945 | ||
|
|
30c08f8849 | ||
|
|
2eb2b508ee | ||
|
|
04195c201b | ||
|
|
b9acfec4d5 |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.15</version>
|
||||
<version>1.1.18</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.15</version>
|
||||
<version>1.1.18</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.15</version>
|
||||
<version>1.1.18</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>
|
||||
|
||||
@@ -44,6 +44,11 @@ public class EightChar {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 流派,2晚子时日柱按当天,1晚子时日柱按明天
|
||||
*/
|
||||
protected int sect = 2;
|
||||
|
||||
/**
|
||||
* 阴历
|
||||
*/
|
||||
@@ -62,6 +67,24 @@ public class EightChar {
|
||||
return getYear() + " " + getMonth() + " " + getDay() + " " + getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取流派
|
||||
*
|
||||
* @return 流派,2晚子时日柱按当天,1晚子时日柱按明天
|
||||
*/
|
||||
public int getSect() {
|
||||
return sect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置流派
|
||||
*
|
||||
* @param sect 流派,2晚子时日柱按当天,1晚子时日柱按明天,其他值默认为2
|
||||
*/
|
||||
public void setSect(int sect) {
|
||||
this.sect = (1 == sect) ? 1 : 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年柱
|
||||
*
|
||||
@@ -104,7 +127,7 @@ public class EightChar {
|
||||
* @return 五行
|
||||
*/
|
||||
public String getYearWuXing() {
|
||||
return LunarUtil.WU_XING_GAN.get(lunar.getYearGanExact()) + LunarUtil.WU_XING_ZHI.get(lunar.getYearZhiExact());
|
||||
return LunarUtil.WU_XING_GAN.get(getYearGan()) + LunarUtil.WU_XING_ZHI.get(getYearZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,9 +166,27 @@ public class EightChar {
|
||||
return getShiShenZhi(getYearZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日干下标
|
||||
*
|
||||
* @return 日干下标,0-9
|
||||
*/
|
||||
public int getDayGanIndex() {
|
||||
return 2 == sect ? lunar.getDayGanIndexExact2() : lunar.getDayGanIndexExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日支下标
|
||||
*
|
||||
* @return 日支下标,0-11
|
||||
*/
|
||||
public int getDayZhiIndex() {
|
||||
return 2 == sect ? lunar.getDayZhiIndexExact2() : lunar.getDayZhiIndexExact();
|
||||
}
|
||||
|
||||
private String getDiShi(int zhiIndex) {
|
||||
int offset = CHANG_SHENG_OFFSET.get(getDayGan());
|
||||
int index = offset + (lunar.getDayGanIndexExact() % 2 == 0 ? zhiIndex : -zhiIndex);
|
||||
int index = offset + (getDayGanIndex() % 2 == 0 ? zhiIndex : -zhiIndex);
|
||||
if (index >= 12) {
|
||||
index -= 12;
|
||||
}
|
||||
@@ -206,7 +247,7 @@ public class EightChar {
|
||||
* @return 五行
|
||||
*/
|
||||
public String getMonthWuXing() {
|
||||
return LunarUtil.WU_XING_GAN.get(lunar.getMonthGanExact()) + LunarUtil.WU_XING_ZHI.get(lunar.getMonthZhiExact());
|
||||
return LunarUtil.WU_XING_GAN.get(getMonthGan()) + LunarUtil.WU_XING_ZHI.get(getMonthZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,7 +292,7 @@ public class EightChar {
|
||||
* @return 日柱
|
||||
*/
|
||||
public String getDay() {
|
||||
return lunar.getDayInGanZhiExact();
|
||||
return 2 == sect ? lunar.getDayInGanZhiExact2() : lunar.getDayInGanZhiExact();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -260,7 +301,7 @@ public class EightChar {
|
||||
* @return 天干
|
||||
*/
|
||||
public String getDayGan() {
|
||||
return lunar.getDayGanExact();
|
||||
return 2 == sect ? lunar.getDayGanExact2() : lunar.getDayGanExact();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -269,7 +310,7 @@ public class EightChar {
|
||||
* @return 地支
|
||||
*/
|
||||
public String getDayZhi() {
|
||||
return lunar.getDayZhiExact();
|
||||
return 2 == sect ? lunar.getDayZhiExact2() : lunar.getDayZhiExact();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -287,7 +328,7 @@ public class EightChar {
|
||||
* @return 五行
|
||||
*/
|
||||
public String getDayWuXing() {
|
||||
return LunarUtil.WU_XING_GAN.get(lunar.getDayGanExact()) + LunarUtil.WU_XING_ZHI.get(lunar.getDayZhiExact());
|
||||
return LunarUtil.WU_XING_GAN.get(getDayGan()) + LunarUtil.WU_XING_ZHI.get(getDayZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -323,7 +364,7 @@ public class EightChar {
|
||||
* @return 地势
|
||||
*/
|
||||
public String getDayDiShi() {
|
||||
return getDiShi(lunar.getDayZhiIndexExact());
|
||||
return getDiShi(getDayZhiIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -526,65 +567,73 @@ public class EightChar {
|
||||
|
||||
/**
|
||||
* 获取年柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getYearXun(){
|
||||
public String getYearXun() {
|
||||
return lunar.getYearXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getYearXunKong(){
|
||||
public String getYearXunKong() {
|
||||
return lunar.getYearXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getMonthXun(){
|
||||
public String getMonthXun() {
|
||||
return lunar.getMonthXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取月柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getMonthXunKong(){
|
||||
public String getMonthXunKong() {
|
||||
return lunar.getMonthXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXun(){
|
||||
return lunar.getDayXunExact();
|
||||
public String getDayXun() {
|
||||
return 2 == sect ? lunar.getDayXunExact2() : lunar.getDayXunExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getDayXunKong(){
|
||||
return lunar.getDayXunKongExact();
|
||||
public String getDayXunKong() {
|
||||
return 2 == sect ? lunar.getDayXunKongExact2() : lunar.getDayXunKongExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时柱所在旬
|
||||
*
|
||||
* @return 旬
|
||||
*/
|
||||
public String getTimeXun(){
|
||||
public String getTimeXun() {
|
||||
return lunar.getTimeXun();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时柱旬空(空亡)
|
||||
*
|
||||
* @return 旬空(空亡)
|
||||
*/
|
||||
public String getTimeXunKong(){
|
||||
public String getTimeXunKong() {
|
||||
return lunar.getTimeXunKong();
|
||||
}
|
||||
}
|
||||
|
||||
53
src/main/java/com/nlf/calendar/Fu.java
Normal file
53
src/main/java/com/nlf/calendar/Fu.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.nlf.calendar;
|
||||
|
||||
/**
|
||||
* 三伏
|
||||
* <p>从夏至后第3个庚日算起,初伏为10天,中伏为10天或20天,末伏为10天。当夏至与立秋之间出现4个庚日时中伏为10天,出现5个庚日则为20天。</p>
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class Fu {
|
||||
/**
|
||||
* 名称:初伏、中伏、末伏
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 当前入伏第几天,1-20
|
||||
*/
|
||||
private int index;
|
||||
|
||||
|
||||
public Fu() {
|
||||
}
|
||||
|
||||
public Fu(String name, int index) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toFullString() {
|
||||
return name + "第" + index + "天";
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ public class Lunar{
|
||||
public static final String QI_SOLAR_SECOND = "大寒";
|
||||
/** 1弧度对应的角秒 */
|
||||
private static final double SECOND_PER_RAD = 180 * 3600 / Math.PI;
|
||||
/** 1天对应的毫秒 */
|
||||
private static final long MS_PER_DAY = 86400000L;
|
||||
/** 节气表,国标以冬至为首个节气 */
|
||||
private static final String[] JIE_QI = {"冬至","小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪"};
|
||||
private static final double[] NUT_B = {2.1824, -33.75705, 36e-6, -1720, 920, 3.5069, 1256.66393, 11e-6, -132, 57, 1.3375, 16799.4182, -51e-6, -23, 10, 4.3649, -67.5141, 72e-6, 21, -9, 0.04, -628.302, 0, -14, 0, 2.36, 8328.691, 0, 7, 0, 3.46, 1884.966, 0, -5, 2, 5.44, 16833.175, 0, -4, 2, 3.69, 25128.110, 0, -3, 0, 3.55, 628.362, 0, 2, 0};
|
||||
@@ -55,10 +57,14 @@ public class Lunar{
|
||||
private int dayGanIndex;
|
||||
/** 日对应的地支下标,0-11 */
|
||||
private int dayZhiIndex;
|
||||
/** 日对应的天干下标(最精确的,供八字用,晚子时算第二天),0-9 */
|
||||
/** 日对应的天干下标(八字流派1,晚子时日柱算明天),0-9 */
|
||||
private int dayGanIndexExact;
|
||||
/** 日对应的地支下标(最精确的,供八字用,晚子时算第二天),0-11 */
|
||||
/** 日对应的地支下标(八字流派1,晚子时日柱算明天),0-11 */
|
||||
private int dayZhiIndexExact;
|
||||
/** 日对应的天干下标(八字流派2,晚子时日柱算当天),0-9 */
|
||||
private int dayGanIndexExact2;
|
||||
/** 日对应的地支下标(八字流派2,晚子时日柱算当天),0-11 */
|
||||
private int dayZhiIndexExact2;
|
||||
/** 月对应的天干下标(以节交接当天起算),0-9 */
|
||||
private int monthGanIndex;
|
||||
/** 月对应的地支下标(以节交接当天起算),0-11 */
|
||||
@@ -564,7 +570,11 @@ public class Lunar{
|
||||
int dayGanExact = dayGanIndex;
|
||||
int dayZhiExact = dayZhiIndex;
|
||||
|
||||
// 晚子时(夜子/子夜)应算作第二天
|
||||
// 八字流派2,晚子时(夜子/子夜)日柱算当天
|
||||
dayGanIndexExact2 = dayGanExact;
|
||||
dayZhiIndexExact2 = dayZhiExact;
|
||||
|
||||
// 八字流派1,晚子时(夜子/子夜)日柱算明天
|
||||
String hm = (hour<10?"0":"")+hour+":"+(minute<10?"0":"")+minute;
|
||||
if(hm.compareTo("23:00")>=0&&hm.compareTo("23:59")<=0){
|
||||
dayGanExact++;
|
||||
@@ -807,7 +817,7 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支纪日(日柱,晚子时算第二天)
|
||||
* 获取干支纪日(日柱,晚子时日柱算明天)
|
||||
*
|
||||
* @return 干支纪日(日柱),如己卯
|
||||
*/
|
||||
@@ -815,6 +825,15 @@ public class Lunar{
|
||||
return getDayGanExact()+getDayZhiExact();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取干支纪日(日柱,晚子时日柱算当天)
|
||||
*
|
||||
* @return 干支纪日(日柱),如己卯
|
||||
*/
|
||||
public String getDayInGanZhiExact2(){
|
||||
return getDayGanExact2()+getDayZhiExact2();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日天干
|
||||
*
|
||||
@@ -825,7 +844,7 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日天干(晚子时算第二天)
|
||||
* 获取日天干(晚子时日柱算明天)
|
||||
*
|
||||
* @return 日天干,如甲
|
||||
*/
|
||||
@@ -833,6 +852,15 @@ public class Lunar{
|
||||
return LunarUtil.GAN[dayGanIndexExact+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日天干(晚子时日柱算当天)
|
||||
*
|
||||
* @return 日天干,如甲
|
||||
*/
|
||||
public String getDayGanExact2(){
|
||||
return LunarUtil.GAN[dayGanIndexExact2+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日地支
|
||||
*
|
||||
@@ -843,7 +871,7 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日地支(晚子时算第二天)
|
||||
* 获取日地支(晚子时日柱算明天)
|
||||
*
|
||||
* @return 日地支,如卯
|
||||
*/
|
||||
@@ -851,6 +879,15 @@ public class Lunar{
|
||||
return LunarUtil.ZHI[dayZhiIndexExact+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日地支(晚子时日柱算当天)
|
||||
*
|
||||
* @return 日地支,如卯
|
||||
*/
|
||||
public String getDayZhiExact2(){
|
||||
return LunarUtil.ZHI[dayZhiIndexExact2+1];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取年生肖
|
||||
*
|
||||
@@ -2304,14 +2341,54 @@ public class Lunar{
|
||||
return timeZhiIndex;
|
||||
}
|
||||
|
||||
public int getDayGanIndex() {
|
||||
return dayGanIndex;
|
||||
}
|
||||
|
||||
public int getDayZhiIndex() {
|
||||
return dayZhiIndex;
|
||||
}
|
||||
|
||||
public int getMonthGanIndex() {
|
||||
return monthGanIndex;
|
||||
}
|
||||
|
||||
public int getMonthZhiIndex() {
|
||||
return monthZhiIndex;
|
||||
}
|
||||
|
||||
public int getYearGanIndex() {
|
||||
return yearGanIndex;
|
||||
}
|
||||
|
||||
public int getYearZhiIndex() {
|
||||
return yearZhiIndex;
|
||||
}
|
||||
|
||||
public int getYearGanIndexByLiChun() {
|
||||
return yearGanIndexByLiChun;
|
||||
}
|
||||
|
||||
public int getYearZhiIndexByLiChun() {
|
||||
return yearZhiIndexByLiChun;
|
||||
}
|
||||
|
||||
public int getDayGanIndexExact() {
|
||||
return dayGanIndexExact;
|
||||
}
|
||||
|
||||
public int getDayGanIndexExact2() {
|
||||
return dayGanIndexExact2;
|
||||
}
|
||||
|
||||
public int getDayZhiIndexExact() {
|
||||
return dayZhiIndexExact;
|
||||
}
|
||||
|
||||
public int getDayZhiIndexExact2() {
|
||||
return dayZhiIndexExact2;
|
||||
}
|
||||
|
||||
public int getMonthGanIndexExact() {
|
||||
return monthGanIndexExact;
|
||||
}
|
||||
@@ -2479,13 +2556,21 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日所在旬(晚子时算第二天)
|
||||
* 获取日所在旬(晚子时日柱算明天)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXunExact(){
|
||||
return LunarUtil.getXun(getDayInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日所在旬(晚子时日柱算当天)
|
||||
* @return 旬
|
||||
*/
|
||||
public String getDayXunExact2(){
|
||||
return LunarUtil.getXun(getDayInGanZhiExact2());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡
|
||||
* @return 空亡(旬空)
|
||||
@@ -2495,13 +2580,21 @@ public class Lunar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡(晚子时算第二天)
|
||||
* 获取值日空亡(晚子时日柱算明天)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getDayXunKongExact(){
|
||||
return LunarUtil.getXunKong(getDayInGanZhiExact());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取值日空亡(晚子时日柱算当天)
|
||||
* @return 空亡(旬空)
|
||||
*/
|
||||
public String getDayXunKongExact2(){
|
||||
return LunarUtil.getXunKong(getDayInGanZhiExact2());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时辰所在旬
|
||||
* @return 旬
|
||||
@@ -2517,4 +2610,139 @@ public class Lunar{
|
||||
public String getTimeXunKong(){
|
||||
return LunarUtil.getXunKong(getTimeInGanZhi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数九
|
||||
* @return 数九,如果不是数九天,返回null
|
||||
*/
|
||||
public ShuJiu getShuJiu(){
|
||||
Calendar currentCalendar = Calendar.getInstance();
|
||||
currentCalendar.set(solar.getYear(),solar.getMonth()-1,solar.getDay(),0,0,0);
|
||||
currentCalendar.set(Calendar.MILLISECOND,0);
|
||||
Solar start = jieQi.get(JIE_QI_APPEND);
|
||||
Calendar startCalendar = Calendar.getInstance();
|
||||
startCalendar.set(start.getYear(),start.getMonth()-1,start.getDay(),0,0,0);
|
||||
startCalendar.set(Calendar.MILLISECOND,0);
|
||||
|
||||
if(currentCalendar.compareTo(startCalendar)<0){
|
||||
start = jieQi.get(JIE_QI_FIRST);
|
||||
startCalendar.set(start.getYear(),start.getMonth()-1,start.getDay(),0,0,0);
|
||||
}
|
||||
|
||||
Calendar endCalendar = Calendar.getInstance();
|
||||
endCalendar.set(start.getYear(),start.getMonth()-1,start.getDay(),0,0,0);
|
||||
endCalendar.add(Calendar.DATE,81);
|
||||
endCalendar.set(Calendar.MILLISECOND,0);
|
||||
|
||||
if(currentCalendar.compareTo(startCalendar)<0||currentCalendar.compareTo(endCalendar)>=0){
|
||||
return null;
|
||||
}
|
||||
|
||||
int days = (int)((currentCalendar.getTimeInMillis()-startCalendar.getTimeInMillis())/MS_PER_DAY);
|
||||
return new ShuJiu(LunarUtil.NUMBER[days/9+1]+"九",days%9+1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取三伏
|
||||
* @return 三伏,如果不是伏天,返回null
|
||||
*/
|
||||
public Fu getFu(){
|
||||
Calendar currentCalendar = Calendar.getInstance();
|
||||
currentCalendar.set(solar.getYear(),solar.getMonth()-1,solar.getDay(),0,0,0);
|
||||
currentCalendar.set(Calendar.MILLISECOND,0);
|
||||
Solar xiaZhi = jieQi.get("夏至");
|
||||
Solar liQiu = jieQi.get("立秋");
|
||||
Calendar startCalendar = Calendar.getInstance();
|
||||
startCalendar.set(xiaZhi.getYear(),xiaZhi.getMonth()-1,xiaZhi.getDay(),0,0,0);
|
||||
startCalendar.set(Calendar.MILLISECOND,0);
|
||||
|
||||
// 第1个庚日
|
||||
int add = 6-xiaZhi.getLunar().getDayGanIndex();
|
||||
if(add<0){
|
||||
add += 10;
|
||||
}
|
||||
// 第3个庚日,即初伏第1天
|
||||
add += 20;
|
||||
startCalendar.add(Calendar.DATE,add);
|
||||
|
||||
// 初伏以前
|
||||
if(currentCalendar.compareTo(startCalendar)<0){
|
||||
return null;
|
||||
}
|
||||
|
||||
int days = (int)((currentCalendar.getTimeInMillis()-startCalendar.getTimeInMillis())/MS_PER_DAY);
|
||||
if(days<10){
|
||||
return new Fu("初伏",days+1);
|
||||
}
|
||||
|
||||
// 第4个庚日,中伏第1天
|
||||
startCalendar.add(Calendar.DATE,10);
|
||||
|
||||
days = (int)((currentCalendar.getTimeInMillis()-startCalendar.getTimeInMillis())/MS_PER_DAY);
|
||||
if(days<10){
|
||||
return new Fu("中伏",days+1);
|
||||
}
|
||||
|
||||
// 第5个庚日,中伏第11天或末伏第1天
|
||||
startCalendar.add(Calendar.DATE,10);
|
||||
|
||||
Calendar liQiuCalendar = Calendar.getInstance();
|
||||
liQiuCalendar.set(liQiu.getYear(),liQiu.getMonth()-1,liQiu.getDay(),0,0,0);
|
||||
liQiuCalendar.set(Calendar.MILLISECOND,0);
|
||||
|
||||
days = (int)((currentCalendar.getTimeInMillis()-startCalendar.getTimeInMillis())/MS_PER_DAY);
|
||||
// 末伏
|
||||
if(liQiuCalendar.compareTo(startCalendar)<=0){
|
||||
if(days<10){
|
||||
return new Fu("末伏",days+1);
|
||||
}
|
||||
}else{
|
||||
// 中伏
|
||||
if(days<10){
|
||||
return new Fu("中伏",days+11);
|
||||
}
|
||||
// 末伏第1天
|
||||
startCalendar.add(Calendar.DATE,10);
|
||||
days = (int)((currentCalendar.getTimeInMillis()-startCalendar.getTimeInMillis())/MS_PER_DAY);
|
||||
if(days<10){
|
||||
return new Fu("末伏",days+1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取六曜
|
||||
* @return 六曜
|
||||
*/
|
||||
public String getLiuYao(){
|
||||
return LunarUtil.LIU_YAO[(Math.abs(month)-1+day-1)%6];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物候
|
||||
* @return 物候
|
||||
*/
|
||||
public String getWuHou(){
|
||||
JieQi jieQi = getPrevJieQi();
|
||||
String name = jieQi.getName();
|
||||
int offset = 0;
|
||||
for(int i=0,j=JIE_QI.length;i<j;i++){
|
||||
if(name.equals(JIE_QI[i])){
|
||||
offset = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Calendar currentCalendar = Calendar.getInstance();
|
||||
currentCalendar.set(solar.getYear(),solar.getMonth()-1,solar.getDay(),0,0,0);
|
||||
currentCalendar.set(Calendar.MILLISECOND,0);
|
||||
|
||||
Solar startSolar = jieQi.getSolar();
|
||||
Calendar startCalendar = Calendar.getInstance();
|
||||
startCalendar.set(startSolar.getYear(),startSolar.getMonth()-1,startSolar.getDay(),0,0,0);
|
||||
startCalendar.set(Calendar.MILLISECOND,0);
|
||||
|
||||
int days = (int)((currentCalendar.getTimeInMillis()-startCalendar.getTimeInMillis())/MS_PER_DAY);
|
||||
return LunarUtil.WU_HOU[offset*3+days/5];
|
||||
}
|
||||
}
|
||||
|
||||
51
src/main/java/com/nlf/calendar/ShuJiu.java
Normal file
51
src/main/java/com/nlf/calendar/ShuJiu.java
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.nlf.calendar;
|
||||
|
||||
/**
|
||||
* 数九
|
||||
* @author 6tail
|
||||
*/
|
||||
public class ShuJiu {
|
||||
|
||||
/**
|
||||
* 名称,如一九、二九
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 当前数九第几天,1-9
|
||||
*/
|
||||
private int index;
|
||||
|
||||
public ShuJiu() {
|
||||
}
|
||||
|
||||
public ShuJiu(String name, int index) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
public void setIndex(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String toFullString() {
|
||||
return name + "第" + index + "天";
|
||||
}
|
||||
}
|
||||
@@ -208,7 +208,7 @@ public class Solar{
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过八字获取阳历列表
|
||||
* 通过八字获取阳历列表(晚子时日柱按当天)
|
||||
* @param yearGanZhi 年柱
|
||||
* @param monthGanZhi 月柱
|
||||
* @param dayGanZhi 日柱
|
||||
@@ -216,6 +216,20 @@ public class Solar{
|
||||
* @return 符合的阳历列表
|
||||
*/
|
||||
public static List<Solar> fromBaZi(String yearGanZhi,String monthGanZhi,String dayGanZhi,String timeGanZhi){
|
||||
return fromBaZi(yearGanZhi,monthGanZhi,dayGanZhi,timeGanZhi,2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过八字获取阳历列表
|
||||
* @param yearGanZhi 年柱
|
||||
* @param monthGanZhi 月柱
|
||||
* @param dayGanZhi 日柱
|
||||
* @param timeGanZhi 时柱
|
||||
* @param sect 流派,2晚子时日柱按当天,1晚子时日柱按明天
|
||||
* @return 符合的阳历列表
|
||||
*/
|
||||
public static List<Solar> fromBaZi(String yearGanZhi,String monthGanZhi,String dayGanZhi,String timeGanZhi,int sect){
|
||||
sect = (1==sect)?1:2;
|
||||
List<Solar> l = new ArrayList<Solar>();
|
||||
Solar today = new Solar();
|
||||
Lunar lunar = today.getLunar();
|
||||
@@ -271,7 +285,8 @@ public class Solar{
|
||||
Solar solar = new Solar(year, month, day, hour, 0, 0);
|
||||
while (counter < 61) {
|
||||
lunar = solar.getLunar();
|
||||
if (lunar.getYearInGanZhiExact().equals(yearGanZhi) && lunar.getMonthInGanZhiExact().equals(monthGanZhi) && lunar.getDayInGanZhiExact().equals(dayGanZhi) && lunar.getTimeInGanZhi().equals(timeGanZhi)) {
|
||||
String dgz = (2==sect)?lunar.getDayInGanZhiExact2():lunar.getDayInGanZhiExact();
|
||||
if (lunar.getYearInGanZhiExact().equals(yearGanZhi) && lunar.getMonthInGanZhiExact().equals(monthGanZhi) && dgz.equals(dayGanZhi) && lunar.getTimeInGanZhi().equals(timeGanZhi)) {
|
||||
l.add(solar);
|
||||
break;
|
||||
}
|
||||
@@ -364,25 +379,25 @@ public class Solar{
|
||||
* @return 星座
|
||||
*/
|
||||
public String getXingZuo(){
|
||||
int index = 11,m = month,d = day;
|
||||
int y = m*100+d;
|
||||
int index = 11;
|
||||
int y = month*100+day;
|
||||
if(y>=321&&y<=419){
|
||||
index = 0;
|
||||
}else if(y>=420&&y<=520){
|
||||
index = 1;
|
||||
}else if(y>=521&&y<=620){
|
||||
}else if(y>=521&&y<=621){
|
||||
index = 2;
|
||||
}else if(y>=621&&y<=722){
|
||||
}else if(y>=622&&y<=722){
|
||||
index = 3;
|
||||
}else if(y>=723&&y<=822){
|
||||
index = 4;
|
||||
}else if(y>=823&&y<=922){
|
||||
index = 5;
|
||||
}else if(y>=923&&y<=1022){
|
||||
}else if(y>=923&&y<=1023){
|
||||
index = 6;
|
||||
}else if(y>=1023&&y<=1121){
|
||||
}else if(y>=1024&&y<=1122){
|
||||
index = 7;
|
||||
}else if(y>=1122&&y<=1221){
|
||||
}else if(y>=1123&&y<=1221){
|
||||
index = 8;
|
||||
}else if(y>=1222||y<=119){
|
||||
index = 9;
|
||||
|
||||
@@ -27,14 +27,18 @@ public class LunarUtil{
|
||||
public static final int BASE_MONTH_ZHI_INDEX = 2;
|
||||
/** 星期偏移量 */
|
||||
public static final int BASE_WEEK_INDEX = 2;
|
||||
/** 闰年表 */
|
||||
/** 闰年表(存在闰月的年份偏移值) */
|
||||
public static final int[] LEAP_MONTH_YEAR = {6,14,19,25,33,36,38,41,44,52,55,79,117,136,147,150,155,158,185,193};
|
||||
/** 闰月表 */
|
||||
/** 月份表(2个字节表示1年,共16个二进制位,前4位表示闰月月份,后12位表示每月大小) */
|
||||
public static final int[] LUNAR_MONTH = {0x00,0x04,0xad,0x08,0x5a,0x01,0xd5,0x54,0xb4,0x09,0x64,0x05,0x59,0x45,0x95,0x0a,0xa6,0x04,0x55,0x24,0xad,0x08,0x5a,0x62,0xda,0x04,0xb4,0x05,0xb4,0x55,0x52,0x0d,0x94,0x0a,0x4a,0x2a,0x56,0x02,0x6d,0x71,0x6d,0x01,0xda,0x02,0xd2,0x52,0xa9,0x05,0x49,0x0d,0x2a,0x45,0x2b,0x09,0x56,0x01,0xb5,0x20,0x6d,0x01,0x59,0x69,0xd4,0x0a,0xa8,0x05,0xa9,0x56,0xa5,0x04,0x2b,0x09,0x9e,0x38,0xb6,0x08,0xec,0x74,0x6c,0x05,0xd4,0x0a,0xe4,0x6a,0x52,0x05,0x95,0x0a,0x5a,0x42,0x5b,0x04,0xb6,0x04,0xb4,0x22,0x6a,0x05,0x52,0x75,0xc9,0x0a,0x52,0x05,0x35,0x55,0x4d,0x0a,0x5a,0x02,0x5d,0x31,0xb5,0x02,0x6a,0x8a,0x68,0x05,0xa9,0x0a,0x8a,0x6a,0x2a,0x05,0x2d,0x09,0xaa,0x48,0x5a,0x01,0xb5,0x09,0xb0,0x39,0x64,0x05,0x25,0x75,0x95,0x0a,0x96,0x04,0x4d,0x54,0xad,0x04,0xda,0x04,0xd4,0x44,0xb4,0x05,0x54,0x85,0x52,0x0d,0x92,0x0a,0x56,0x6a,0x56,0x02,0x6d,0x02,0x6a,0x41,0xda,0x02,0xb2,0xa1,0xa9,0x05,0x49,0x0d,0x0a,0x6d,0x2a,0x09,0x56,0x01,0xad,0x50,0x6d,0x01,0xd9,0x02,0xd1,0x3a,0xa8,0x05,0x29,0x85,0xa5,0x0c,0x2a,0x09,0x96,0x54,0xb6,0x08,0x6c,0x09,0x64,0x45,0xd4,0x0a,0xa4,0x05,0x51,0x25,0x95,0x0a,0x2a,0x72,0x5b,0x04,0xb6,0x04,0xac,0x52,0x6a,0x05,0xd2,0x0a,0xa2,0x4a,0x4a,0x05,0x55,0x94,0x2d,0x0a,0x5a,0x02,0x75,0x61,0xb5,0x02,0x6a,0x03,0x61,0x45,0xa9,0x0a,0x4a,0x05,0x25,0x25,0x2d,0x09,0x9a,0x68,0xda,0x08,0xb4,0x09,0xa8,0x59,0x54,0x03,0xa5,0x0a,0x91,0x3a,0x96,0x04,0xad,0xb0,0xad,0x04,0xda,0x04,0xf4,0x62,0xb4,0x05,0x54,0x0b,0x44,0x5d,0x52,0x0a,0x95,0x04,0x55,0x22,0x6d,0x02,0x5a,0x71,0xda,0x02,0xaa,0x05,0xb2,0x55,0x49,0x0b,0x4a,0x0a,0x2d,0x39,0x36,0x01,0x6d,0x80,0x6d,0x01,0xd9,0x02,0xe9,0x6a,0xa8,0x05,0x29,0x0b,0x9a,0x4c,0xaa,0x08,0xb6,0x08,0xb4,0x38,0x6c,0x09,0x54,0x75,0xd4,0x0a,0xa4,0x05,0x45,0x55,0x95,0x0a,0x9a,0x04,0x55,0x44,0xb5,0x04,0x6a,0x82,0x6a,0x05,0xd2,0x0a,0x92,0x6a,0x4a,0x05,0x55,0x0a,0x2a,0x4a,0x5a,0x02,0xb5,0x02,0xb2,0x31,0x69,0x03,0x31,0x73,0xa9,0x0a,0x4a,0x05,0x2d,0x55,0x2d,0x09,0x5a,0x01,0xd5,0x48,0xb4,0x09,0x68,0x89,0x54,0x0b,0xa4,0x0a,0xa5,0x6a,0x95,0x04,0xad,0x08,0x6a,0x44,0xda,0x04,0x74,0x05,0xb0,0x25,0x54,0x03};
|
||||
/** 旬 */
|
||||
public static final String[] XUN = {"甲子","甲戌","甲申","甲午","甲辰","甲寅"};
|
||||
/** 旬空 */
|
||||
public static final String[] XUN_KONG = {"戌亥","申酉","午未","辰巳","寅卯","子丑"};
|
||||
/** 六曜 */
|
||||
public static final String[] LIU_YAO = {"先胜","友引","先负","佛灭","大安","赤口"};
|
||||
/** 物候 */
|
||||
public static final String[] WU_HOU = {"蚯蚓结","麋角解","水泉动","雁北乡","鹊始巢","雉始雊","鸡始乳","征鸟厉疾","水泽腹坚","东风解冻","蛰虫始振","鱼陟负冰","獭祭鱼","候雁北","草木萌动","桃始华","仓庚鸣","鹰化为鸠","玄鸟至","雷乃发声","始电","桐始华","田鼠化为鴽","虹始见","萍始生","鸣鸠拂奇羽","戴胜降于桑","蝼蝈鸣","蚯蚓出","王瓜生","苦菜秀","靡草死","麦秋至","螳螂生","鵙始鸣","反舌无声","鹿角解","蜩始鸣","半夏生","温风至","蟋蟀居壁","鹰始挚","腐草为萤","土润溽暑","大雨行时","凉风至","白露降","寒蝉鸣","鹰乃祭鸟","天地始肃","禾乃登","鸿雁来","玄鸟归","群鸟养羞","雷始收声","蛰虫坯户","水始涸","鸿雁来宾","雀入大水为蛤","菊有黄花","豺乃祭兽","草木黄落","蛰虫咸俯","水始冰","地始冻","雉入大水为蜃","虹藏不见","天气上升地气下降","闭塞而成冬","鹖鴠不鸣","虎始交","荔挺出"};
|
||||
/** 天干 */
|
||||
public static final String[] GAN = {"","甲","乙","丙","丁","戊","己","庚","辛","壬","癸"};
|
||||
/** 喜神方位,《喜神方位歌》:甲己在艮乙庚乾,丙辛坤位喜神安. 丁壬只在离宫坐,戊癸原在在巽间。 */
|
||||
@@ -151,41 +155,47 @@ public class LunarUtil{
|
||||
put("12-30","除夕");
|
||||
}
|
||||
};
|
||||
/** 农历日期对应的非正式节日 */
|
||||
/** 农历日期对应的非正式节日,参考《寿康宝鉴》 */
|
||||
public static final Map<String,List<String>> OTHER_FESTIVAL = new HashMap<String,List<String>>(){
|
||||
private static final long serialVersionUID = -1;
|
||||
{
|
||||
put("1-1",Collections.nCopies(1,"弥勒佛圣诞"));
|
||||
put("1-8",Collections.nCopies(1,"五殿阎罗天子诞"));
|
||||
put("1-9",Collections.nCopies(1,"玉皇上帝诞"));
|
||||
put("1-13",Collections.nCopies(1,"杨公忌"));
|
||||
put("2-1",Collections.nCopies(1,"一殿秦广王诞"));
|
||||
put("2-2",Collections.nCopies(1,"福德土地正神诞"));
|
||||
put("2-3",Collections.nCopies(1,"文昌帝君诞"));
|
||||
put("2-6",Collections.nCopies(1,"东华帝君诞"));
|
||||
put("2-8",Collections.nCopies(1,"释迦牟尼佛出家"));
|
||||
put("2-15",Collections.nCopies(1,"释迦牟尼佛般涅槃"));
|
||||
put("2-11",Collections.nCopies(1,"杨公忌"));
|
||||
put("2-15",Arrays.asList("释迦牟尼佛涅槃","太上老君诞"));
|
||||
put("2-17",Collections.nCopies(1,"东方杜将军诞"));
|
||||
put("2-18",Collections.nCopies(1,"至圣先师孔子讳辰"));
|
||||
put("2-18",Arrays.asList("四殿五官王诞","至圣先师孔子讳辰"));
|
||||
put("2-19",Collections.nCopies(1,"观音大士诞"));
|
||||
put("2-21",Collections.nCopies(1,"普贤菩萨诞"));
|
||||
put("3-1",Collections.nCopies(1,"二殿楚江王诞"));
|
||||
put("3-3",Collections.nCopies(1,"玄天上帝诞"));
|
||||
put("3-8",Collections.nCopies(1,"六殿卞城王诞"));
|
||||
put("3-15",Collections.nCopies(1,"昊天上帝诞"));
|
||||
put("3-9",Collections.nCopies(1,"杨公忌"));
|
||||
put("3-12",Collections.nCopies(1,"中央五道诞"));
|
||||
put("3-15",Arrays.asList("玄坛诞","昊天上帝诞"));
|
||||
put("3-16",Collections.nCopies(1,"准提菩萨诞"));
|
||||
put("3-19",Collections.nCopies(1,"中岳大帝诞"));
|
||||
put("3-18",Arrays.asList("中岳大帝诞","后土娘娘诞"));
|
||||
put("3-20",Collections.nCopies(1,"子孙娘娘诞"));
|
||||
put("3-27",Collections.nCopies(1,"七殿泰山王诞"));
|
||||
put("3-28",Collections.nCopies(1,"苍颉至圣先师诞"));
|
||||
put("4-1",Collections.nCopies(1,"八殿都市王诞"));
|
||||
put("4-4",Collections.nCopies(1,"文殊菩萨诞"));
|
||||
put("4-8",Collections.nCopies(1,"释迦牟尼佛诞"));
|
||||
put("4-7",Collections.nCopies(1,"杨公忌"));
|
||||
put("4-8",Arrays.asList("释迦牟尼佛诞","九殿平等王诞"));
|
||||
put("4-14",Collections.nCopies(1,"纯阳祖师诞"));
|
||||
put("4-15",Collections.nCopies(1,"钟离祖师诞"));
|
||||
put("4-17",Collections.nCopies(1,"十殿转轮王诞"));
|
||||
put("4-18",Collections.nCopies(1,"紫徽大帝诞"));
|
||||
put("4-20",Collections.nCopies(1,"眼光圣母诞"));
|
||||
put("5-1",Collections.nCopies(1,"南极长生大帝诞"));
|
||||
put("5-5",Collections.nCopies(1,"杨公忌"));
|
||||
put("5-8",Collections.nCopies(1,"南方五道诞"));
|
||||
put("5-11",Collections.nCopies(1,"天下都城隍诞"));
|
||||
put("5-12",Collections.nCopies(1,"炳灵公诞"));
|
||||
@@ -193,10 +203,16 @@ public class LunarUtil{
|
||||
put("5-16",Collections.nCopies(1,"天地元气造化万物之辰"));
|
||||
put("5-18",Collections.nCopies(1,"张天师诞"));
|
||||
put("5-22",Collections.nCopies(1,"孝娥神诞"));
|
||||
put("6-19",Collections.nCopies(1,"观世音菩萨成道日"));
|
||||
put("6-24",Collections.nCopies(1,"关帝诞"));
|
||||
put("6-3",Collections.nCopies(1,"杨公忌"));
|
||||
put("6-10",Collections.nCopies(1,"金粟如来诞"));
|
||||
put("6-13",Collections.nCopies(1,"井泉龙王诞"));
|
||||
put("6-19",Collections.nCopies(1,"观音大士涅槃"));
|
||||
put("6-23",Collections.nCopies(1,"南方火神诞"));
|
||||
put("6-24",Arrays.asList("雷祖诞","关帝诞"));
|
||||
put("7-1",Collections.nCopies(1,"杨公忌"));
|
||||
put("7-7",Collections.nCopies(1,"魁星诞"));
|
||||
put("7-13",Arrays.asList("长真谭真人诞","大势至菩萨诞"));
|
||||
put("7-12",Collections.nCopies(1,"长真谭真人诞"));
|
||||
put("7-13",Collections.nCopies(1,"大势至菩萨诞"));
|
||||
put("7-15",Collections.nCopies(1,"中元节"));
|
||||
put("7-18",Collections.nCopies(1,"西王母诞"));
|
||||
put("7-19",Collections.nCopies(1,"太岁诞"));
|
||||
@@ -212,31 +228,42 @@ public class LunarUtil{
|
||||
put("8-18",Collections.nCopies(1,"天人兴福之辰"));
|
||||
put("8-23",Collections.nCopies(1,"汉恒候张显王诞"));
|
||||
put("8-24",Collections.nCopies(1,"灶君夫人诞"));
|
||||
put("8-29",Collections.nCopies(1,"至圣先师孔子诞"));
|
||||
put("9-1",Collections.nCopies(1,"北斗九星降世"));
|
||||
put("9-3",Collections.nCopies(1,"五瘟神诞"));
|
||||
put("9-9",Collections.nCopies(1,"酆都大帝诞"));
|
||||
put("8-27",Arrays.asList("至圣先师孔子诞","杨公忌"));
|
||||
put("9-1",Collections.nCopies(1,"北斗九星降"));
|
||||
put("9-2",Collections.nCopies(1,"北斗九星降"));
|
||||
put("9-3",Arrays.asList("北斗九星降","五瘟神诞"));
|
||||
put("9-4",Collections.nCopies(1,"北斗九星降"));
|
||||
put("9-5",Collections.nCopies(1,"北斗九星降"));
|
||||
put("9-6",Collections.nCopies(1,"北斗九星降"));
|
||||
put("9-7",Collections.nCopies(1,"北斗九星降"));
|
||||
put("9-8",Collections.nCopies(1,"北斗九星降"));
|
||||
put("9-9",Arrays.asList("北斗九星降","酆都大帝诞"));
|
||||
put("9-13",Collections.nCopies(1,"孟婆尊神诞"));
|
||||
put("9-17",Collections.nCopies(1,"金龙四大王诞"));
|
||||
put("9-19",Collections.nCopies(1,"观世音菩萨出家"));
|
||||
put("9-25",Collections.nCopies(1,"杨公忌"));
|
||||
put("9-30",Collections.nCopies(1,"药师琉璃光佛诞"));
|
||||
put("10-1",Collections.nCopies(1,"寒衣节"));
|
||||
put("10-3",Collections.nCopies(1,"三茅诞"));
|
||||
put("10-5",Collections.nCopies(1,"达摩祖师诞"));
|
||||
put("10-8",Collections.nCopies(1,"佛涅槃日"));
|
||||
put("10-15",Collections.nCopies(1,"下元节"));
|
||||
put("10-23",Collections.nCopies(1,"杨公忌"));
|
||||
put("10-27",Collections.nCopies(1,"北极紫薇大帝降"));
|
||||
put("11-4",Collections.nCopies(1,"至圣先师孔子诞"));
|
||||
put("11-6",Collections.nCopies(1,"西岳大帝诞"));
|
||||
put("11-11",Collections.nCopies(1,"太乙救苦天尊诞"));
|
||||
put("11-17",Collections.nCopies(1,"阿弥陀佛诞"));
|
||||
put("11-19",Collections.nCopies(1,"太阳日宫诞"));
|
||||
put("11-21",Collections.nCopies(1,"杨公忌"));
|
||||
put("11-23",Collections.nCopies(1,"张仙诞"));
|
||||
put("11-25",Collections.nCopies(1,"掠刷大夫降"));
|
||||
put("11-26",Collections.nCopies(1,"北方五道诞"));
|
||||
put("12-8",Collections.nCopies(1,"释迦如来成佛之辰"));
|
||||
put("12-16",Collections.nCopies(1,"南岳大帝诞"));
|
||||
put("12-19",Collections.nCopies(1,"杨公忌"));
|
||||
put("12-21",Collections.nCopies(1,"天猷上帝诞"));
|
||||
put("12-23",Collections.nCopies(1,"小年"));
|
||||
put("12-24",Collections.nCopies(1,"子时灶君上天朝玉帝"));
|
||||
put("12-23",Arrays.asList("小年","五岳神降"));
|
||||
put("12-29",Collections.nCopies(1,"华严菩萨诞"));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -29,6 +29,12 @@ public class BaZiTest {
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
|
||||
eightChar.setSect(1);
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "辛丑", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
|
||||
|
||||
140
src/test/java/test/FuTest.java
Normal file
140
src/test/java/test/FuTest.java
Normal file
@@ -0,0 +1,140 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Fu;
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 三伏测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class FuTest {
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
Solar solar = new Solar(2011,7,14);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"初伏第1天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
Solar solar = new Solar(2011,7,23);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"初伏第10天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
Solar solar = new Solar(2011,7,24);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"中伏第1天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
Solar solar = new Solar(2011,8,12);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"中伏第20天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
Solar solar = new Solar(2011,8,13);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"末伏第1天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test6(){
|
||||
Solar solar = new Solar(2011,8,22);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"末伏第10天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7(){
|
||||
Solar solar = new Solar(2011,7,13);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertNull(solar.toYmd(),fu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test8(){
|
||||
Solar solar = new Solar(2011,8,23);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertNull(solar.toYmd(),fu);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test9(){
|
||||
Solar solar = new Solar(2012,7,18);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"初伏第1天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test10(){
|
||||
Solar solar = new Solar(2012,8,5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"中伏第9天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11(){
|
||||
Solar solar = new Solar(2012,8,8);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"末伏第2天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test12(){
|
||||
Solar solar = new Solar(2020,7,17);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"初伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"初伏第2天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test13(){
|
||||
Solar solar = new Solar(2020,7,26);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"中伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"中伏第1天",fu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test14(){
|
||||
Solar solar = new Solar(2020,8,24);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Fu fu = lunar.getFu();
|
||||
Assert.assertEquals(solar.toYmd(),"末伏",fu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"末伏第10天",fu.toFullString());
|
||||
}
|
||||
|
||||
}
|
||||
71
src/test/java/test/LiuYaoTest.java
Normal file
71
src/test/java/test/LiuYaoTest.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 六曜测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class LiuYaoTest {
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
Solar solar = new Solar(2020,4,23);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"佛灭",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
Solar solar = new Solar(2021,1,15);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"友引",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
Solar solar = new Solar(2017,1,5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"先胜",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
Solar solar = new Solar(2020,4,10);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"友引",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
Solar solar = new Solar(2020,6,11);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"大安",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test6(){
|
||||
Solar solar = new Solar(2020,6,1);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"先胜",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7(){
|
||||
Solar solar = new Solar(2020,12,8);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"先负",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test8(){
|
||||
Solar solar = new Solar(2020,12,11);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(lunar.toString(),"赤口",lunar.getLiuYao());
|
||||
}
|
||||
|
||||
}
|
||||
78
src/test/java/test/ShuJiuTest.java
Normal file
78
src/test/java/test/ShuJiuTest.java
Normal file
@@ -0,0 +1,78 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.ShuJiu;
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 数九测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class ShuJiuTest {
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
Solar solar = new Solar(2020,12,21);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.assertEquals(solar.toYmd(),"一九",shuJiu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"一九第1天",shuJiu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
Solar solar = new Solar(2020,12,22);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.assertEquals(solar.toYmd(),"一九",shuJiu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"一九第2天",shuJiu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
Solar solar = new Solar(2020,1,7);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.assertEquals(solar.toYmd(),"二九",shuJiu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"二九第8天",shuJiu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
Solar solar = new Solar(2021,1,6);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.assertEquals(solar.toYmd(),"二九",shuJiu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"二九第8天",shuJiu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
Solar solar = new Solar(2021,1,8);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.assertEquals(solar.toYmd(),"三九",shuJiu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"三九第1天",shuJiu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test6(){
|
||||
Solar solar = new Solar(2021,3,5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.assertEquals(solar.toYmd(),"九九",shuJiu.toString());
|
||||
Assert.assertEquals(solar.toYmd(),"九九第3天",shuJiu.toFullString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7(){
|
||||
Solar solar = new Solar(2021,7,5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
ShuJiu shuJiu = lunar.getShuJiu();
|
||||
Assert.assertNull(solar.toYmd(),shuJiu);
|
||||
}
|
||||
|
||||
}
|
||||
71
src/test/java/test/WuHouTest.java
Normal file
71
src/test/java/test/WuHouTest.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Lunar;
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 物候测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class WuHouTest {
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
Solar solar = new Solar(2020,4,23);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"萍始生",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
Solar solar = new Solar(2021,1,15);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"雉始雊",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
Solar solar = new Solar(2017,1,5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"雁北乡",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
Solar solar = new Solar(2020,4,10);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"田鼠化为鴽",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
Solar solar = new Solar(2020,6,11);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"鵙始鸣",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test6(){
|
||||
Solar solar = new Solar(2020,6,1);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"麦秋至",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7(){
|
||||
Solar solar = new Solar(2020,12,8);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"鹖鴠不鸣",lunar.getWuHou());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test8(){
|
||||
Solar solar = new Solar(2020,12,11);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals(solar.toString(),"鹖鴠不鸣",lunar.getWuHou());
|
||||
}
|
||||
|
||||
}
|
||||
110
src/test/java/test/XingZuoTest.java
Normal file
110
src/test/java/test/XingZuoTest.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Solar;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 阳历测试
|
||||
*
|
||||
* @author 6tail
|
||||
*/
|
||||
public class XingZuoTest {
|
||||
|
||||
@Test
|
||||
public void test1(){
|
||||
Solar solar = new Solar(2020,3,21);
|
||||
Assert.assertEquals(solar.toYmd(),"白羊",solar.getXingZuo());
|
||||
solar = new Solar(2020,4,19);
|
||||
Assert.assertEquals(solar.toYmd(),"白羊",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2(){
|
||||
Solar solar = new Solar(2020,4,20);
|
||||
Assert.assertEquals(solar.toYmd(),"金牛",solar.getXingZuo());
|
||||
solar = new Solar(2020,5,20);
|
||||
Assert.assertEquals(solar.toYmd(),"金牛",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3(){
|
||||
Solar solar = new Solar(2020,5,21);
|
||||
Assert.assertEquals(solar.toYmd(),"双子",solar.getXingZuo());
|
||||
solar = new Solar(2020,6,21);
|
||||
Assert.assertEquals(solar.toYmd(),"双子",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4(){
|
||||
Solar solar = new Solar(2020,6,22);
|
||||
Assert.assertEquals(solar.toYmd(),"巨蟹",solar.getXingZuo());
|
||||
solar = new Solar(2020,7,22);
|
||||
Assert.assertEquals(solar.toYmd(),"巨蟹",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5(){
|
||||
Solar solar = new Solar(2020,7,23);
|
||||
Assert.assertEquals(solar.toYmd(),"狮子",solar.getXingZuo());
|
||||
solar = new Solar(2020,8,22);
|
||||
Assert.assertEquals(solar.toYmd(),"狮子",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test6(){
|
||||
Solar solar = new Solar(2020,8,23);
|
||||
Assert.assertEquals(solar.toYmd(),"处女",solar.getXingZuo());
|
||||
solar = new Solar(2020,9,22);
|
||||
Assert.assertEquals(solar.toYmd(),"处女",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test7(){
|
||||
Solar solar = new Solar(2020,9,23);
|
||||
Assert.assertEquals(solar.toYmd(),"天秤",solar.getXingZuo());
|
||||
solar = new Solar(2020,10,23);
|
||||
Assert.assertEquals(solar.toYmd(),"天秤",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test8(){
|
||||
Solar solar = new Solar(2020,10,24);
|
||||
Assert.assertEquals(solar.toYmd(),"天蝎",solar.getXingZuo());
|
||||
solar = new Solar(2020,11,22);
|
||||
Assert.assertEquals(solar.toYmd(),"天蝎",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test9(){
|
||||
Solar solar = new Solar(2020,11,23);
|
||||
Assert.assertEquals(solar.toYmd(),"射手",solar.getXingZuo());
|
||||
solar = new Solar(2020,12,21);
|
||||
Assert.assertEquals(solar.toYmd(),"射手",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test10(){
|
||||
Solar solar = new Solar(2020,12,22);
|
||||
Assert.assertEquals(solar.toYmd(),"摩羯",solar.getXingZuo());
|
||||
solar = new Solar(2021,1,19);
|
||||
Assert.assertEquals(solar.toYmd(),"摩羯",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11(){
|
||||
Solar solar = new Solar(2021,1,20);
|
||||
Assert.assertEquals(solar.toYmd(),"水瓶",solar.getXingZuo());
|
||||
solar = new Solar(2021,2,18);
|
||||
Assert.assertEquals(solar.toYmd(),"水瓶",solar.getXingZuo());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test12(){
|
||||
Solar solar = new Solar(2021,2,19);
|
||||
Assert.assertEquals(solar.toYmd(),"双鱼",solar.getXingZuo());
|
||||
solar = new Solar(2021,3,20);
|
||||
Assert.assertEquals(solar.toYmd(),"双鱼",solar.getXingZuo());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user