@@ -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 }
0 commit comments