import java.time.Duration;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class ZonaDST {
    public static void main(String[] args) {
        ZoneId newYork = ZoneId.of("America/New_York");

        // 8 Maret 2026: daylight saving dimulai di New York (-05:00 -> -04:00).
        ZonedDateTime sebelum = ZonedDateTime.of(2026, 3, 7, 12, 0, 0, 0, newYork);
        ZonedDateTime sesudah = ZonedDateTime.of(2026, 3, 8, 12, 0, 0, 0, newYork);

        System.out.println("7 Mar 12:00 : " + sebelum);
        System.out.println("8 Mar 12:00 : " + sesudah);
        System.out.println("isDaylightSavings 7 Mar  : "
                + newYork.getRules().isDaylightSavings(sebelum.toInstant()));
        System.out.println("isDaylightSavings 8 Mar  : "
                + newYork.getRules().isDaylightSavings(sesudah.toInstant()));

        // plusDays menjaga waktu dinding; plus(Duration) menggeser waktu fisik.
        System.out.println("sebelum.plusDays(1)     : " + sebelum.plusDays(1));
        System.out.println("sebelum.plus 24 jam     : " + sebelum.plus(Duration.ofHours(24)));
        System.out.println("durasi antar dua siang  : "
                + Duration.between(sebelum.toInstant(), sesudah.toInstant()));

        // Jam 02:30 pada 8 Maret tidak pernah ada di New York (meloncat ke 03:00).
        System.out.println("jam 02:30 yang hilang   : "
                + ZonedDateTime.of(2026, 3, 8, 2, 30, 0, 0, newYork));

        // 1 November 2026: DST berakhir; jam 01:30 terjadi dua kali.
        ZonedDateTime ganda = ZonedDateTime.of(2026, 11, 1, 1, 30, 0, 0, newYork);
        System.out.println("jam 01:30 ganda         : " + ganda);
        System.out.println("versi offset akhir      : " + ganda.withLaterOffsetAtOverlap());
    }
}
