Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cbab78d641 | ||
|
|
a44ced263d | ||
|
|
bd19489441 | ||
|
|
a235e076db | ||
|
|
4995e3f9d0 | ||
|
|
554c474e4d | ||
|
|
316e9b7b88 | ||
|
|
b220249cd7 | ||
|
|
147499032b |
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)和农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.12</version>
|
||||
<version>1.1.15</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.1.12</version>
|
||||
<version>1.1.15</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.1.12</version>
|
||||
<version>1.1.15</version>
|
||||
<name>${project.groupId}:${project.artifactId}</name>
|
||||
<url>https://github.com/6tail/lunar-java</url>
|
||||
<description>a calendar library for Solar and Chinese Lunar</description>
|
||||
|
||||
@@ -30,11 +30,11 @@ public class EightChar {
|
||||
|
||||
{
|
||||
//阳
|
||||
put("甲", 11);
|
||||
put("丙", 2);
|
||||
put("戊", 2);
|
||||
put("庚", 5);
|
||||
put("壬", 8);
|
||||
put("甲", 1);
|
||||
put("丙", 10);
|
||||
put("戊", 10);
|
||||
put("庚", 7);
|
||||
put("壬", 4);
|
||||
//阴
|
||||
put("乙", 6);
|
||||
put("丁", 9);
|
||||
|
||||
@@ -53,7 +53,8 @@ public class LiuNian {
|
||||
* @return 干支
|
||||
*/
|
||||
public String getGanZhi() {
|
||||
int offset = LunarUtil.getJiaZiIndex(lunar.getYearInGanZhiExact()) + this.index;
|
||||
// 干支与出生日期和起运日期都没关系
|
||||
int offset = LunarUtil.getJiaZiIndex(lunar.getJieQiTable().get("立春").getLunar().getYearInGanZhiExact()) + this.index;
|
||||
if (daYun.getIndex() > 0) {
|
||||
offset += daYun.getStartAge() - 1;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -191,6 +191,15 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(9, yun.getStartMonth());
|
||||
Assert.assertEquals(20, yun.getStartDay());
|
||||
Assert.assertEquals("1973-09-12", yun.getStartSolar().toYmd());
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
Assert.assertEquals(9, yun.getStartYear());
|
||||
Assert.assertEquals(0, yun.getStartMonth());
|
||||
Assert.assertEquals(10, yun.getStartDay());
|
||||
Assert.assertEquals("2001-02-12", yun.getStartSolar().toYmd());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,6 +225,25 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(endAges[i], daYun.getEndAge());
|
||||
Assert.assertEquals(yearGanZhi[i], daYun.getGanZhi());
|
||||
}
|
||||
|
||||
startYears = new int[]{1992, 2001, 2011, 2021, 2031, 2041, 2051, 2061, 2071, 2081};
|
||||
endYears = new int[]{2000, 2010, 2020, 2030, 2040, 2050, 2060, 2070, 2080, 2090};
|
||||
startAges = new int[]{1, 10, 20, 30, 40, 50, 60, 70, 80, 90};
|
||||
endAges = new int[]{9, 19, 29, 39, 49, 59, 69, 79, 89, 99};
|
||||
yearGanZhi = new String[]{"", "庚子", "己亥", "戊戌", "丁酉", "丙申", "乙未", "甲午", "癸巳", "壬辰"};
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
l = yun.getDaYun();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
DaYun daYun = l[i];
|
||||
Assert.assertEquals(startYears[i], daYun.getStartYear());
|
||||
Assert.assertEquals(endYears[i], daYun.getEndYear());
|
||||
Assert.assertEquals(startAges[i], daYun.getStartAge());
|
||||
Assert.assertEquals(endAges[i], daYun.getEndAge());
|
||||
Assert.assertEquals(yearGanZhi[i], daYun.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,6 +326,23 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
years = new int[]{1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000};
|
||||
ages = new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
ganZhi = new String[]{"壬申","癸酉","甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰"};
|
||||
l = daYun[0].getLiuNian();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuNian liuNian = l[i];
|
||||
Assert.assertEquals(years[i], liuNian.getYear());
|
||||
Assert.assertEquals(ages[i], liuNian.getAge());
|
||||
Assert.assertEquals(ganZhi[i], liuNian.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,6 +377,19 @@ public class BaZiTestNew {
|
||||
Assert.assertEquals(ages[i], xiaoYun.getAge());
|
||||
Assert.assertEquals(years[i] + "年", ganZhi[i], xiaoYun.getGanZhi());
|
||||
}
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
ganZhi = new String[]{"丁巳", "丙辰", "乙卯", "甲寅", "癸丑", "壬子","辛亥","庚戌","己酉"};
|
||||
l = daYun[0].getXiaoYun();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
XiaoYun xiaoYun = l[i];
|
||||
Assert.assertEquals(ganZhi[i], xiaoYun.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -360,6 +418,21 @@ public class BaZiTestNew {
|
||||
LiuYue liuYue = l[i];
|
||||
Assert.assertEquals(ganZhi[i], liuYue.getGanZhi());
|
||||
}
|
||||
|
||||
|
||||
solar = new Solar(1992, 2, 2, 12, 0, 0);
|
||||
lunar = solar.getLunar();
|
||||
bazi = lunar.getEightChar();
|
||||
yun = bazi.getYun(1);
|
||||
daYun = yun.getDaYun();
|
||||
|
||||
ganZhi = new String[]{"壬寅", "癸卯", "甲辰", "乙巳", "丙午", "丁未", "戊申", "己酉", "庚戌", "辛亥", "壬子", "癸丑"};
|
||||
liuNian = daYun[0].getLiuNian();
|
||||
l = liuNian[0].getLiuYue();
|
||||
for (int i = 0, j = l.length; i < j; i++) {
|
||||
LiuYue liuYue = l[i];
|
||||
Assert.assertEquals(ganZhi[i], liuYue.getGanZhi());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,10 +87,90 @@ public class BaZiTest {
|
||||
Solar solar = new Solar(2005, 12, 23, 8, 37, 0);
|
||||
Lunar lunar = solar.getLunar();
|
||||
EightChar eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals("年柱地势", "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals("月柱地势", "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals("日柱地势", "死", eightChar.getDayDiShi());
|
||||
Assert.assertEquals("时柱地势", "墓", eightChar.getTimeDiShi());
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "死", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "墓", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 18, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "病", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "死", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "衰", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "绝", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 19, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "胎", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "绝", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "长生", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "死", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 20, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "绝", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "胎", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "病", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "长生", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 21, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "胎", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "绝", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "冠带", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "死", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 22, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "绝", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "胎", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "帝旺", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "长生", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 23, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "死", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "病", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "沐浴", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "帝旺", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 24, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "长生", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "沐浴", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "衰", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "临官", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 25, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "帝旺", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "临官", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "长生", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "沐浴", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 26, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "临官", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "帝旺", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "病", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "病", eightChar.getTimeDiShi());
|
||||
|
||||
solar = new Solar(2020, 11, 27, 17, 37, 0);
|
||||
lunar = solar.getLunar();
|
||||
eightChar = lunar.getEightChar();
|
||||
Assert.assertEquals(String.format("年柱地势(%s%s)",eightChar.getDayGan(),eightChar.getYearZhi()), "沐浴", eightChar.getYearDiShi());
|
||||
Assert.assertEquals(String.format("月柱地势(%s%s)",eightChar.getDayGan(),eightChar.getMonthZhi()), "长生", eightChar.getMonthDiShi());
|
||||
Assert.assertEquals(String.format("日柱地势(%s%s)",eightChar.getDayGan(),eightChar.getDayZhi()), "养", eightChar.getDayDiShi());
|
||||
Assert.assertEquals(String.format("时柱地势(%s%s)",eightChar.getDayGan(),eightChar.getTimeZhi()), "胎", eightChar.getTimeDiShi());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,27 +1,97 @@
|
||||
package test;
|
||||
|
||||
import com.nlf.calendar.Solar;
|
||||
import com.nlf.calendar.util.HolidayUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HolidayTest {
|
||||
|
||||
@Test
|
||||
public void test(){
|
||||
Assert.assertEquals("2020-01-01 元旦节 2020-01-01",HolidayUtil.getHoliday("2020-01-01")+"");
|
||||
public void test2021() {
|
||||
Map<String, String> holidays = new HashMap<String, String>() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
{
|
||||
put("2021-01-01", "2021-01-01 元旦节 2021-01-01");
|
||||
put("2021-01-02", "2021-01-02 元旦节 2021-01-01");
|
||||
put("2021-01-03", "2021-01-03 元旦节 2021-01-01");
|
||||
|
||||
put("2021-02-11", "2021-02-11 春节 2021-02-12");
|
||||
put("2021-02-12", "2021-02-12 春节 2021-02-12");
|
||||
put("2021-02-13", "2021-02-13 春节 2021-02-12");
|
||||
put("2021-02-14", "2021-02-14 春节 2021-02-12");
|
||||
put("2021-02-15", "2021-02-15 春节 2021-02-12");
|
||||
put("2021-02-16", "2021-02-16 春节 2021-02-12");
|
||||
put("2021-02-17", "2021-02-17 春节 2021-02-12");
|
||||
|
||||
put("2021-02-07", "2021-02-07 春节调休 2021-02-12");
|
||||
put("2021-02-20", "2021-02-20 春节调休 2021-02-12");
|
||||
|
||||
put("2021-04-03", "2021-04-03 清明节 2021-04-04");
|
||||
put("2021-04-04", "2021-04-04 清明节 2021-04-04");
|
||||
put("2021-04-05", "2021-04-05 清明节 2021-04-04");
|
||||
|
||||
put("2021-05-01", "2021-05-01 劳动节 2021-05-01");
|
||||
put("2021-05-02", "2021-05-02 劳动节 2021-05-01");
|
||||
put("2021-05-03", "2021-05-03 劳动节 2021-05-01");
|
||||
put("2021-05-04", "2021-05-04 劳动节 2021-05-01");
|
||||
put("2021-05-05", "2021-05-05 劳动节 2021-05-01");
|
||||
|
||||
put("2021-04-25", "2021-04-25 劳动节调休 2021-05-01");
|
||||
put("2021-05-08", "2021-05-08 劳动节调休 2021-05-01");
|
||||
|
||||
put("2021-06-12", "2021-06-12 端午节 2021-06-14");
|
||||
put("2021-06-13", "2021-06-13 端午节 2021-06-14");
|
||||
put("2021-06-14", "2021-06-14 端午节 2021-06-14");
|
||||
|
||||
put("2021-09-19", "2021-09-19 中秋节 2021-09-21");
|
||||
put("2021-09-20", "2021-09-20 中秋节 2021-09-21");
|
||||
put("2021-09-21", "2021-09-21 中秋节 2021-09-21");
|
||||
|
||||
put("2021-09-18", "2021-09-18 中秋节调休 2021-09-21");
|
||||
|
||||
put("2021-10-01", "2021-10-01 国庆节 2021-10-01");
|
||||
put("2021-10-02", "2021-10-02 国庆节 2021-10-01");
|
||||
put("2021-10-03", "2021-10-03 国庆节 2021-10-01");
|
||||
put("2021-10-04", "2021-10-04 国庆节 2021-10-01");
|
||||
put("2021-10-05", "2021-10-05 国庆节 2021-10-01");
|
||||
put("2021-10-06", "2021-10-06 国庆节 2021-10-01");
|
||||
put("2021-10-07", "2021-10-07 国庆节 2021-10-01");
|
||||
|
||||
put("2021-09-26", "2021-09-26 国庆节调休 2021-10-01");
|
||||
put("2021-10-09", "2021-10-09 国庆节调休 2021-10-01");
|
||||
}
|
||||
};
|
||||
Solar solar = Solar.fromYmd(2021, 1, 1);
|
||||
while (solar.toYmd().compareTo("2022-01-01") < 0) {
|
||||
String ymd = solar.toYmd();
|
||||
String holiday = holidays.get(ymd);
|
||||
Assert.assertEquals(ymd, holiday + "", HolidayUtil.getHoliday(ymd) + "");
|
||||
|
||||
solar = solar.next(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertEquals("2020-01-01 元旦节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
|
||||
// 将2020-01-01修改为春节
|
||||
HolidayUtil.fix("202001011120200101");
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01",HolidayUtil.getHoliday("2020-01-01")+"");
|
||||
Assert.assertEquals("2020-01-01 春节 2020-01-01", HolidayUtil.getHoliday("2020-01-01") + "");
|
||||
|
||||
// 追加2099-01-01为元旦节
|
||||
HolidayUtil.fix("209901010120990101");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01",HolidayUtil.getHoliday("2099-01-01")+"");
|
||||
Assert.assertEquals("2099-01-01 元旦节 2099-01-01", HolidayUtil.getHoliday("2099-01-01") + "");
|
||||
|
||||
// 将2020-01-01修改为春节,并追加2099-01-01为元旦节
|
||||
HolidayUtil.fix("202001011120200101209901010120990101");
|
||||
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")+"");
|
||||
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;
|
||||
@@ -29,12 +99,12 @@ public class HolidayTest {
|
||||
names[1] = "大年初一";
|
||||
|
||||
HolidayUtil.fix(names, null);
|
||||
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")+"");
|
||||
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") + "");
|
||||
|
||||
// 追加节假日名称和数据
|
||||
names = new String[12];
|
||||
for(int i=0,j=HolidayUtil.NAMES.length;i<j;i++){
|
||||
for (int i = 0, j = HolidayUtil.NAMES.length; i < j; i++) {
|
||||
names[i] = HolidayUtil.NAMES[i];
|
||||
}
|
||||
names[9] = "我的生日";
|
||||
@@ -42,8 +112,8 @@ public class HolidayTest {
|
||||
names[11] = "她的生日";
|
||||
|
||||
HolidayUtil.fix(names, "20210529912021052920211111:12021111120211201;120211201");
|
||||
Assert.assertEquals("2021-05-29 我的生日 2021-05-29",HolidayUtil.getHoliday("2021-05-29")+"");
|
||||
Assert.assertEquals("2021-11-11 结婚纪念日 2021-11-11",HolidayUtil.getHoliday("2021-11-11")+"");
|
||||
Assert.assertEquals("2021-12-01 她的生日 2021-12-01",HolidayUtil.getHoliday("2021-12-01")+"");
|
||||
Assert.assertEquals("2021-05-29 我的生日 2021-05-29", HolidayUtil.getHoliday("2021-05-29") + "");
|
||||
Assert.assertEquals("2021-11-11 结婚纪念日 2021-11-11", HolidayUtil.getHoliday("2021-11-11") + "");
|
||||
Assert.assertEquals("2021-12-01 她的生日 2021-12-01", HolidayUtil.getHoliday("2021-12-01") + "");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user