v1.2.24 节假日数据支持删除。
This commit is contained in:
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
|
||||
<dependency>
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<version>1.2.23</version>
|
||||
<version>1.2.24</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.23</version>
|
||||
<version>1.2.24</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -7,7 +7,7 @@
|
||||
<groupId>cn.6tail</groupId>
|
||||
<artifactId>lunar</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.2.23</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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user