Skip to content

Commit 1aefcdc

Browse files
committed
v1.2.24 节假日数据支持删除。
1 parent 5d589eb commit 1aefcdc

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ lunar是一款无第三方依赖的公历(阳历)、农历(阴历、老黄历)
1616
<dependency>
1717
<groupId>cn.6tail</groupId>
1818
<artifactId>lunar</artifactId>
19-
<version>1.2.23</version>
19+
<version>1.2.24</version>
2020
</dependency>
2121
```
2222

README_EN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ lunar is a calendar library for Solar and Chinese Lunar.
1212
<dependency>
1313
<groupId>cn.6tail</groupId>
1414
<artifactId>lunar</artifactId>
15-
<version>1.2.23</version>
15+
<version>1.2.24</version>
1616
</dependency>
1717
```
1818

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>cn.6tail</groupId>
88
<artifactId>lunar</artifactId>
99
<packaging>jar</packaging>
10-
<version>1.2.23</version>
10+
<version>1.2.24</version>
1111
<name>${project.groupId}:${project.artifactId}</name>
1212
<url>https://github.com/6tail/lunar-java</url>
1313
<description>a calendar library for Solar and Chinese Lunar</description>

src/main/java/com/nlf/calendar/util/HolidayUtil.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public class HolidayUtil {
1717
private static final int SIZE = 18;
1818
/** 0 */
1919
private static final char ZERO = '0';
20+
/** 删除标识 */
21+
private static final String TAG_REMOVE = "~";
2022
/** 默认节假日名称(元旦0,春节1,清明2,劳动3,端午4,中秋5,国庆6,国庆中秋7,抗战胜利日8) */
2123
public static final String[] NAMES = {"元旦节","春节","清明节","劳动节","端午节","中秋节","国庆节","国庆中秋","抗战胜利日"};
2224
/** 默认节假日数据,日期YYYYMMDD+名称下标+是否调休+对应节日YYYYMMDD */
@@ -188,35 +190,38 @@ public static List<Holiday> getHolidaysByTarget(int year, int month, int day){
188190
* @param data 需要修正或追加的节假日数据,每18位表示1天依次排列,格式:当天年月日YYYYMMDD(8位)+节假日名称下标(1位)+调休标识(1位)+节假日当天YYYYMMDD(8位)。例:202005023120200501代表2020-05-02为劳动节放假,对应节假日为2020-05-01
189191
*/
190192
public static void fix(String[] names, String data){
191-
if(null!=names){
193+
if(null != names){
192194
NAMES_IN_USE = names;
193195
}
194-
if(null==data){
196+
if(null == data){
195197
return;
196198
}
197199
StringBuilder append = new StringBuilder();
198-
while(data.length()>=SIZE){
199-
String segment = data.substring(0,SIZE);
200-
String day = segment.substring(0,8);
200+
while(data.length() >= SIZE){
201+
String segment = data.substring(0, SIZE);
202+
String day = segment.substring(0, 8);
203+
boolean remove = TAG_REMOVE.equals(segment.substring(8, 9));
201204
Holiday holiday = getHoliday(day);
202-
if(null==holiday){
203-
append.append(segment);
205+
if(null == holiday){
206+
if (!remove) {
207+
append.append(segment);
208+
}
204209
}else{
205210
int nameIndex = -1;
206-
for(int i=0,j=NAMES_IN_USE.length;i<j;i++){
211+
for(int i = 0,j = NAMES_IN_USE.length; i < j; i++){
207212
if(NAMES_IN_USE[i].equals(holiday.getName())){
208213
nameIndex = i;
209214
break;
210215
}
211216
}
212217
if(nameIndex>-1) {
213-
String old = day+(char)(nameIndex+ZERO)+(holiday.isWork()?ZERO:'1')+holiday.getTarget().replace("-","");
214-
DATA_IN_USE = DATA_IN_USE.replace(old, segment);
218+
String old = day + (char)(nameIndex + ZERO) + (holiday.isWork() ? ZERO : '1') + holiday.getTarget().replace("-","");
219+
DATA_IN_USE = DATA_IN_USE.replace(old, remove ? "" : segment);
215220
}
216221
}
217222
data = data.substring(SIZE);
218223
}
219-
if(append.length()>0){
224+
if(append.length() > 0){
220225
DATA_IN_USE += append.toString();
221226
}
222227
}

src/test/java/test/HolidayTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,15 @@ public void test1() {
125125
Assert.assertNotNull(holiday.getTarget());
126126
Assert.assertEquals("2016-10-01",holiday.getTarget());
127127
}
128+
129+
@Test
130+
public void testRemove() {
131+
Holiday holiday = HolidayUtil.getHoliday(2010,1,1);
132+
Assert.assertNotNull(holiday);
133+
Assert.assertEquals("元旦",holiday.getName());
134+
135+
HolidayUtil.fix("20100101~000000000000000000000000000");
136+
holiday = HolidayUtil.getHoliday(2010,1,1);
137+
Assert.assertNull(holiday);
138+
}
128139
}

0 commit comments

Comments
 (0)