import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.Locale;

public class ParsingKustom {
    public static void main(String[] args) {
        Locale id = Locale.forLanguageTag("id");

        // Pola kustom untuk format sehari-hari.
        DateTimeFormatter polaTgl = DateTimeFormatter.ofPattern("dd/MM/yyyy");
        LocalDate dariTeks = LocalDate.parse("15/01/2026", polaTgl);
        System.out.println("dd/MM/yyyy      : " + dariTeks);

        // Pola dengan nama bulan harus cocok dengan Locale formatter.
        DateTimeFormatter polaBulan = DateTimeFormatter.ofPattern("dd MMMM yyyy").withLocale(id);
        System.out.println("bulan Indonesia : " + LocalDate.parse("15 Januari 2026", polaBulan));

        DateTimeFormatter polaEn = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.US);
        System.out.println("bulan Inggris   : " + LocalDate.parse("January 15, 2026", polaEn));

        // Teks yang tidak sesuai pola melempar DateTimeParseException.
        try {
            LocalDate salah = LocalDate.parse("15-01-2026", polaTgl);
            System.out.println("tidak terjadi: " + salah);
        } catch (DateTimeParseException e) {
            System.out.println("gagal parse     : " + e.getMessage());
            System.out.println("posisi galat    : " + e.getErrorIndex());
        }
    }
}
