class DateFormatCustom {
  static String monthLocal(String month) {
    switch (month) {
      case "01":
        return "Januari";
      case "02":
        return "Februari";
      case "03":
        return "Maret";
      case "04":
        return "April";
      case "05":
        return "Mei";
      case "06":
        return "Juni";
      case "07":
        return "Juli";
      case "08":
        return "Agustus";
      case "09":
        return "September";
      case "10":
        return "Oktober";
      case "11":
        return "November";
      case "12":
        return "Desember";
      default:
        return "Unknown";
    }
  }

  static String monthInternational(String monthLocal) {
    switch (monthLocal) {
      case "Januari":
        return "01";
      case "Februari":
        return "02";
      case "Maret":
        return "03";
      case "April":
        return "04";
      case "Mei":
        return "05";
      case "Juni":
        return "06";
      case "Juli":
        return "07";
      case "Agustus":
        return "08";
      case "September":
        return "09";
      case "Oktober":
        return "10";
      case "November":
        return "11";
      case "Desember":
        return "12";
      default:
        return "Unknown";
    }
  }
}

String dateLocal(String dateTime, {bool fullDateTime = false}) {
  List<String> split = dateTime.split(" ");
  String date = split[0];
  List<String> splitDate = date.split("-");
  String year = splitDate[0];
  String month = DateFormatCustom.monthLocal(splitDate[1]);
  String tgl = splitDate[2];
  String result;
  if (fullDateTime) {
    result = "$tgl $month $year ${split[1]}";
  } else {
    result = "$tgl $month $year";
  }
  return result;
}

DateTime toInternationFormat(String dateLocal,
    {bool fullDateTime = false, timeInclude = true}) {
  List<String> splitDate = dateLocal.split(" ");
  String? time;
  if (fullDateTime) {
    // 01 Mei 2023 00:00:00
    time = splitDate[3];
  }
  String month = DateFormatCustom.monthInternational(splitDate[1]);
  String year = splitDate[2];
  String tgl = splitDate[0];
  DateTime? result;
  if (fullDateTime) {
    result = DateTime.tryParse("$year-$month-${tgl}T$time");
  } else {
    result = DateTime.tryParse("$year-$month-$tgl");
  }
  return result!;
}

String getOnlyDate(DateTime fullDateTime) {
  String f = fullDateTime.toString();
  List<String> s = f.split(" ");
  return s[0];
}
