private static int julianExtract(TimeUnitRange range, int julian) {
    int j = julian + 32044;
    int g = j / 146097;
    int dg = j % 146097;
    int c = (dg / 36524 + 1) * 3 / 4;
    int dc = dg - c * 36524;
    int b = dc / 1461;
    int db = dc % 1461;
    int a = (db / 365 + 1) * 3 / 4;
    int da = db - a * 365;
    int y = g * 400 + c * 100 + b * 4 + a;
    int m = (da * 5 + 308) / 153 - 2;
    int d = da - (m + 4) * 153 / 5 + 122;
    int year = y - 4800 + (m + 2) / 12;
    int month = (m + 2) % 12 + 1;
    int day = d + 1;
    switch (range) {
      case YEAR:
        return year;
      case YEAR_TO_MONTH:
      case DAY_TO_SECOND:
      case DAY_TO_MINUTE:
      case DAY_TO_HOUR:
      case HOUR:
      case HOUR_TO_MINUTE:
      case HOUR_TO_SECOND:
      case MINUTE_TO_SECOND:
      case MINUTE:
      case SECOND:
      case EPOCH:
      default:
        throw new AssertionError(range);
      case MONTH:
        return month;
      case DAY:
        return day;
      case ISOYEAR:
        int weekNumber = getIso8601WeekNumber(julian, year, month, day);
        if (weekNumber == 1 && month == 12) {
          return year + 1;
        } else {
          if (month == 1 && weekNumber > 50) {
            return year - 1;
          }

          return year;
        }
      case QUARTER:
        return (month + 2) / 3;
      case DOW:
        return (int) floorMod(julian + 1, 7L) + 1;
      case ISODOW:
        return (int) floorMod(julian, 7L) + 1;
      case WEEK:
        return getIso8601WeekNumber(julian, year, month, day);
      case DOY:
        long janFirst = ymdToJulian(year, 1, 1);
        return (int) ((long) julian - janFirst) + 1;
      case DECADE:
        return year / 10;
      case CENTURY:
        return year > 0 ? (year + 99) / 100 : (year - 99) / 100;
      case MILLENNIUM:
        return year > 0 ? (year + 999) / 1000 : (year - 999) / 1000;
    }
  }
Helper for CAST({date} AS VARCHAR(n)).
amoro-format-mixed/amoro-mixed-flink/amoro-mixed-flink-common/src/main/java/org/apache/amoro/flink/util/DateTimeUtils.java