import java.time.LocalDate;
import java.time.Period;
import java.time.temporal.ChronoUnit;

public class RentangPeriod {
    public static void main(String[] args) {
        // Membuat periode dari komponen kalender.
        Period sewa = Period.of(1, 2, 10); // 1 tahun, 2 bulan, 10 hari
        System.out.println("Period.of(1, 2, 10) : " + sewa);
        System.out.println("Period.ofDays(10)   : " + Period.ofDays(10));
        System.out.println("Period.ofWeeks(3)   : " + Period.ofWeeks(3));

        // Selisih kalender antara dua tanggal.
        LocalDate mulai = LocalDate.of(2026, 1, 15);
        LocalDate selesai = LocalDate.of(2026, 3, 20);
        Period selisih = Period.between(mulai, selesai);
        System.out.println("between             : " + selisih);
        System.out.println("getYears/getMonths/getDays: "
                + selisih.getYears() + " / " + selisih.getMonths() + " / " + selisih.getDays());

        // Total dalam satu satuan memakai ChronoUnit.
        System.out.println("total hari          : " + ChronoUnit.DAYS.between(mulai, selesai));
        System.out.println("total bulan penuh   : " + ChronoUnit.MONTHS.between(mulai, selesai));

        // Arah terbalik menghasilkan periode negatif.
        System.out.println("between terbalik    : " + Period.between(selesai, mulai));

        // Periode dijumlahkan ke tanggal.
        System.out.println("mulai + sewa        : " + mulai.plus(sewa));
    }
}
