class LoaderUtils {

  public static YearMonth parseYearMonth(String str) {
    try {
      // yyyy-MM
      if (str.length() == 7 && str.charAt(4) == '-') {
        return YearMonth.parse(str, YYYY_MM_DASH);
      }
      // MMM-yy
      // MMM-yyyy
      // MMMyy
      // MMMyyyy
      if (str.length() >= 5 && !Character.isDigit(str.charAt(0))) {
        return YearMonth.parse(str, MMM_YEAR);
      }
      // d/M/yyyy - handle Excel converting YearMonth to date
      if (str.length() >= 8 && (str.charAt(1) == '/' || str.charAt(2) == '/')) {
        LocalDate date = LocalDate.parse(str, D_M_YEAR_SLASH);
        if (date.getDayOfMonth() == 1) {
          return YearMonth.of(date.getYear(), date.getMonth());
        }
        throw new IllegalArgumentException("Found Excel-style date but day-of-month was not set to 1:" + str);
      }
      // yyyyMM
      return YearMonth.parse(str, YYYYMM);

    } catch (DateTimeParseException ex) {
      throw new IllegalArgumentException(
          "Unknown date format, must be formatted as 'yyyy-MM', 'yyyyMM', " +
              "'MMM-yyyy', 'MMMyyyy', 'MMM-yy' or 'MMMyy' but was: " + str);
    }
  }

  private  LoaderUtils();

}