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

Compare commits

..

10 Commits

36 changed files with 1089 additions and 381 deletions

View File

@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
<dependency>
<groupId>cn.6tail</groupId>
<artifactId>lunar</artifactId>
<version>1.2.16</version>
<version>1.2.24</version>
</dependency>
```
@@ -54,33 +54,3 @@ 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

@@ -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.16</version>
<version>1.2.24</version>
</dependency>
```

View File

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

@@ -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;
@@ -556,13 +579,24 @@ public class EightChar {
}
/**
* 获取运
* 使用默认流派1获取运
*
* @param gender 性别:1男,0女
* @return 运
*/
public Yun getYun(int gender) {
return new Yun(this, gender);
return getYun(gender, 1);
}
/**
* 获取运
*
* @param gender 性别:1男,0女
* @param sect 流派,1按天数和时辰数计算,3天1年,1天4个月,1时辰10天;2按分钟数计算
* @return 运
*/
public Yun getYun(int gender, int sect) {
return new Yun(this, gender, sect);
}
/**

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;

File diff suppressed because it is too large Load Diff

View File

@@ -2,6 +2,8 @@ package com.nlf.calendar;
import com.nlf.calendar.util.LunarUtil;
import java.util.List;
/**
* 农历月
*
@@ -12,28 +14,29 @@ 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;
/**
* 初始化
* @param lunarYear 农历年
* @param lunarMonth 农历月:1-12,闰月为负数,如闰2月为-2
* @param dayCount 天数
*
* @param lunarYear 农历年
* @param lunarMonth 农历月:1-12,闰月为负数,如闰2月为-2
* @param dayCount 天数
* @param firstJulianDay 初一的儒略日
*/
public LunarMonth(int lunarYear, int lunarMonth, int dayCount, double firstJulianDay) {
@@ -45,16 +48,18 @@ public class LunarMonth {
/**
* 通过农历年月初始化
* @param lunarYear 农历年
*
* @param lunarYear 农历年
* @param lunarMonth 农历月:1-12,闰月为负数,如闰2月为-2
* @return 农历月
*/
public static LunarMonth fromYm(int lunarYear, int lunarMonth){
public static LunarMonth fromYm(int lunarYear, int lunarMonth) {
return LunarYear.fromYear(lunarYear).getMonth(lunarMonth);
}
/**
* 获取农历年
*
* @return 农历年
*/
public int getYear() {
@@ -63,6 +68,7 @@ public class LunarMonth {
/**
* 获取农历月
*
* @return 农历月:1-12,闰月为负数,如闰2月为-2
*/
public int getMonth() {
@@ -71,6 +77,7 @@ public class LunarMonth {
/**
* 是否闰月
*
* @return true/false
*/
public boolean isLeap() {
@@ -79,6 +86,7 @@ public class LunarMonth {
/**
* 获取天数
*
* @return 天数
*/
public int getDayCount() {
@@ -87,6 +95,7 @@ public class LunarMonth {
/**
* 获取初一的儒略日
*
* @return 初一的儒略日
*/
public double getFirstJulianDay() {
@@ -96,27 +105,21 @@ public class LunarMonth {
/**
* 获取太岁方位
*
* @return 太岁方位,如艮
* @return 方位,如艮
*/
public String getPositionTaiSui() {
String p;
int m = Math.abs(month);
switch(m) {
int m = Math.abs(month) % 4;
switch (m) {
case 0:
p = "巽";
break;
case 1:
case 5:
case 9:
p = "艮";
break;
case 3:
case 7:
case 11:
p = "坤";
break;
case 4:
case 8:
case 12:
p = "巽";
break;
default:
p = LunarUtil.POSITION_GAN[Solar.fromJulianDay(this.getFirstJulianDay()).getLunar().getMonthGanIndex()];
}
@@ -126,15 +129,99 @@ public class LunarMonth {
/**
* 获取太岁方位描述
*
* @return 太岁方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionTaiSuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionTaiSui());
}
/**
* 获取月九星
*
* @return 九星
*/
public NineStar getNineStar() {
int index = LunarYear.fromYear(year).getZhiIndex() % 3;
int m = Math.abs(month);
int monthZhiIndex = (13 + m) % 12;
int n = 27 - index * 3;
if (monthZhiIndex < LunarUtil.BASE_MONTH_ZHI_INDEX) {
n -= 3;
}
int offset = (n - monthZhiIndex) % 9;
return NineStar.fromIndex(offset);
}
@Override
public String toString() {
return year + "年" + (isLeap() ? "闰" : "") + LunarUtil.MONTH[Math.abs(month)] + "月(" + dayCount + "天)";
}
/**
* 获取往后推几个月的阴历月,如果要往前推,则月数用负数
*
* @param n 月数
* @return 阴历月
*/
public LunarMonth next(int n) {
if (0 == n) {
return LunarMonth.fromYm(year, month);
} else if (n > 0) {
int rest = n;
int ny = year;
int iy = ny;
int im = month;
int index = 0;
List<LunarMonth> months = LunarYear.fromYear(ny).getMonths();
while (true) {
int size = months.size();
for (int i = 0; i < size; i++) {
LunarMonth m = months.get(i);
if (m.getYear() == iy && m.getMonth() == im) {
index = i;
break;
}
}
int more = size - index - 1;
if (rest < more) {
break;
}
rest -= more;
LunarMonth lastMonth = months.get(size - 1);
iy = lastMonth.getYear();
im = lastMonth.getMonth();
ny++;
months = LunarYear.fromYear(ny).getMonths();
}
return months.get(index + rest);
} else {
int rest = -n;
int ny = year;
int iy = ny;
int im = month;
int index = 0;
List<LunarMonth> months = LunarYear.fromYear(ny).getMonths();
while (true) {
int size = months.size();
for (int i = 0; i < size; i++) {
LunarMonth m = months.get(i);
if (m.getYear() == iy && m.getMonth() == im) {
index = i;
break;
}
}
if (rest <= index) {
break;
}
rest -= index;
LunarMonth firstMonth = months.get(0);
iy = firstMonth.getYear();
im = firstMonth.getMonth();
ny--;
months = LunarYear.fromYear(ny).getMonths();
}
return months.get(index - rest);
}
}
}

View File

@@ -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)) {

View File

@@ -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>();
/**
* 初始化
@@ -214,6 +214,24 @@ public class LunarYear {
return jieQiJulianDays;
}
/**
* 获取天干序号,从0开始
*
* @return 序号
*/
public int getGanIndex() {
return ganIndex;
}
/**
* 获取地支序号,从0开始
*
* @return 序号
*/
public int getZhiIndex() {
return zhiIndex;
}
/**
* 获取天干
*
@@ -436,14 +454,9 @@ public class LunarYear {
* @return 九星
*/
public NineStar getNineStar() {
int index = LunarUtil.getJiaZiIndex(this.getGanZhi()) + 1;
int n = 65;
if ("中元".equals(getYuan())) {
n = 68;
} else if ("下元".equals(getYuan())) {
n = 62;
}
int offset = (n - index) % 9;
int index = LunarUtil.getJiaZiIndex(getGanZhi()) + 1;
int yuan = ((this.year + 2696) / 60) % 3;
int offset = (62 + yuan * 3 - index) % 9;
if (0 == offset) {
offset = 9;
}
@@ -453,7 +466,7 @@ public class LunarYear {
/**
* 获取喜神方位
*
* @return 喜神方位,如艮
* @return 方位,如艮
*/
public String getPositionXi() {
return LunarUtil.POSITION_XI[ganIndex + 1];
@@ -462,7 +475,7 @@ public class LunarYear {
/**
* 获取喜神方位描述
*
* @return 喜神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionXiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionXi());
@@ -471,7 +484,7 @@ public class LunarYear {
/**
* 获取阳贵神方位
*
* @return 阳贵神方位,如艮
* @return 方位,如艮
*/
public String getPositionYangGui() {
return LunarUtil.POSITION_YANG_GUI[ganIndex + 1];
@@ -480,7 +493,7 @@ public class LunarYear {
/**
* 获取阳贵神方位描述
*
* @return 阳贵神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionYangGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYangGui());
@@ -489,7 +502,7 @@ public class LunarYear {
/**
* 获取阴贵神方位
*
* @return 阴贵神方位,如艮
* @return 方位,如艮
*/
public String getPositionYinGui() {
return LunarUtil.POSITION_YIN_GUI[ganIndex + 1];
@@ -498,7 +511,7 @@ public class LunarYear {
/**
* 获取阴贵神方位描述
*
* @return 阴贵神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionYinGuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionYinGui());
@@ -507,7 +520,7 @@ public class LunarYear {
/**
* 获取福神方位(默认流派:2)
*
* @return 福神方位,如艮
* @return 方位,如艮
*/
public String getPositionFu() {
return getPositionFu(2);
@@ -517,7 +530,7 @@ public class LunarYear {
* 获取福神方位
*
* @param sect 流派,1或2
* @return 福神方位,如艮
* @return 方位,如艮
*/
public String getPositionFu(int sect) {
return (1 == sect ? LunarUtil.POSITION_FU : LunarUtil.POSITION_FU_2)[ganIndex + 1];
@@ -526,7 +539,7 @@ public class LunarYear {
/**
* 获取福神方位描述(默认流派:2)
*
* @return 福神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionFuDesc() {
return getPositionFuDesc(2);
@@ -536,7 +549,7 @@ public class LunarYear {
* 获取福神方位描述
*
* @param sect 流派,1或2
* @return 福神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionFuDesc(int sect) {
return LunarUtil.POSITION_DESC.get(getPositionFu(sect));
@@ -554,7 +567,7 @@ public class LunarYear {
/**
* 获取财神方位描述
*
* @return 财神方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionCaiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionCai());
@@ -563,7 +576,7 @@ public class LunarYear {
/**
* 获取太岁方位
*
* @return 太岁方位,如艮
* @return 方位,如艮
*/
public String getPositionTaiSui() {
return LunarUtil.POSITION_TAI_SUI_YEAR[zhiIndex];
@@ -572,7 +585,7 @@ public class LunarYear {
/**
* 获取太岁方位描述
*
* @return 太岁方位描述,如东北
* @return 方位描述,如东北
*/
public String getPositionTaiSuiDesc() {
return LunarUtil.POSITION_DESC.get(getPositionTaiSui());
@@ -586,4 +599,14 @@ public class LunarYear {
public String toFullString() {
return year + "年";
}
/**
* 获取往后推几年的阴历年,如果要往前推,则年数用负数
*
* @param n 年数
* @return 阴历年
*/
public LunarYear next(int n) {
return LunarYear.fromYear(year + n);
}
}

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -14,11 +14,13 @@ public class SolarSeason {
/**
* 年
*/
private int year;
private final int year;
/**
* 月
*/
private int month;
private final int month;
/**
* 一个季度的月数
*/

View File

@@ -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;
/**
* 默认当月
@@ -155,14 +158,29 @@ public class SolarWeek {
*
* @return 周序号,从1开始
*/
@SuppressWarnings("MagicConstant")
public int getIndex() {
Calendar c = ExactDate.fromYmd(year, month, 1);
int firstDayWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
if (firstDayWeek == 0) {
firstDayWeek = 7;
int offset = firstDayWeek - start;
if(offset < 0) {
offset += 7;
}
return (int) Math.ceil((day + firstDayWeek - start) / 7D);
return (int) Math.ceil((day + offset) / 7D);
}
/**
* 获取当前日期是在当年第几周
*
* @return 周序号,从1开始
*/
public int getIndexInYear() {
Calendar c = ExactDate.fromYmd(year, 1, 1);
int firstDayWeek = c.get(Calendar.DAY_OF_WEEK) - 1;
int offset = firstDayWeek - start;
if(offset < 0) {
offset += 7;
}
return (int) Math.ceil((SolarUtil.getDaysInYear(year, month, day) + offset) / 7D);
}
/**
@@ -172,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);
@@ -227,7 +244,6 @@ public class SolarWeek {
*
* @return 本周第一天的阳历日期
*/
@SuppressWarnings("MagicConstant")
public Solar getFirstDay() {
Calendar c = ExactDate.fromYmd(year, month, day);
int week = c.get(Calendar.DAY_OF_WEEK) - 1;
@@ -259,6 +275,7 @@ public class SolarWeek {
*
* @return 本周的阳历日期列表
*/
@SuppressWarnings("all")
public List<Solar> getDays() {
Solar firstDay = getFirstDay();
List<Solar> l = new ArrayList<Solar>();

View File

@@ -14,7 +14,7 @@ public class SolarYear {
/**
* 年
*/
private int year;
private final int year;
/**
* 一年的月数

View File

@@ -18,7 +18,7 @@ public class Tao {
/**
* 阴历
*/
private Lunar lunar;
private final Lunar lunar;
public Tao(Lunar lunar) {
this.lunar = lunar;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -14,26 +14,51 @@ public class Yun {
/**
* 性别(1男,0女)
*/
private int gender;
private final int gender;
/**
* 起运年数
*/
private int startYear;
/**
* 起运月数
*/
private int startMonth;
/**
* 起运天数
*/
private int startDay;
/**
* 起运小时数
*/
private int startHour;
/**
* 是否顺推
*/
private boolean forward;
private Lunar lunar;
private final boolean forward;
private final Lunar lunar;
/**
* 使用默认流派1初始化运
* @param eightChar 八字
* @param gender 性别,1男,0女
*/
public Yun(EightChar eightChar, int gender) {
this(eightChar, gender, 1);
}
/**
* 初始化运
* @param eightChar 八字
* @param gender 性别,1男,0女
* @param sect 流派,1按天数和时辰数计算,3天1年,1天4个月,1时辰10天;2按分钟数计算
*/
public Yun(EightChar eightChar, int gender, int sect) {
this.lunar = eightChar.getLunar();
this.gender = gender;
// 阳
@@ -41,14 +66,13 @@ public class Yun {
// 男
boolean man = 1 == gender;
forward = (yang && man) || (!yang && !man);
computeStart();
computeStart(sect);
}
/**
* 起运计算
*/
@SuppressWarnings("MagicConstant")
private void computeStart() {
private void computeStart(int sect) {
// 上节
JieQi prev = lunar.getPrevJie();
// 下节
@@ -58,26 +82,46 @@ public class Yun {
// 阳男阴女顺推,阴男阳女逆推
Solar start = forward ? current : prev.getSolar();
Solar end = forward ? next.getSolar() : current;
int endTimeZhiIndex = (end.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(end.toYmdHms().substring(11, 16));
int startTimeZhiIndex = (start.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().substring(11, 16));
// 时辰差
int hourDiff = endTimeZhiIndex - startTimeZhiIndex;
Calendar endCalendar = ExactDate.fromYmd(end.getYear(), end.getMonth(), end.getDay());
Calendar startCalendar = ExactDate.fromYmd(start.getYear(), start.getMonth(), start.getDay());
// 天数差
int dayDiff = (int) ((endCalendar.getTimeInMillis() - startCalendar.getTimeInMillis()) / (1000 * 3600 * 24));
if (hourDiff < 0) {
hourDiff += 12;
dayDiff--;
int year;
int month;
int day;
int hour = 0;
if (2 == sect) {
long minutes = (end.getCalendar().getTimeInMillis() - start.getCalendar().getTimeInMillis()) / 60000;
long y = minutes / 4320;
minutes -= y * 4320;
long m = minutes / 360;
minutes -= m * 360;
long d = minutes / 12;
minutes -= d * 12;
long h = minutes * 2;
year = (int)y;
month = (int)m;
day = (int)d;
hour = (int)h;
} else {
int endTimeZhiIndex = (end.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(end.toYmdHms().substring(11, 16));
int startTimeZhiIndex = (start.getHour() == 23) ? 11 : LunarUtil.getTimeZhiIndex(start.toYmdHms().substring(11, 16));
// 时辰差
int hourDiff = endTimeZhiIndex - startTimeZhiIndex;
// 天数差
int dayDiff = ExactDate.getDaysBetween(start.getYear(), start.getMonth(), start.getDay(), end.getYear(), end.getMonth(), end.getDay());
if (hourDiff < 0) {
hourDiff += 12;
dayDiff--;
}
int monthDiff = hourDiff * 10 / 30;
month = dayDiff * 4 + monthDiff;
day = hourDiff * 10 - monthDiff * 30;
year = month / 12;
month = month - year * 12;
}
int monthDiff = hourDiff * 10 / 30;
int month = dayDiff * 4 + monthDiff;
int day = hourDiff * 10 - monthDiff * 30;
int year = month / 12;
month = month - year * 12;
this.startYear = year;
this.startMonth = month;
this.startDay = day;
this.startHour = hour;
}
/**
@@ -116,6 +160,15 @@ public class Yun {
return startDay;
}
/**
* 获取起运小时数
*
* @return 起运小时数
*/
public int getStartHour() {
return startHour;
}
/**
* 是否顺推
*
@@ -134,13 +187,13 @@ public class Yun {
*
* @return 阳历日期
*/
@SuppressWarnings("MagicConstant")
public Solar getStartSolar() {
Solar birth = lunar.getSolar();
Calendar c = ExactDate.fromYmd(birth.getYear(), birth.getMonth(), birth.getDay());
Calendar c = ExactDate.fromYmdHms(birth.getYear(), birth.getMonth(), birth.getDay(), birth.getHour(), birth.getMinute(), birth.getSecond());
c.add(Calendar.YEAR, startYear);
c.add(Calendar.MONTH, startMonth);
c.add(Calendar.DATE, startDay);
c.add(Calendar.HOUR, startHour);
return Solar.fromCalendar(c);
}

View File

@@ -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();
}
}

View File

@@ -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;

View File

@@ -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, "世界环境日"));

View File

@@ -17,7 +17,7 @@ public class TaoUtil {
private static final long serialVersionUID = 1;
{
put("1-1", Collections.nCopies(1, new TaoFestival("天腊之辰", "天腊,此日五帝会于束方九炁青天")));
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("举迁赏会", "此日上元赐福,天官同地水二官考校罪福")));
@@ -52,7 +52,7 @@ public class TaoUtil {
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-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("张天师圣诞")));
@@ -94,7 +94,7 @@ public class TaoUtil {
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-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("建生大会", "此日下元解厄,水官同天地二官考校罪福")));
@@ -105,7 +105,7 @@ public class TaoUtil {
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-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("天猷上帝圣诞")));

View File

@@ -1,5 +1,6 @@
package sample;
import com.nlf.calendar.LunarMonth;
import com.nlf.calendar.Solar;
import com.nlf.calendar.SolarMonth;
import org.junit.Test;
@@ -10,11 +11,11 @@ import org.junit.Test;
public class MonthTest {
@Test
public void test(){
public void test() {
//下个月
SolarMonth month = new SolarMonth().next(1);
//遍历每一天
for(Solar d:month.getDays()){
for (Solar d : month.getDays()) {
//输出阳历信息
System.out.println(d.toFullString());
//输出阴历信息
@@ -23,4 +24,22 @@ public class MonthTest {
}
}
@Test
public void test1() {
LunarMonth month = LunarMonth.fromYm(2020, 1);
// 顺推
for (int i = 0; i < 60; i++) {
System.out.println(month.next(i).toString());
}
}
@Test
public void test2() {
LunarMonth month = LunarMonth.fromYm(2020, 1);
// 倒推
for (int i = 0; i < 60; i++) {
System.out.println(month.next(-i).toString());
}
}
}

View File

@@ -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);

View File

@@ -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());
}
}

View File

@@ -125,4 +125,15 @@ public class HolidayTest {
Assert.assertNotNull(holiday.getTarget());
Assert.assertEquals("2016-10-01",holiday.getTarget());
}
@Test
public void testRemove() {
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);
}
}

View File

@@ -5,6 +5,11 @@ import com.nlf.calendar.Solar;
import org.junit.Assert;
import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
/**
* 农历测试
*
@@ -159,13 +164,13 @@ public class LunarTest {
@Test
public void test23() {
Lunar lunar = Lunar.fromYmd(2022, 1, 1);
Assert.assertEquals("五黄土玉衡", lunar.getYearNineStar().toString());
Assert.assertEquals("六白金开阳", lunar.getYearNineStar().toString());
}
@Test
public void test24() {
Lunar lunar = Lunar.fromYmd(2033, 1, 1);
Assert.assertEquals("三碧木天玑", lunar.getYearNineStar().toString());
Assert.assertEquals("四绿木天权", lunar.getYearNineStar().toString());
}
@Test
@@ -394,4 +399,64 @@ public class LunarTest {
Assert.assertEquals("[嫁娶, 祭祀, 祈福, 求嗣, 开光, 出行, 解除, 出火, 拆卸, 进人口, 入宅, 移徙, 安床, 栽种, 动土, 修造, 纳畜, 入殓, 安葬, 立碑, 除服, 成服]", lunar.getDayYi().toString());
}
@Test
public void test54() throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
Date date = format.parse("1986-08-14");
Lunar lunar = new Lunar(date);
Assert.assertEquals("一九八六年七月初九", lunar.toString());
}
@Test
public void test55() {
Solar solar = new Solar(1986, 8, 14);
Lunar lunar = solar.getLunar();
Assert.assertEquals("一九八六年七月初九", lunar.toString());
}
@Test
public void test56() {
Solar solar = new Solar(2022, 4, 5);
Lunar lunar = solar.getLunar();
Assert.assertEquals("甲辰", lunar.getMonthInGanZhi());
Assert.assertEquals("癸卯", lunar.getMonthInGanZhiExact());
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));
}
}

View File

@@ -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));
}
}

View File

@@ -0,0 +1,86 @@
package test;
import com.nlf.calendar.SolarWeek;
import org.junit.Assert;
import org.junit.Test;
/**
* 阳历周测试
*
* @author 6tail
*/
public class SolarWeekTest {
@Test
public void test() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 1, 0);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test1() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 7, 0);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test2() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 8, 0);
Assert.assertEquals(2, week.getIndex());
}
@Test
public void test3() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 1, 1);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test4() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 2, 1);
Assert.assertEquals(2, week.getIndex());
}
@Test
public void test5() {
SolarWeek week = SolarWeek.fromYmd(2022, 5, 8, 1);
Assert.assertEquals(2, week.getIndex());
}
@Test
public void test6() {
SolarWeek week = SolarWeek.fromYmd(2021, 11, 1, 0);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test7() {
SolarWeek week = SolarWeek.fromYmd(2021, 11, 1, 1);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test8() {
SolarWeek week = SolarWeek.fromYmd(2021, 5, 2, 2);
Assert.assertEquals(1, week.getIndex());
}
@Test
public void test9() {
SolarWeek week = SolarWeek.fromYmd(2021, 5, 4, 2);
Assert.assertEquals(2, week.getIndex());
}
@Test
public void test10() {
SolarWeek week = SolarWeek.fromYmd(2022, 3, 6, 0);
Assert.assertEquals(11, week.getIndexInYear());
}
@Test
public void test11() {
SolarWeek week = SolarWeek.fromYmd(2022, 3, 6, 1);
Assert.assertEquals(10, week.getIndexInYear());
}
}

View File

@@ -53,4 +53,34 @@ public class YunTest {
Assert.assertEquals("起运阳历", "2020-02-06", yun.getStartSolar().toYmd());
}
@Test
public void test4() {
Solar solar = new Solar(2022, 3, 9, 20, 51, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(1);
Assert.assertEquals("起运阳历", "2030-12-19", yun.getStartSolar().toYmd());
}
@Test
public void test5() {
Solar solar = new Solar(2022, 3, 9, 20, 51, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(1, 2);
Assert.assertEquals("起运年数", 8, yun.getStartYear());
Assert.assertEquals("起运月数", 9, yun.getStartMonth());
Assert.assertEquals("起运天数", 2, yun.getStartDay());
Assert.assertEquals("起运阳历", "2030-12-12", yun.getStartSolar().toYmd());
}
@Test
public void test6() {
Solar solar = new Solar(2018, 6, 11, 9, 30, 0);
Lunar lunar = solar.getLunar();
EightChar eightChar = lunar.getEightChar();
Yun yun = eightChar.getYun(0, 2);
Assert.assertEquals("起运阳历", "2020-03-21", yun.getStartSolar().toYmd());
}
}