fix static method

void fix(
  1. List<String>? names,
  2. String? data
)

修正或追加节假日数据。节假日名称下标从0开始,超过9的,按ASCII码表依次往后排列;调休标识0为上班,否则放假 @param names 用于替换默认的节假日名称列表,传null即可使用默认名称 @param data 需要修正或追加的节假日数据,每18位表示1天依次排列,格式:当天年月日YYYYMMDD(8位)+节假日名称下标(1位)+调休标识(1位)+节假日当天YYYYMMDD(8位)。例:202005023120200501代表2020-05-02为劳动节放假,对应节假日为2020-05-01

Implementation

static void fix(List<String>? names, String? data) {
  if (null != names) {
    namesInUse = names;
  }
  if (null == data) {
    return;
  }
  String append = '';
  while (data!.length >= SIZE) {
    String segment = data.substring(0, SIZE);
    String day = segment.substring(0, 8);
    bool remove = TAG_REMOVE == segment.substring(8, 9);
    Holiday? holiday = getHoliday(day);
    if (null == holiday) {
      if (!remove) {
        append += segment;
      }
    } else {
      int nameIndex = -1;
      for (int i = 0, j = namesInUse.length; i < j; i++) {
        if (namesInUse[i] == holiday.getName()) {
          nameIndex = i;
          break;
        }
      }
      if (nameIndex > -1) {
        String old = day +
            new String.fromCharCode(nameIndex + zero) +
            (holiday.isWork() ? zero.toString() : '1') +
            holiday.getTarget().replaceAll('-', '');
        dataInUse = dataInUse.replaceAll(old, remove ? '' : segment);
      }
    }
    data = data.substring(SIZE);
  }
  if (append.length > 0) {
    dataInUse += append.toString();
  }
}