public List<String> formatTypeAndRange(@Nullable String type, long beginMillis, long endMillis) {
    GregorianCalendar current = midnightUTC(beginMillis);
    GregorianCalendar end = midnightUTC(endMillis);

    String prefix = prefix(type);
    List<String> indices = new ArrayList<>();
    while (current.compareTo(end) <= 0) {
      if (current.get(Calendar.MONTH) == Calendar.JANUARY && current.get(DAY_OF_MONTH) == 1) {
        // attempt to compress a year
        current.set(Calendar.DAY_OF_YEAR, current.getActualMaximum(Calendar.DAY_OF_YEAR));
        if (current.compareTo(end) <= 0) {
          indices.add(
            "%s-%s%c*".formatted(prefix, current.get(Calendar.YEAR), dateSeparator()));
          current.add(DAY_OF_MONTH, 1); // rollover to next year
          continue;
        } else {
          current.set(Calendar.DAY_OF_YEAR, 1); // rollback to first of the year
        }
      } else if (current.get(DAY_OF_MONTH) == 1) {
        // attempt to compress a month
        current.set(DAY_OF_MONTH, current.getActualMaximum(DAY_OF_MONTH));
        if (current.compareTo(end) <= 0) {
          indices.add(formatIndexPattern("%s-%s%c%02d%c*", current, prefix));
          current.add(DAY_OF_MONTH, 1); // rollover to next month
          continue;
        }
        current.set(DAY_OF_MONTH, 9); // try to compress days 0-9
        if (current.compareTo(end) <= 0) {
          indices.add(formatIndexPattern("%s-%s%c%02d%c0*", current, prefix));
          current.add(DAY_OF_MONTH, 1); // rollover to day 10
          continue;
        }
        current.set(DAY_OF_MONTH, 1); // set back to day 1
      } else if (current.get(DAY_OF_MONTH) == 10) {
        current.set(DAY_OF_MONTH, 19); // try to compress days 10-19
        if (current.compareTo(end) <= 0) {
          indices.add(formatIndexPattern("%s-%s%c%02d%c1*", current, prefix));
          current.add(DAY_OF_MONTH, 1); // rollover to day 20
          continue;
        }
        current.set(DAY_OF_MONTH, 10); // set back to day 10
      } else if (current.get(DAY_OF_MONTH) == 20) {
        current.set(DAY_OF_MONTH, 29); // try to compress days 20-29
        if (current.compareTo(end) <= 0) {
          indices.add(formatIndexPattern("%s-%s%c%02d%c2*", current, prefix));
          current.add(DAY_OF_MONTH, 1); // rollover to day 30
          continue;
        }
        current.set(DAY_OF_MONTH, 20); // set back to day 20
      }
      indices.add(formatTypeAndTimestamp(type, current.getTimeInMillis()));
      current.add(DAY_OF_MONTH, 1);
    }
    return indices;
  }
Returns a set of index patterns that represent the range provided. Notably, this compresses
months or years using wildcards (in order to send smaller API calls).

<p>For example, if {@code beginMillis} is 2016-11-30 and {@code endMillis} is 2017-01-02, the
result will be 2016-11-30, 2016-12-*, 2017-01-01 and 2017-01-02.
zipkin-storage/elasticsearch/src/main/java/zipkin2/elasticsearch/internal/IndexNameFormatter.java