mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add term
This commit is contained in:
parent
99b7af1dff
commit
4865b10d3b
@ -8,6 +8,7 @@
|
||||
### 新特性
|
||||
* 【core 】 修改数字转换的实现,增加按照指定端序转换(pr#1492@Github)
|
||||
* 【core 】 修改拆分byte数组时最后一组长度的规则(pr#1494@Github)
|
||||
* 【core 】 新增根据日期获取节气(pr#1496@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 修复Validator.isUrl()传空返回true(issue#I3ETTY@Gitee)
|
||||
|
@ -1,7 +1,11 @@
|
||||
package cn.hutool.core.date;
|
||||
|
||||
import cn.hutool.core.convert.NumberChineseFormatter;
|
||||
import cn.hutool.core.date.chinese.*;
|
||||
import cn.hutool.core.date.chinese.ChineseMonth;
|
||||
import cn.hutool.core.date.chinese.GanZhi;
|
||||
import cn.hutool.core.date.chinese.LunarFestival;
|
||||
import cn.hutool.core.date.chinese.LunarInfo;
|
||||
import cn.hutool.core.date.chinese.SolarTerms;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
import java.util.Calendar;
|
||||
@ -328,6 +332,7 @@ public class ChineseDate {
|
||||
/**
|
||||
* 获得节气
|
||||
* @return 获得节气
|
||||
* @since 5.6.3
|
||||
*/
|
||||
public String getTerm() {
|
||||
return SolarTerms.getTerm(gyear, gmonth, gday);
|
||||
|
@ -16,226 +16,6 @@ import java.util.Date;
|
||||
*/
|
||||
public class SolarTerms {
|
||||
|
||||
/**
|
||||
* 24节气
|
||||
*/
|
||||
public static final String[] TERMS = {
|
||||
"小寒", "大寒", "立春", "雨水", "惊蛰", "春分",
|
||||
"清明", "谷雨", "立夏", "小满", "芒种", "夏至",
|
||||
"小暑", "大暑", "立秋", "处暑", "白露", "秋分",
|
||||
"寒露", "霜降", "立冬", "小雪", "大雪", "冬至"
|
||||
};
|
||||
|
||||
/**
|
||||
* 小寒
|
||||
*/
|
||||
public static final String XIAO_HAN = TERMS[0];
|
||||
/**
|
||||
* 大寒
|
||||
*/
|
||||
public static final String DA_HAN = TERMS[1];
|
||||
/**
|
||||
* 立春
|
||||
*/
|
||||
public static final String LI_CHUN = TERMS[2];
|
||||
/**
|
||||
* 雨水
|
||||
*/
|
||||
public static final String YU_SHUI = TERMS[3];
|
||||
/**
|
||||
* 惊蛰
|
||||
*/
|
||||
public static final String JING_ZHE = TERMS[4];
|
||||
/**
|
||||
* 春分
|
||||
*/
|
||||
public static final String CHUN_FEN = TERMS[5];
|
||||
/**
|
||||
* 清明
|
||||
*/
|
||||
public static final String QING_MING = TERMS[6];
|
||||
/**
|
||||
* 谷雨
|
||||
*/
|
||||
public static final String GU_YU = TERMS[7];
|
||||
/**
|
||||
* 立夏
|
||||
*/
|
||||
public static final String LI_XIA = TERMS[8];
|
||||
/**
|
||||
* 小满
|
||||
*/
|
||||
public static final String XIAO_MAN = TERMS[9];
|
||||
/**
|
||||
* 芒种
|
||||
*/
|
||||
public static final String MANG_ZHONG = TERMS[10];
|
||||
/**
|
||||
* 夏至
|
||||
*/
|
||||
public static final String XIA_ZHI = TERMS[11];
|
||||
/**
|
||||
* 小暑
|
||||
*/
|
||||
public static final String XIAO_SHU = TERMS[12];
|
||||
/**
|
||||
* 大暑
|
||||
*/
|
||||
public static final String DA_SHU = TERMS[13];
|
||||
/**
|
||||
* 立秋
|
||||
*/
|
||||
public static final String LI_QIU = TERMS[14];
|
||||
/**
|
||||
* 处暑
|
||||
*/
|
||||
public static final String CHU_SHU = TERMS[15];
|
||||
/**
|
||||
* 白露
|
||||
*/
|
||||
public static final String BAI_LU = TERMS[16];
|
||||
/**
|
||||
* 秋分
|
||||
*/
|
||||
public static final String QIU_FEN = TERMS[17];
|
||||
/**
|
||||
* 寒露
|
||||
*/
|
||||
public static final String HAN_LU = TERMS[18];
|
||||
/**
|
||||
* 霜降
|
||||
*/
|
||||
public static final String SHUANG_JIANG = TERMS[19];
|
||||
/**
|
||||
* 立冬
|
||||
*/
|
||||
public static final String LI_DONG = TERMS[20];
|
||||
/**
|
||||
* 小雪
|
||||
*/
|
||||
public static final String XIAO_XUE = TERMS[21];
|
||||
/**
|
||||
* 大雪
|
||||
*/
|
||||
public static final String DA_XUE = TERMS[22];
|
||||
/**
|
||||
* 冬至
|
||||
*/
|
||||
public static final String DONG_ZHI = TERMS[23];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据节气修正干支月
|
||||
*
|
||||
* @param y 月
|
||||
* @param n 节气
|
||||
* @return 干支月
|
||||
*/
|
||||
public static int getTerm(int y, int n) {
|
||||
if (y < 1900 || y > 2100) {
|
||||
return -1;
|
||||
}
|
||||
if (n < 1 || n > 24) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
String _table = S_TERM_INFO[y - 1900];
|
||||
Integer[] _info = new Integer[6];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
_info[i] = NumberUtil.parseInt("0x" + _table.substring(i * 5, 5 * (i + 1)));
|
||||
}
|
||||
String[] _calday = new String[24];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
_calday[4 * i] = _info[i].toString().substring(0, 1);
|
||||
_calday[4 * i + 1] = _info[i].toString().substring(1, 3);
|
||||
_calday[4 * i + 2] = _info[i].toString().substring(3, 4);
|
||||
_calday[4 * i + 3] = _info[i].toString().substring(4, 6);
|
||||
}
|
||||
return NumberUtil.parseInt(_calday[n - 1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 根据日期获取节气
|
||||
* @param date 日期
|
||||
* @return 返回指定日期所处的节气
|
||||
*/
|
||||
public static String getTerm(Date date) {
|
||||
final DateTime dt = DateUtil.date(date);
|
||||
return getTerm0(dt.year(), dt.month() + 1, dt.dayOfMonth());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据农历日期获取节气
|
||||
* @param chineseDate 农历日期
|
||||
* @return 返回指定日期所处的节气
|
||||
*/
|
||||
public static String getTerm(ChineseDate chineseDate) {
|
||||
return chineseDate.getTerm();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据日期获取节气
|
||||
* @param date 日期
|
||||
* @return 返回指定日期所处的节气
|
||||
*/
|
||||
public static String getTerm(LocalDate date) {
|
||||
return getTerm0(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据年月日获取节气
|
||||
* @param year 年
|
||||
* @param mouth 月
|
||||
* @param day 日
|
||||
* @return 返回指定年月日所处的节气
|
||||
*/
|
||||
public static String getTerm(int year, int mouth, int day) {
|
||||
return getTerm(LocalDate.of(year, mouth, day));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据年月日获取节气, 内部方法,不对月和日做有效校验
|
||||
* @param year 年
|
||||
* @param mouth 月
|
||||
* @param day 日
|
||||
* @return 返回指定年月日所处的节气
|
||||
*/
|
||||
static String getTerm0(int year, int mouth, int day) {
|
||||
if (year < 1900 || year > 2100) {
|
||||
throw new IllegalArgumentException("只支持1900-2100之间的日期获取节气");
|
||||
}
|
||||
|
||||
String termTable = S_TERM_INFO[year - 1900];
|
||||
|
||||
// 节气速查表中每5个字符含有4个节气,通过月份直接计算偏移
|
||||
int segment = (mouth + 1) / 2 - 1;
|
||||
int termInfo = NumberUtil.parseInt("0x" + termTable.substring(segment * 5, (segment + 1) * 5));
|
||||
|
||||
String[] segmentTable = new String[24];
|
||||
segmentTable[0] = String.valueOf(termInfo).substring(0, 1);
|
||||
segmentTable[1] = String.valueOf(termInfo).substring(1, 3);
|
||||
segmentTable[2] = String.valueOf(termInfo).substring(3, 4);
|
||||
segmentTable[3] = String.valueOf(termInfo).substring(4, 6);
|
||||
|
||||
// 奇数月份的节气在前2个,偶数月份的节气在后两个
|
||||
int segmentOffset = (mouth & 1) == 1 ? 0 : 2;
|
||||
if (day < NumberUtil.parseInt(segmentTable[segmentOffset])) {
|
||||
int idx = segment * 4 + segmentOffset - 1;
|
||||
return TERMS[idx < 0 ? 23 : idx];
|
||||
}
|
||||
if(day >= NumberUtil.parseInt(segmentTable[segmentOffset + 1])) {
|
||||
return TERMS[segment * 4 + segmentOffset + 1];
|
||||
}
|
||||
return TERMS[segment * 4 + segmentOffset];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 1900-2100各年的24节气日期速查表
|
||||
* 此表来自:https://github.com/jjonline/calendar.js/blob/master/calendar.js
|
||||
@ -308,4 +88,121 @@ public class SolarTerms {
|
||||
"7f0e36665b66a449801e9808297c35", "665f67f0e37f14898082b072297c35", "7ec967f0e37f14998082b0787b06bd",
|
||||
"7f07e7f0e47f531b0723b0b6fb0721", "7f0e26665b66a449801e9808297c35", "665f67f0e37f1489801eb072297c35",
|
||||
"7ec967f0e37f14998082b0787b06bd", "7f07e7f0e47f531b0723b0b6fb0721", "7f0e27f1487f531b0b0bb0b6fb0722"};
|
||||
|
||||
/**
|
||||
* 24节气
|
||||
*/
|
||||
private static final String[] TERMS = {
|
||||
"小寒", "大寒", "立春", "雨水", "惊蛰", "春分",
|
||||
"清明", "谷雨", "立夏", "小满", "芒种", "夏至",
|
||||
"小暑", "大暑", "立秋", "处暑", "白露", "秋分",
|
||||
"寒露", "霜降", "立冬", "小雪", "大雪", "冬至"
|
||||
};
|
||||
|
||||
/**
|
||||
* 传入公历y年获得该年第n个节气的公历日期
|
||||
*
|
||||
* @param y 公历年(1900-2100)
|
||||
* @param n 二十四节气中的第几个节气(1~24);从n=1(小寒)算起
|
||||
* @return getTerm(1987,3) -》4;意即1987年2月4日立春
|
||||
*/
|
||||
public static int getTerm(int y, int n) {
|
||||
if (y < 1900 || y > 2100) {
|
||||
return -1;
|
||||
}
|
||||
if (n < 1 || n > 24) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
final String _table = S_TERM_INFO[y - 1900];
|
||||
Integer[] _info = new Integer[6];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
_info[i] = Integer.parseInt(_table.substring(i * 5, 5 * (i + 1)), 16);
|
||||
}
|
||||
String[] _calday = new String[24];
|
||||
for (int i = 0; i < 6; i++) {
|
||||
_calday[4 * i] = _info[i].toString().substring(0, 1);
|
||||
_calday[4 * i + 1] = _info[i].toString().substring(1, 3);
|
||||
_calday[4 * i + 2] = _info[i].toString().substring(3, 4);
|
||||
_calday[4 * i + 3] = _info[i].toString().substring(4, 6);
|
||||
}
|
||||
return NumberUtil.parseInt(_calday[n - 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据日期获取节气
|
||||
* @param date 日期
|
||||
* @return 返回指定日期所处的节气
|
||||
*/
|
||||
public static String getTerm(Date date) {
|
||||
final DateTime dt = DateUtil.date(date);
|
||||
return getTermInternal(dt.year(), dt.month() + 1, dt.dayOfMonth());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据农历日期获取节气
|
||||
* @param chineseDate 农历日期
|
||||
* @return 返回指定日期所处的节气
|
||||
*/
|
||||
public static String getTerm(ChineseDate chineseDate) {
|
||||
return chineseDate.getTerm();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据日期获取节气
|
||||
* @param date 日期
|
||||
* @return 返回指定日期所处的节气
|
||||
*/
|
||||
public static String getTerm(LocalDate date) {
|
||||
return getTermInternal(date.getYear(), date.getMonthValue(), date.getDayOfMonth());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据年月日获取节气
|
||||
* @param year 公历年
|
||||
* @param mouth 公历月,从1开始
|
||||
* @param day 公历日,从1开始
|
||||
* @return 返回指定年月日所处的节气
|
||||
*/
|
||||
public static String getTerm(int year, int mouth, int day) {
|
||||
return getTerm(LocalDate.of(year, mouth, day));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据年月日获取节气, 内部方法,不对月和日做有效校验
|
||||
* @param year 年
|
||||
* @param mouth 月,从1计数
|
||||
* @param day 日,从1计数
|
||||
* @return 返回指定年月日所处的节气
|
||||
*/
|
||||
private static String getTermInternal(int year, int mouth, int day) {
|
||||
if (year < 1900 || year > 2100) {
|
||||
throw new IllegalArgumentException("只支持1900-2100之间的日期获取节气");
|
||||
}
|
||||
|
||||
final String termTable = S_TERM_INFO[year - 1900];
|
||||
|
||||
// 节气速查表中每5个字符含有4个节气,通过月份直接计算偏移
|
||||
final int segment = (mouth + 1) / 2 - 1;
|
||||
final int termInfo = Integer.parseInt(termTable.substring(segment * 5, (segment + 1) * 5), 16);
|
||||
final String termInfoStr = String.valueOf(termInfo);
|
||||
|
||||
final String[] segmentTable = new String[24];
|
||||
segmentTable[0] = termInfoStr.substring(0, 1);
|
||||
segmentTable[1] = termInfoStr.substring(1, 3);
|
||||
segmentTable[2] = termInfoStr.substring(3, 4);
|
||||
segmentTable[3] = termInfoStr.substring(4, 6);
|
||||
|
||||
// 奇数月份的节气在前2个,偶数月份的节气在后两个
|
||||
int segmentOffset = (mouth & 1) == 1 ? 0 : 2;
|
||||
if (day < NumberUtil.parseInt(segmentTable[segmentOffset])) {
|
||||
int idx = segment * 4 + segmentOffset - 1;
|
||||
return TERMS[idx < 0 ? 23 : idx];
|
||||
}
|
||||
if(day >= NumberUtil.parseInt(segmentTable[segmentOffset + 1])) {
|
||||
return TERMS[segment * 4 + segmentOffset + 1];
|
||||
}
|
||||
return TERMS[segment * 4 + segmentOffset];
|
||||
}
|
||||
}
|
||||
|
@ -5,76 +5,101 @@ import cn.hutool.core.date.DateUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class SolarTermsTest {
|
||||
|
||||
@Test
|
||||
public void getTermTest1(){
|
||||
final int term = SolarTerms.getTerm(1987, 3);
|
||||
Assert.assertEquals(4, term);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getTermTest() {
|
||||
Assert.assertEquals(SolarTerms.DONG_ZHI, SolarTerms.getTerm(2021, 1, 4));
|
||||
Assert.assertEquals(SolarTerms.XIAO_HAN, SolarTerms.getTerm(2021, 1, 5));
|
||||
Assert.assertEquals(SolarTerms.XIAO_HAN, SolarTerms.getTerm(2021, 1, 19));
|
||||
Assert.assertEquals(SolarTerms.DA_HAN, SolarTerms.getTerm(2021, 1, 20));
|
||||
Assert.assertEquals(SolarTerms.DA_HAN, SolarTerms.getTerm(2021, 2, 2));
|
||||
Assert.assertEquals(SolarTerms.LI_CHUN, SolarTerms.getTerm(2021, 2, 3));
|
||||
Assert.assertEquals(SolarTerms.LI_CHUN, SolarTerms.getTerm(2021, 2, 17));
|
||||
Assert.assertEquals(SolarTerms.YU_SHUI, SolarTerms.getTerm(2021, 2, 18));
|
||||
Assert.assertEquals(SolarTerms.YU_SHUI, SolarTerms.getTerm(2021, 3, 4));
|
||||
Assert.assertEquals(SolarTerms.JING_ZHE, SolarTerms.getTerm(2021, 3, 5));
|
||||
Assert.assertEquals(SolarTerms.JING_ZHE, SolarTerms.getTerm(2021, 3, 19));
|
||||
Assert.assertEquals(SolarTerms.CHUN_FEN, SolarTerms.getTerm(2021, 3, 20));
|
||||
Assert.assertEquals(SolarTerms.CHUN_FEN, SolarTerms.getTerm(2021, 4, 3));
|
||||
Assert.assertEquals(SolarTerms.QING_MING, SolarTerms.getTerm(2021, 4, 4));
|
||||
Assert.assertEquals(SolarTerms.QING_MING, SolarTerms.getTerm(2021, 4, 10));
|
||||
Assert.assertEquals(SolarTerms.QING_MING, SolarTerms.getTerm(2021, 4, 19));
|
||||
Assert.assertEquals(SolarTerms.GU_YU, SolarTerms.getTerm(2021, 4, 20));
|
||||
Assert.assertEquals(SolarTerms.GU_YU, SolarTerms.getTerm(2021, 4, 29));
|
||||
Assert.assertEquals(SolarTerms.GU_YU, SolarTerms.getTerm(2021, 5, 4));
|
||||
Assert.assertEquals(SolarTerms.LI_XIA, SolarTerms.getTerm(2021, 5, 5));
|
||||
Assert.assertEquals(SolarTerms.LI_XIA, SolarTerms.getTerm(2021, 5, 9));
|
||||
Assert.assertEquals(SolarTerms.LI_XIA, SolarTerms.getTerm(2021, 5, 20));
|
||||
Assert.assertEquals(SolarTerms.XIAO_MAN, SolarTerms.getTerm(2021, 5, 21));
|
||||
Assert.assertEquals(SolarTerms.XIAO_MAN, SolarTerms.getTerm(2021, 6, 4));
|
||||
Assert.assertEquals(SolarTerms.MANG_ZHONG, SolarTerms.getTerm(2021, 6, 5));
|
||||
Assert.assertEquals(SolarTerms.MANG_ZHONG, SolarTerms.getTerm(2021, 6, 20));
|
||||
Assert.assertEquals(SolarTerms.XIA_ZHI, SolarTerms.getTerm(2021, 6, 21));
|
||||
Assert.assertEquals(SolarTerms.XIA_ZHI, SolarTerms.getTerm(2021, 7, 6));
|
||||
Assert.assertEquals(SolarTerms.XIAO_SHU, SolarTerms.getTerm(2021, 7, 7));
|
||||
Assert.assertEquals(SolarTerms.XIAO_SHU, SolarTerms.getTerm(2021, 7, 21));
|
||||
Assert.assertEquals(SolarTerms.DA_SHU, SolarTerms.getTerm(2021, 7, 22));
|
||||
Assert.assertEquals(SolarTerms.DA_SHU, SolarTerms.getTerm(2021, 8, 6));
|
||||
Assert.assertEquals(SolarTerms.LI_QIU, SolarTerms.getTerm(2021, 8, 7));
|
||||
Assert.assertEquals(SolarTerms.CHU_SHU, SolarTerms.getTerm(2021, 8, 23));
|
||||
Assert.assertEquals(SolarTerms.CHU_SHU, SolarTerms.getTerm(2021, 9, 6));
|
||||
Assert.assertEquals(SolarTerms.BAI_LU, SolarTerms.getTerm(2021, 9, 7));
|
||||
Assert.assertEquals(SolarTerms.BAI_LU, SolarTerms.getTerm(2021, 9, 22));
|
||||
Assert.assertEquals(SolarTerms.QIU_FEN, SolarTerms.getTerm(2021, 9, 23));
|
||||
Assert.assertEquals(SolarTerms.QIU_FEN, SolarTerms.getTerm(2021, 10, 7));
|
||||
Assert.assertEquals(SolarTerms.HAN_LU, SolarTerms.getTerm(2021, 10, 8));
|
||||
Assert.assertEquals(SolarTerms.HAN_LU, SolarTerms.getTerm(2021, 10, 22));
|
||||
Assert.assertEquals(SolarTerms.SHUANG_JIANG, SolarTerms.getTerm(2021, 10, 23));
|
||||
Assert.assertEquals(SolarTerms.SHUANG_JIANG, SolarTerms.getTerm(2021, 11, 6));
|
||||
Assert.assertEquals(SolarTerms.LI_DONG, SolarTerms.getTerm(2021, 11, 7));
|
||||
Assert.assertEquals(SolarTerms.LI_DONG, SolarTerms.getTerm(2021, 11, 21));
|
||||
Assert.assertEquals(SolarTerms.XIAO_XUE, SolarTerms.getTerm(2021, 11, 22));
|
||||
Assert.assertEquals(SolarTerms.XIAO_XUE, SolarTerms.getTerm(2021, 12, 6));
|
||||
Assert.assertEquals(SolarTerms.DA_XUE, SolarTerms.getTerm(2021, 12, 7));
|
||||
Assert.assertEquals(SolarTerms.DA_XUE, SolarTerms.getTerm(2021, 12, 20));
|
||||
Assert.assertEquals(SolarTerms.DONG_ZHI, SolarTerms.getTerm(2021, 12, 21));
|
||||
Assert.assertEquals("冬至", SolarTerms.getTerm(2021, 1, 4));
|
||||
|
||||
Assert.assertEquals("小寒", SolarTerms.getTerm(2021, 1, 5));
|
||||
Assert.assertEquals("小寒", SolarTerms.getTerm(2021, 1, 19));
|
||||
|
||||
Assert.assertEquals("大寒", SolarTerms.getTerm(2021, 1, 20));
|
||||
Assert.assertEquals("大寒", SolarTerms.getTerm(2021, 2, 2));
|
||||
|
||||
Assert.assertEquals("立春", SolarTerms.getTerm(2021, 2, 3));
|
||||
Assert.assertEquals("立春", SolarTerms.getTerm(2021, 2, 17));
|
||||
|
||||
Assert.assertEquals("雨水", SolarTerms.getTerm(2021, 2, 18));
|
||||
Assert.assertEquals("雨水", SolarTerms.getTerm(2021, 3, 4));
|
||||
|
||||
Assert.assertEquals("惊蛰", SolarTerms.getTerm(2021, 3, 5));
|
||||
Assert.assertEquals("惊蛰", SolarTerms.getTerm(2021, 3, 19));
|
||||
|
||||
Assert.assertEquals("春分", SolarTerms.getTerm(2021, 3, 20));
|
||||
Assert.assertEquals("春分", SolarTerms.getTerm(2021, 4, 3));
|
||||
|
||||
Assert.assertEquals("清明", SolarTerms.getTerm(2021, 4, 4));
|
||||
Assert.assertEquals("清明", SolarTerms.getTerm(2021, 4, 10));
|
||||
Assert.assertEquals("清明", SolarTerms.getTerm(2021, 4, 19));
|
||||
|
||||
Assert.assertEquals("谷雨", SolarTerms.getTerm(2021, 4, 20));
|
||||
Assert.assertEquals("谷雨", SolarTerms.getTerm(2021, 4, 29));
|
||||
Assert.assertEquals("谷雨", SolarTerms.getTerm(2021, 5, 4));
|
||||
|
||||
Assert.assertEquals("立夏", SolarTerms.getTerm(2021, 5, 5));
|
||||
Assert.assertEquals("立夏", SolarTerms.getTerm(2021, 5, 9));
|
||||
Assert.assertEquals("立夏", SolarTerms.getTerm(2021, 5, 20));
|
||||
|
||||
Assert.assertEquals("小满", SolarTerms.getTerm(2021, 5, 21));
|
||||
Assert.assertEquals("小满", SolarTerms.getTerm(2021, 6, 4));
|
||||
|
||||
Assert.assertEquals("芒种", SolarTerms.getTerm(2021, 6, 5));
|
||||
Assert.assertEquals("芒种", SolarTerms.getTerm(2021, 6, 20));
|
||||
|
||||
Assert.assertEquals("夏至", SolarTerms.getTerm(2021, 6, 21));
|
||||
Assert.assertEquals("夏至", SolarTerms.getTerm(2021, 7, 6));
|
||||
|
||||
Assert.assertEquals("小暑", SolarTerms.getTerm(2021, 7, 7));
|
||||
Assert.assertEquals("小暑", SolarTerms.getTerm(2021, 7, 21));
|
||||
|
||||
Assert.assertEquals("大暑", SolarTerms.getTerm(2021, 7, 22));
|
||||
Assert.assertEquals("大暑", SolarTerms.getTerm(2021, 8, 6));
|
||||
|
||||
Assert.assertEquals("立秋", SolarTerms.getTerm(2021, 8, 7));
|
||||
|
||||
Assert.assertEquals("处暑", SolarTerms.getTerm(2021, 8, 23));
|
||||
Assert.assertEquals("处暑", SolarTerms.getTerm(2021, 9, 6));
|
||||
|
||||
Assert.assertEquals("白露", SolarTerms.getTerm(2021, 9, 7));
|
||||
Assert.assertEquals("白露", SolarTerms.getTerm(2021, 9, 22));
|
||||
|
||||
Assert.assertEquals("秋分", SolarTerms.getTerm(2021, 9, 23));
|
||||
Assert.assertEquals("秋分", SolarTerms.getTerm(2021, 10, 7));
|
||||
|
||||
Assert.assertEquals("寒露", SolarTerms.getTerm(2021, 10, 8));
|
||||
Assert.assertEquals("寒露", SolarTerms.getTerm(2021, 10, 22));
|
||||
|
||||
Assert.assertEquals("霜降", SolarTerms.getTerm(2021, 10, 23));
|
||||
Assert.assertEquals("霜降", SolarTerms.getTerm(2021, 11, 6));
|
||||
|
||||
Assert.assertEquals("立冬", SolarTerms.getTerm(2021, 11, 7));
|
||||
Assert.assertEquals("立冬", SolarTerms.getTerm(2021, 11, 21));
|
||||
|
||||
Assert.assertEquals("小雪", SolarTerms.getTerm(2021, 11, 22));
|
||||
Assert.assertEquals("小雪", SolarTerms.getTerm(2021, 12, 6));
|
||||
|
||||
Assert.assertEquals("大雪", SolarTerms.getTerm(2021, 12, 7));
|
||||
Assert.assertEquals("大雪", SolarTerms.getTerm(2021, 12, 20));
|
||||
|
||||
Assert.assertEquals("冬至", SolarTerms.getTerm(2021, 12, 21));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getTermByDateTest() {
|
||||
Assert.assertEquals(SolarTerms.CHUN_FEN, SolarTerms.getTerm(DateUtil.parseDate("2021-04-02")));
|
||||
Assert.assertEquals("春分", SolarTerms.getTerm(DateUtil.parseDate("2021-04-02")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getTermByChineseDateTest() {
|
||||
Assert.assertEquals(SolarTerms.QING_MING, SolarTerms.getTerm(new ChineseDate(2021, 2, 25)));
|
||||
Assert.assertEquals("清明", SolarTerms.getTerm(new ChineseDate(2021, 2, 25)));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user