Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee0b227f75 | ||
|
|
a16767e2c7 | ||
|
|
dc0c03ff09 | ||
|
|
1aefcdcf0c | ||
|
|
5d589eb957 | ||
|
|
3415fc04a4 |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.2.21</version>
|
||||
<version>1.2.25</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.2.21</version>
|
||||
<version>1.2.25</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
11
pom.xml
11
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.21</version>
|
||||
<version>1.2.25</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>
|
||||
@@ -48,6 +48,7 @@
|
||||
<sourceEncoding>UTF-8</sourceEncoding>
|
||||
<source-version>1.5</source-version>
|
||||
<target-version>1.5</target-version>
|
||||
<creator>6tail</creator>
|
||||
<maven-compiler-plugin-version>3.3</maven-compiler-plugin-version>
|
||||
<maven-surefire-plugin-version>2.5</maven-surefire-plugin-version>
|
||||
<maven-javadoc-plugin-version>2.9</maven-javadoc-plugin-version>
|
||||
@@ -60,7 +61,7 @@
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.13.1</version>
|
||||
<version>4.13.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
@@ -154,6 +155,12 @@
|
||||
<descriptors>
|
||||
<descriptor>${basedir}/src/assembly/assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
<archive>
|
||||
<manifestEntries>
|
||||
<Created-By>${creator}</Created-By>
|
||||
<Built-By>${creator}</Built-By>
|
||||
</manifestEntries>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
@@ -474,6 +474,26 @@ public class EightChar {
|
||||
return LunarUtil.NAYIN.get(getTaiYuan());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取胎息
|
||||
*
|
||||
* @return 胎息
|
||||
*/
|
||||
public String getTaiXi() {
|
||||
int ganIndex = (2 == sect) ? lunar.getDayGanIndexExact2() : lunar.getDayGanIndexExact();
|
||||
int zhiIndex = (2 == sect) ? lunar.getDayZhiIndexExact2() : lunar.getDayZhiIndexExact();
|
||||
return LunarUtil.HE_GAN_5[ganIndex] + LunarUtil.HE_ZHI_6[zhiIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取胎息纳音
|
||||
*
|
||||
* @return 纳音
|
||||
*/
|
||||
public String getTaiXiNaYin() {
|
||||
return LunarUtil.NAYIN.get(getTaiXi());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取命宫
|
||||
*
|
||||
@@ -531,7 +551,10 @@ public class EightChar {
|
||||
timeZhiIndex = i;
|
||||
}
|
||||
}
|
||||
int zhiIndex = (2 + (monthZhiIndex + timeZhiIndex)) % 12;
|
||||
int zhiIndex = 2 + monthZhiIndex + timeZhiIndex;
|
||||
if (zhiIndex > 12) {
|
||||
zhiIndex -= 12;
|
||||
}
|
||||
int jiaZiIndex = LunarUtil.getJiaZiIndex(lunar.getMonthInGanZhiExact()) - (monthZhiIndex - zhiIndex);
|
||||
if (jiaZiIndex >= 60) {
|
||||
jiaZiIndex -= 60;
|
||||
|
||||
@@ -18,6 +18,7 @@ public class ExactDate {
|
||||
*/
|
||||
private static final TimeZone TIME_ZONE = TimeZone.getTimeZone("GMT+8");
|
||||
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public static Calendar fromYmdHms(int year, int month, int day, int hour, int minute, int second) {
|
||||
Calendar c = Calendar.getInstance(TIME_ZONE);
|
||||
c.set(year, month - 1, day, hour, minute, second);
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Foto {
|
||||
/**
|
||||
* 阴历
|
||||
*/
|
||||
private Lunar lunar;
|
||||
private final Lunar lunar;
|
||||
|
||||
public Foto(Lunar lunar) {
|
||||
this.lunar = lunar;
|
||||
@@ -228,7 +228,7 @@ public class Foto {
|
||||
|
||||
public String toFullString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(toString());
|
||||
s.append(this);
|
||||
for (FotoFestival f : getFestivals()) {
|
||||
s.append(" (");
|
||||
s.append(f);
|
||||
|
||||
@@ -10,22 +10,22 @@ public class FotoFestival {
|
||||
/**
|
||||
* 是日何日,如:雷斋日
|
||||
*/
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* 犯之因果,如:犯者夺纪
|
||||
*/
|
||||
private String result;
|
||||
private final String result;
|
||||
|
||||
/**
|
||||
* 是否每月同
|
||||
*/
|
||||
private boolean everyMonth;
|
||||
private final boolean everyMonth;
|
||||
|
||||
/**
|
||||
* 备注,如:宜先一日即戒
|
||||
*/
|
||||
private String remark;
|
||||
private final String remark;
|
||||
|
||||
public FotoFestival(String name, String result, boolean everyMonth, String remark) {
|
||||
this.name = name;
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Lunar {
|
||||
/**
|
||||
* 对应阳历
|
||||
*/
|
||||
private Solar solar;
|
||||
private final Solar solar;
|
||||
/**
|
||||
* 时对应的天干下标,0-9
|
||||
*/
|
||||
@@ -116,15 +116,15 @@ public class Lunar {
|
||||
/**
|
||||
* 阳历小时
|
||||
*/
|
||||
private int hour;
|
||||
private final int hour;
|
||||
/**
|
||||
* 阳历分钟
|
||||
*/
|
||||
private int minute;
|
||||
private final int minute;
|
||||
/**
|
||||
* 阳历秒钟
|
||||
*/
|
||||
private int second;
|
||||
private final int second;
|
||||
/**
|
||||
* 八字
|
||||
*/
|
||||
@@ -132,7 +132,7 @@ public class Lunar {
|
||||
/**
|
||||
* 24节气表(对应阳历的准确时刻)
|
||||
*/
|
||||
private Map<String, Solar> jieQi = new LinkedHashMap<String, Solar>();
|
||||
private final Map<String, Solar> jieQi = new LinkedHashMap<String, Solar>();
|
||||
|
||||
/**
|
||||
* 默认使用当前日期初始化
|
||||
@@ -183,6 +183,9 @@ public class Lunar {
|
||||
this.second = second;
|
||||
Solar noon = Solar.fromJulianDay(m.getFirstJulianDay() + lunarDay - 1);
|
||||
this.solar = Solar.fromYmdHms(noon.getYear(), noon.getMonth(), noon.getDay(), hour, minute, second);
|
||||
if (noon.getYear() != lunarYear) {
|
||||
y = LunarYear.fromYear(noon.getYear());
|
||||
}
|
||||
compute(y);
|
||||
}
|
||||
|
||||
@@ -191,7 +194,6 @@ public class Lunar {
|
||||
*
|
||||
* @param date 阳历日期
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public Lunar(Date date) {
|
||||
solar = new Solar(date);
|
||||
int currentYear = solar.getYear();
|
||||
@@ -968,9 +970,27 @@ public class Lunar {
|
||||
if (null != fs) {
|
||||
l.addAll(fs);
|
||||
}
|
||||
if (solar.toYmd().equals(jieQi.get("清明").next(-1).toYmd())) {
|
||||
String solarYmd = solar.toYmd();
|
||||
if (solarYmd.equals(jieQi.get("清明").next(-1).toYmd())) {
|
||||
l.add("寒食节");
|
||||
}
|
||||
Solar jq = jieQi.get("立春");
|
||||
int offset = 4 - jq.getLunar().getDayGanIndex();
|
||||
if (offset < 0) {
|
||||
offset += 10;
|
||||
}
|
||||
if (solarYmd.equals(jq.next(offset + 40).toYmd())) {
|
||||
l.add("春社");
|
||||
}
|
||||
|
||||
jq = jieQi.get("立秋");
|
||||
offset = 4 - jq.getLunar().getDayGanIndex();
|
||||
if (offset < 0) {
|
||||
offset += 10;
|
||||
}
|
||||
if (solarYmd.equals(jq.next(offset + 40).toYmd())) {
|
||||
l.add("秋社");
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -1292,14 +1312,12 @@ public class Lunar {
|
||||
public String getMonthPositionTaiSui(int sect) {
|
||||
int monthZhiIndex;
|
||||
int monthGanIndex;
|
||||
switch (sect) {
|
||||
case 3:
|
||||
monthZhiIndex = this.monthZhiIndexExact;
|
||||
monthGanIndex = this.monthGanIndexExact;
|
||||
break;
|
||||
default:
|
||||
monthZhiIndex = this.monthZhiIndex;
|
||||
monthGanIndex = this.monthGanIndex;
|
||||
if (sect == 3) {
|
||||
monthZhiIndex = this.monthZhiIndexExact;
|
||||
monthGanIndex = this.monthGanIndexExact;
|
||||
} else {
|
||||
monthZhiIndex = this.monthZhiIndex;
|
||||
monthGanIndex = this.monthGanIndex;
|
||||
}
|
||||
return getMonthPositionTaiSui(monthZhiIndex, monthGanIndex);
|
||||
}
|
||||
@@ -1889,7 +1907,7 @@ public class Lunar {
|
||||
* @return 日冲,如申
|
||||
*/
|
||||
public String getDayChong() {
|
||||
return LunarUtil.CHONG[dayZhiIndex + 1];
|
||||
return LunarUtil.CHONG[dayZhiIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1931,7 +1949,7 @@ public class Lunar {
|
||||
* @return 无情之克的日冲天干,如甲
|
||||
*/
|
||||
public String getDayChongGan() {
|
||||
return LunarUtil.CHONG_GAN[dayGanIndex + 1];
|
||||
return LunarUtil.CHONG_GAN[dayGanIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1940,7 +1958,7 @@ public class Lunar {
|
||||
* @return 有情之克的日冲天干,如甲
|
||||
*/
|
||||
public String getDayChongGanTie() {
|
||||
return LunarUtil.CHONG_GAN_TIE[dayGanIndex + 1];
|
||||
return LunarUtil.CHONG_GAN_TIE[dayGanIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1949,7 +1967,7 @@ public class Lunar {
|
||||
* @return 时冲,如申
|
||||
*/
|
||||
public String getTimeChong() {
|
||||
return LunarUtil.CHONG[timeZhiIndex + 1];
|
||||
return LunarUtil.CHONG[timeZhiIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1991,7 +2009,7 @@ public class Lunar {
|
||||
* @return 无情之克的时冲天干,如甲
|
||||
*/
|
||||
public String getTimeChongGan() {
|
||||
return LunarUtil.CHONG_GAN[timeGanIndex + 1];
|
||||
return LunarUtil.CHONG_GAN[timeGanIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2000,7 +2018,7 @@ public class Lunar {
|
||||
* @return 有情之克的时冲天干,如甲
|
||||
*/
|
||||
public String getTimeChongGanTie() {
|
||||
return LunarUtil.CHONG_GAN_TIE[timeGanIndex + 1];
|
||||
return LunarUtil.CHONG_GAN_TIE[timeGanIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2458,7 +2476,7 @@ public class Lunar {
|
||||
|
||||
public String toFullString() {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append(toString());
|
||||
s.append(this);
|
||||
s.append(" ");
|
||||
s.append(getYearInGanZhi());
|
||||
s.append("(");
|
||||
@@ -2862,7 +2880,6 @@ public class Lunar {
|
||||
*
|
||||
* @return 数九,如果不是数九天,返回null
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public ShuJiu getShuJiu() {
|
||||
Calendar currentCalendar = ExactDate.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay());
|
||||
Solar start = jieQi.get("DONG_ZHI");
|
||||
@@ -2889,7 +2906,6 @@ public class Lunar {
|
||||
*
|
||||
* @return 三伏,如果不是伏天,返回null
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public Fu getFu() {
|
||||
Calendar currentCalendar = ExactDate.fromYmd(solar.getYear(), solar.getMonth(), solar.getDay());
|
||||
Solar xiaZhi = jieQi.get("夏至");
|
||||
@@ -2962,7 +2978,6 @@ public class Lunar {
|
||||
*
|
||||
* @return 物候
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public String getWuHou() {
|
||||
JieQi jieQi = getPrevJieQi(true);
|
||||
String name = jieQi.getName();
|
||||
|
||||
@@ -14,22 +14,22 @@ public class LunarMonth {
|
||||
/**
|
||||
* 农历年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 农历月:1-12,闰月为负数,如闰2月为-2
|
||||
*/
|
||||
private int month;
|
||||
private final int month;
|
||||
|
||||
/**
|
||||
* 天数,大月30天,小月29天
|
||||
*/
|
||||
private int dayCount;
|
||||
private final int dayCount;
|
||||
|
||||
/**
|
||||
* 初一的儒略日
|
||||
*/
|
||||
private double firstJulianDay;
|
||||
private final double firstJulianDay;
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
|
||||
@@ -15,17 +15,17 @@ public class LunarTime {
|
||||
/**
|
||||
* 天干下标,0-9
|
||||
*/
|
||||
private int ganIndex;
|
||||
private final int ganIndex;
|
||||
|
||||
/**
|
||||
* 地支下标,0-11
|
||||
*/
|
||||
private int zhiIndex;
|
||||
private final int zhiIndex;
|
||||
|
||||
/**
|
||||
* 阴历
|
||||
*/
|
||||
private Lunar lunar;
|
||||
private final 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);
|
||||
@@ -235,7 +235,7 @@ public class LunarTime {
|
||||
* @return 时冲,如申
|
||||
*/
|
||||
public String getChong() {
|
||||
return LunarUtil.CHONG[zhiIndex + 1];
|
||||
return LunarUtil.CHONG[zhiIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -277,7 +277,7 @@ public class LunarTime {
|
||||
* @return 无情之克的时冲天干,如甲
|
||||
*/
|
||||
public String getChongGan() {
|
||||
return LunarUtil.CHONG_GAN[ganIndex + 1];
|
||||
return LunarUtil.CHONG_GAN[ganIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -286,7 +286,7 @@ public class LunarTime {
|
||||
* @return 有情之克的时冲天干,如甲
|
||||
*/
|
||||
public String getChongGanTie() {
|
||||
return LunarUtil.CHONG_GAN_TIE[ganIndex + 1];
|
||||
return LunarUtil.CHONG_GAN_TIE[ganIndex];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -316,10 +316,7 @@ public class LunarTime {
|
||||
//顺逆
|
||||
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;
|
||||
}
|
||||
boolean asc = solarYmd.compareTo(jieQi.get("冬至").toYmd()) >= 0 && solarYmd.compareTo(jieQi.get("夏至").toYmd()) < 0;
|
||||
int start = asc ? 7 : 3;
|
||||
String dayZhi = lunar.getDayZhi();
|
||||
if ("子午卯酉".contains(dayZhi)) {
|
||||
|
||||
@@ -50,27 +50,27 @@ public class LunarYear {
|
||||
/**
|
||||
* 农历年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 天干下标
|
||||
*/
|
||||
private int ganIndex;
|
||||
private final int ganIndex;
|
||||
|
||||
/**
|
||||
* 地支下标
|
||||
*/
|
||||
private int zhiIndex;
|
||||
private final int zhiIndex;
|
||||
|
||||
/**
|
||||
* 农历月们
|
||||
*/
|
||||
private List<LunarMonth> months = new ArrayList<LunarMonth>();
|
||||
private final List<LunarMonth> months = new ArrayList<LunarMonth>();
|
||||
|
||||
/**
|
||||
* 节气儒略日们
|
||||
*/
|
||||
private List<Double> jieQiJulianDays = new ArrayList<Double>();
|
||||
private final List<Double> jieQiJulianDays = new ArrayList<Double>();
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
|
||||
@@ -19,34 +19,41 @@ public class Solar {
|
||||
* 2000年儒略日数(2000-1-1 12:00:00 UTC)
|
||||
*/
|
||||
public static final double J2000 = 2451545;
|
||||
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 月
|
||||
*/
|
||||
private int month;
|
||||
private final int month;
|
||||
|
||||
/**
|
||||
* 日
|
||||
*/
|
||||
private int day;
|
||||
private final int day;
|
||||
|
||||
/**
|
||||
* 时
|
||||
*/
|
||||
private int hour;
|
||||
private final int hour;
|
||||
|
||||
/**
|
||||
* 分
|
||||
*/
|
||||
private int minute;
|
||||
private final int minute;
|
||||
|
||||
/**
|
||||
* 秒
|
||||
*/
|
||||
private int second;
|
||||
private final int second;
|
||||
|
||||
/**
|
||||
* 日历
|
||||
*/
|
||||
private Calendar calendar;
|
||||
private final Calendar calendar;
|
||||
|
||||
/**
|
||||
* 默认使用当前日期初始化
|
||||
@@ -76,7 +83,6 @@ public class Solar {
|
||||
* @param minute 分钟,0到59
|
||||
* @param second 秒钟,0到59
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public Solar(int year, int month, int day, int hour, int minute, int second) {
|
||||
calendar = ExactDate.fromYmdHms(year, month, day, hour, minute, second);
|
||||
this.year = year;
|
||||
@@ -123,7 +129,6 @@ public class Solar {
|
||||
*
|
||||
* @param julianDay 儒略日
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public Solar(double julianDay) {
|
||||
int d = (int) (julianDay + 0.5);
|
||||
double f = julianDay + 0.5 - d;
|
||||
@@ -381,6 +386,12 @@ public class Solar {
|
||||
if (null != f) {
|
||||
l.add(f);
|
||||
}
|
||||
if (day + 7 > SolarUtil.getDaysOfMonth(year, month)) {
|
||||
f = SolarUtil.WEEK_FESTIVAL.get(month + "-0-" + week);
|
||||
if (null != f) {
|
||||
l.add(f);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
@@ -515,10 +526,7 @@ public class Solar {
|
||||
int m = this.month;
|
||||
double d = this.day + ((this.second * 1D / 60 + this.minute) / 60 + this.hour) / 24;
|
||||
int n = 0;
|
||||
boolean g = false;
|
||||
if (y * 372 + m * 31 + (int) d >= 588829) {
|
||||
g = true;
|
||||
}
|
||||
boolean g = y * 372 + m * 31 + (int) d >= 588829;
|
||||
if (m <= 2) {
|
||||
m += 12;
|
||||
y--;
|
||||
@@ -595,7 +603,6 @@ public class Solar {
|
||||
* @param onlyWorkday 是否仅限工作日
|
||||
* @return 阳历日期
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public Solar next(int days, boolean onlyWorkday) {
|
||||
Calendar c = ExactDate.fromYmdHms(year, month, day, hour, minute, second);
|
||||
if (0 != days) {
|
||||
|
||||
@@ -14,11 +14,11 @@ public class SolarHalfYear {
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
/**
|
||||
* 月
|
||||
*/
|
||||
private int month;
|
||||
private final int month;
|
||||
|
||||
/**
|
||||
* 半年的月数
|
||||
@@ -124,7 +124,6 @@ public class SolarHalfYear {
|
||||
* @param halfYears 推移的半年数,负数为倒推
|
||||
* @return 推移后的半年
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public SolarHalfYear next(int halfYears) {
|
||||
if (0 == halfYears) {
|
||||
return new SolarHalfYear(year, month);
|
||||
|
||||
@@ -16,11 +16,11 @@ public class SolarMonth {
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
/**
|
||||
* 月
|
||||
*/
|
||||
private int month;
|
||||
private final int month;
|
||||
|
||||
/**
|
||||
* 默认当月
|
||||
@@ -128,7 +128,6 @@ public class SolarMonth {
|
||||
* @param months 月数
|
||||
* @return 阳历月
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public SolarMonth next(int months) {
|
||||
Calendar c = ExactDate.fromYmd(year, month, 1);
|
||||
c.add(Calendar.MONTH, months);
|
||||
|
||||
@@ -14,11 +14,13 @@ public class SolarSeason {
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 月
|
||||
*/
|
||||
private int month;
|
||||
private final int month;
|
||||
|
||||
/**
|
||||
* 一个季度的月数
|
||||
*/
|
||||
|
||||
@@ -16,19 +16,22 @@ public class SolarWeek {
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 月
|
||||
*/
|
||||
private int month;
|
||||
private final int month;
|
||||
|
||||
/**
|
||||
* 日
|
||||
*/
|
||||
private int day;
|
||||
private final int day;
|
||||
|
||||
/**
|
||||
* 星期几作为一周的开始,1234560分别代表星期一至星期天
|
||||
*/
|
||||
private int start;
|
||||
private final int start;
|
||||
|
||||
/**
|
||||
* 默认当月
|
||||
@@ -187,7 +190,6 @@ public class SolarWeek {
|
||||
* @param separateMonth 是否按月单独计算
|
||||
* @return 推移后的阳历周
|
||||
*/
|
||||
@SuppressWarnings("MagicConstant")
|
||||
public SolarWeek next(int weeks, boolean separateMonth) {
|
||||
if (0 == weeks) {
|
||||
return new SolarWeek(year, month, day, start);
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SolarYear {
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 一年的月数
|
||||
|
||||
@@ -18,7 +18,7 @@ public class Tao {
|
||||
/**
|
||||
* 阴历
|
||||
*/
|
||||
private Lunar lunar;
|
||||
private final Lunar lunar;
|
||||
|
||||
public Tao(Lunar lunar) {
|
||||
this.lunar = lunar;
|
||||
|
||||
@@ -10,12 +10,12 @@ public class TaoFestival {
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
private String name;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
private final String remark;
|
||||
|
||||
public TaoFestival(String name, String remark) {
|
||||
this.name = name;
|
||||
|
||||
@@ -12,28 +12,34 @@ public class DaYun {
|
||||
/**
|
||||
* 开始年(含)
|
||||
*/
|
||||
private int startYear;
|
||||
private final int startYear;
|
||||
|
||||
/**
|
||||
* 结束年(含)
|
||||
*/
|
||||
private int endYear;
|
||||
private final int endYear;
|
||||
|
||||
/**
|
||||
* 开始年龄(含)
|
||||
*/
|
||||
private int startAge;
|
||||
private final int startAge;
|
||||
|
||||
/**
|
||||
* 结束年龄(含)
|
||||
*/
|
||||
private int endAge;
|
||||
private final int endAge;
|
||||
|
||||
/**
|
||||
* 序数,0-9
|
||||
*/
|
||||
private int index;
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* 运
|
||||
*/
|
||||
private Yun yun;
|
||||
private Lunar lunar;
|
||||
private final Yun yun;
|
||||
|
||||
private final Lunar lunar;
|
||||
|
||||
public DaYun(Yun yun, int index) {
|
||||
this.yun = yun;
|
||||
|
||||
@@ -12,20 +12,24 @@ public class LiuNian {
|
||||
/**
|
||||
* 序数,0-9
|
||||
*/
|
||||
private int index;
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* 大运
|
||||
*/
|
||||
private DaYun daYun;
|
||||
private final DaYun daYun;
|
||||
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
private int age;
|
||||
private Lunar lunar;
|
||||
private final int age;
|
||||
|
||||
private final Lunar lunar;
|
||||
|
||||
public LiuNian(DaYun daYun, int index) {
|
||||
this.daYun = daYun;
|
||||
|
||||
@@ -11,8 +11,9 @@ public class LiuYue {
|
||||
/**
|
||||
* 序数,0-9
|
||||
*/
|
||||
private int index;
|
||||
private LiuNian liuNian;
|
||||
private final int index;
|
||||
|
||||
private final LiuNian liuNian;
|
||||
|
||||
public LiuYue(LiuNian liuNian, int index) {
|
||||
this.liuNian = liuNian;
|
||||
|
||||
@@ -12,24 +12,29 @@ public class XiaoYun {
|
||||
/**
|
||||
* 序数,0-9
|
||||
*/
|
||||
private int index;
|
||||
private final int index;
|
||||
|
||||
/**
|
||||
* 大运
|
||||
*/
|
||||
private DaYun daYun;
|
||||
private final DaYun daYun;
|
||||
|
||||
/**
|
||||
* 年
|
||||
*/
|
||||
private int year;
|
||||
private final int year;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
private int age;
|
||||
private final int age;
|
||||
|
||||
/**
|
||||
* 是否顺推
|
||||
*/
|
||||
private boolean forward;
|
||||
private Lunar lunar;
|
||||
private final boolean forward;
|
||||
|
||||
private final Lunar lunar;
|
||||
|
||||
public XiaoYun(DaYun daYun, int index, boolean forward) {
|
||||
this.daYun = daYun;
|
||||
|
||||
@@ -14,7 +14,7 @@ public class Yun {
|
||||
/**
|
||||
* 性别(1男,0女)
|
||||
*/
|
||||
private int gender;
|
||||
private final int gender;
|
||||
|
||||
/**
|
||||
* 起运年数
|
||||
@@ -39,9 +39,9 @@ public class Yun {
|
||||
/**
|
||||
* 是否顺推
|
||||
*/
|
||||
private boolean forward;
|
||||
private final boolean forward;
|
||||
|
||||
private Lunar lunar;
|
||||
private final Lunar lunar;
|
||||
|
||||
/**
|
||||
* 使用默认流派1初始化运
|
||||
|
||||
@@ -17,6 +17,8 @@ public class HolidayUtil {
|
||||
private static final int SIZE = 18;
|
||||
/** 0 */
|
||||
private static final char ZERO = '0';
|
||||
/** 删除标识 */
|
||||
private static final String TAG_REMOVE = "~";
|
||||
/** 默认节假日名称(元旦0,春节1,清明2,劳动3,端午4,中秋5,国庆6,国庆中秋7,抗战胜利日8) */
|
||||
public static final String[] NAMES = {"元旦节","春节","清明节","劳动节","端午节","中秋节","国庆节","国庆中秋","抗战胜利日"};
|
||||
/** 默认节假日数据,日期YYYYMMDD+名称下标+是否调休+对应节日YYYYMMDD */
|
||||
@@ -188,35 +190,38 @@ public class HolidayUtil {
|
||||
* @param data 需要修正或追加的节假日数据,每18位表示1天依次排列,格式:当天年月日YYYYMMDD(8位)+节假日名称下标(1位)+调休标识(1位)+节假日当天YYYYMMDD(8位)。例:202005023120200501代表2020-05-02为劳动节放假,对应节假日为2020-05-01
|
||||
*/
|
||||
public static void fix(String[] names, String data){
|
||||
if(null!=names){
|
||||
if(null != names){
|
||||
NAMES_IN_USE = names;
|
||||
}
|
||||
if(null==data){
|
||||
if(null == data){
|
||||
return;
|
||||
}
|
||||
StringBuilder append = new StringBuilder();
|
||||
while(data.length()>=SIZE){
|
||||
String segment = data.substring(0,SIZE);
|
||||
String day = segment.substring(0,8);
|
||||
while(data.length() >= SIZE){
|
||||
String segment = data.substring(0, SIZE);
|
||||
String day = segment.substring(0, 8);
|
||||
boolean remove = TAG_REMOVE.equals(segment.substring(8, 9));
|
||||
Holiday holiday = getHoliday(day);
|
||||
if(null==holiday){
|
||||
append.append(segment);
|
||||
if(null == holiday){
|
||||
if (!remove) {
|
||||
append.append(segment);
|
||||
}
|
||||
}else{
|
||||
int nameIndex = -1;
|
||||
for(int i=0,j=NAMES_IN_USE.length;i<j;i++){
|
||||
for(int i = 0,j = NAMES_IN_USE.length; i < j; i++){
|
||||
if(NAMES_IN_USE[i].equals(holiday.getName())){
|
||||
nameIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(nameIndex>-1) {
|
||||
String old = day+(char)(nameIndex+ZERO)+(holiday.isWork()?ZERO:'1')+holiday.getTarget().replace("-","");
|
||||
DATA_IN_USE = DATA_IN_USE.replace(old, segment);
|
||||
String old = day + (char)(nameIndex + ZERO) + (holiday.isWork() ? ZERO : '1') + holiday.getTarget().replace("-","");
|
||||
DATA_IN_USE = DATA_IN_USE.replace(old, remove ? "" : segment);
|
||||
}
|
||||
}
|
||||
data = data.substring(SIZE);
|
||||
}
|
||||
if(append.length()>0){
|
||||
if(append.length() > 0){
|
||||
DATA_IN_USE += append.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class LunarUtil{
|
||||
put("1-25",Collections.nCopies(1,"填仓节"));
|
||||
put("1-30",Collections.nCopies(1,"正月晦"));
|
||||
put("2-1",Collections.nCopies(1,"中和节"));
|
||||
put("2-2",Collections.nCopies(1,"春社"));
|
||||
put("2-2",Collections.nCopies(1,"社日节"));
|
||||
put("3-3",Collections.nCopies(1,"上巳节"));
|
||||
put("5-20",Collections.nCopies(1,"分龙节"));
|
||||
put("5-25",Collections.nCopies(1,"会龙节"));
|
||||
@@ -351,32 +351,17 @@ public class LunarUtil{
|
||||
}
|
||||
};
|
||||
/** 地支相冲(子午相冲,丑未相冲,寅申相冲,辰戌相冲,卯酉相冲,巳亥相冲),由于地支对应十二生肖,也就对应了生肖相冲 */
|
||||
public static final String[] CHONG = {"","午","未","申","酉","戌","亥","子","丑","寅","卯","辰","巳"};
|
||||
public static final String[] CHONG = {"午","未","申","酉","戌","亥","子","丑","寅","卯","辰","巳"};
|
||||
/** 天干相冲之无情之克(阳克阳,阴克阴) */
|
||||
public static final String[] CHONG_GAN = {"","戊","己","庚","辛","壬","癸","甲","乙","丙","丁"};
|
||||
/** 天干四冲(无情之克中克得最严重的4个) */
|
||||
public static final Map<String,String> CHONG_GAN_BAD = new HashMap<String,String>(){
|
||||
private static final long serialVersionUID = -1;
|
||||
{
|
||||
put("庚","甲");
|
||||
put("辛","乙");
|
||||
put("壬","丙");
|
||||
put("癸","丁");
|
||||
}
|
||||
};
|
||||
public static final String[] CHONG_GAN = {"戊","己","庚","辛","壬","癸","甲","乙","丙","丁"};
|
||||
/** 天干相冲之有情之克(阳克阴,阴克阳) */
|
||||
public static final String[] CHONG_GAN_TIE = {"","己","戊","辛","庚","癸","壬","乙","甲","丁","丙"};
|
||||
/** 天干五合(有情之克中最有情的5个) */
|
||||
public static final Map<String,String> CHONG_GAN_TIE_GOOD = new HashMap<String,String>(){
|
||||
private static final long serialVersionUID = -1;
|
||||
{
|
||||
put("甲","己");
|
||||
put("丙","辛");
|
||||
put("戊","癸");
|
||||
put("庚","乙");
|
||||
put("壬","丁");
|
||||
}
|
||||
};
|
||||
public static final String[] CHONG_GAN_TIE = {"己","戊","辛","庚","癸","壬","乙","甲","丁","丙"};
|
||||
/** 天干四冲(无情之克中克得最严重的4个) */
|
||||
public static final String[] CHONG_GAN_4 = {"庚","辛","壬","癸","","","甲","乙","丙","丁"};
|
||||
/** 天干五合(有情之克中最有情的5个,甲己合,乙庚合,丙辛合,丁壬合,戊癸合) */
|
||||
public static final String[] HE_GAN_5 = {"己","庚","辛","壬","癸","甲","乙","丙","丁","戊"};
|
||||
/** 地支六合(子丑合,寅亥合,卯戌合,辰酉合,巳申合,午未合) */
|
||||
public static final String[] HE_ZHI_6 = {"丑","子","亥","戌","酉","申","未","午","巳","辰","卯","寅"};
|
||||
/** 煞(逢巳日、酉日、丑日必煞东;亥日、卯日、未日必煞西;申日、子日、辰日必煞南;寅日、午日、戌日必煞北) */
|
||||
public static final Map<String,String> SHA = new HashMap<String,String>(){
|
||||
private static final long serialVersionUID = -1;
|
||||
|
||||
@@ -42,6 +42,8 @@ public class SolarUtil {
|
||||
put("8-1", "建军节");
|
||||
put("9-10", "教师节");
|
||||
put("10-1", "国庆节");
|
||||
put("10-31", "万圣节前夜");
|
||||
put("11-1", "万圣节");
|
||||
put("12-24", "平安夜");
|
||||
put("12-25", "圣诞节");
|
||||
}
|
||||
@@ -53,6 +55,7 @@ public class SolarUtil {
|
||||
private static final long serialVersionUID = -1;
|
||||
|
||||
{
|
||||
put("3-0-1", "全国中小学生安全教育日");
|
||||
put("5-2-0", "母亲节");
|
||||
put("6-3-0", "父亲节");
|
||||
put("11-4-4", "感恩节");
|
||||
@@ -97,6 +100,7 @@ public class SolarUtil {
|
||||
put("5-5", Collections.nCopies(1, "马克思诞辰纪念日"));
|
||||
put("5-8", Collections.nCopies(1, "世界红十字日"));
|
||||
put("5-11", Collections.nCopies(1, "世界肥胖日"));
|
||||
put("5-25", Collections.nCopies(1, "525心理健康节"));
|
||||
put("5-27", Collections.nCopies(1, "上海解放日"));
|
||||
put("5-31", Collections.nCopies(1, "世界无烟日"));
|
||||
put("6-5", Collections.nCopies(1, "世界环境日"));
|
||||
|
||||
@@ -230,6 +230,24 @@ public class BaZiTest {
|
||||
Assert.assertEquals("身宫", "壬午", lunar.getEightChar().getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShenGong1() {
|
||||
Lunar lunar = new Solar(1994, 12, 6, 2, 0, 0).getLunar();
|
||||
Assert.assertEquals("身宫", "丁丑", lunar.getEightChar().getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShenGong2() {
|
||||
Lunar lunar = new Solar(1990, 12, 11, 6, 0, 0).getLunar();
|
||||
Assert.assertEquals("身宫", "庚辰", lunar.getEightChar().getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShenGong3() {
|
||||
Lunar lunar = new Solar(1993, 5, 23, 4, 0, 0).getLunar();
|
||||
Assert.assertEquals("身宫", "庚申", lunar.getEightChar().getShenGong());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaZi2Solar() {
|
||||
Solar solar = Solar.fromYmdHms(2027,1,27,12,0,0);
|
||||
@@ -258,4 +276,23 @@ public class BaZiTest {
|
||||
Assert.assertEquals("1990-04-15", lunar.getEightChar().getYun(1).getStartSolar().toYmd());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test10(){
|
||||
Lunar lunar = Solar.fromYmdHms(1988, 2, 15, 23, 30, 0).getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11(){
|
||||
Lunar lunar = Lunar.fromYmdHms(1987, 12, 28, 23, 30, 0);
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱", "戊辰", eightChar.getYear());
|
||||
Assert.assertEquals("月柱", "甲寅", eightChar.getMonth());
|
||||
Assert.assertEquals("日柱", "庚子", eightChar.getDay());
|
||||
Assert.assertEquals("时柱", "戊子", eightChar.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,4 +333,22 @@ public class GanZhiTest {
|
||||
Assert.assertEquals("丁丑",lunar.getMonthInGanZhiExact());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test19() {
|
||||
Solar solar = new Solar(2022,4,6,20,18,0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("壬寅",lunar.getYearInGanZhi());
|
||||
Assert.assertEquals("壬寅",lunar.getYearInGanZhiByLiChun());
|
||||
Assert.assertEquals("壬寅",lunar.getYearInGanZhiExact());
|
||||
|
||||
Assert.assertEquals("甲辰",lunar.getMonthInGanZhi());
|
||||
Assert.assertEquals("甲辰",lunar.getMonthInGanZhiExact());
|
||||
|
||||
Assert.assertEquals("己丑",lunar.getDayInGanZhi());
|
||||
Assert.assertEquals("己丑",lunar.getDayInGanZhiExact());
|
||||
Assert.assertEquals("己丑",lunar.getDayInGanZhiExact2());
|
||||
|
||||
Assert.assertEquals("甲戌",lunar.getTimeInGanZhi());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -94,8 +94,11 @@ public class HolidayTest {
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
|
||||
|
||||
// 更改节假日名称
|
||||
String[] names = HolidayUtil.NAMES;
|
||||
// 自定义节假日名称
|
||||
String[] names = new String[HolidayUtil.NAMES.length];
|
||||
for (int i = 0, j = HolidayUtil.NAMES.length; i < j; i++) {
|
||||
names[i] = HolidayUtil.NAMES[i];
|
||||
}
|
||||
names[0] = "元旦";
|
||||
names[1] = "大年初一";
|
||||
|
||||
@@ -125,4 +128,17 @@ public class HolidayTest {
|
||||
Assert.assertNotNull(holiday.getTarget());
|
||||
Assert.assertEquals("2016-10-01",holiday.getTarget());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemove() {
|
||||
// 设置默认的节假日名称
|
||||
HolidayUtil.fix(HolidayUtil.NAMES, null);
|
||||
Holiday holiday = HolidayUtil.getHoliday(2010,1,1);
|
||||
Assert.assertNotNull(holiday);
|
||||
Assert.assertEquals("元旦节",holiday.getName());
|
||||
|
||||
HolidayUtil.fix("20100101~000000000000000000000000000");
|
||||
holiday = HolidayUtil.getHoliday(2010,1,1);
|
||||
Assert.assertNull(holiday);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ public class JieQiTest {
|
||||
@Test
|
||||
public void test8() {
|
||||
Lunar lunar = Lunar.fromYmd(2050, 12, 1);
|
||||
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("大雪").toYmdHms());
|
||||
Assert.assertEquals("2050-12-07 06:41:00", lunar.getJieQiTable().get("DA_XUE").toYmdHms());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -424,4 +424,39 @@ public class LunarTest {
|
||||
Assert.assertEquals(4, lunar.getDayJi().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test57() {
|
||||
Solar solar = new Solar(1991, 2, 5);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("庚寅", lunar.getMonthInGanZhi());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test58() {
|
||||
Solar solar = new Solar(2021, 3, 21);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("春社", lunar.getOtherFestivals().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test59() {
|
||||
Solar solar = new Solar(2022, 3, 16);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("春社", lunar.getOtherFestivals().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test60() {
|
||||
Solar solar = new Solar(1722, 9, 25);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("秋社", lunar.getOtherFestivals().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test61() {
|
||||
Solar solar = new Solar(840, 9, 14);
|
||||
Lunar lunar = solar.getLunar();
|
||||
Assert.assertEquals("秋社", lunar.getOtherFestivals().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public class SolarTest {
|
||||
|
||||
@Test
|
||||
public void test10(){
|
||||
Assert.assertEquals(false, SolarUtil.isLeapYear(1500));
|
||||
Assert.assertFalse(SolarUtil.isLeapYear(1500));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,4 +73,10 @@ public class SolarTest {
|
||||
Assert.assertEquals("2020-01-19",date.next(1,true).toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test11(){
|
||||
Solar solar = new Solar(2022, 3, 28);
|
||||
Assert.assertEquals("全国中小学生安全教育日",solar.getFestivals().get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user