package net.ranides.assira.time2;

import net.ranides.assira.junit.NewAssert;
import org.junit.Test;

import java.time.ZonedDateTime;
import java.time.format.DateTimeParseException;

public class DateTimeParsersTest {

    @Test
    public void testParsePolishDateTime() {
        ZonedDate date1 = ZonedDate.now().withZoneUtc();
        ZonedDate date2 = ZonedDate.now().plusDays(25);
        ZonedDateTime date3 = ZonedDateTime.now().plusDays(40);
        ZonedDate date4 = ZonedDate.ofEpochSecond(DateTimeUtils.ZONE_PL, 11_800_150L);

        date1.isAfter(date2);
        date1.isAfter(date3);

        ZonedTime time1 = ZonedTime.now();
        ZonedTime time2 = ZonedTime.now().plusMinutes(15);
        ZonedDateTime time3 = ZonedDateTime.now().plusMinutes(30);

        time1.isAfter(time2);
        time1.isAfter(time3);

        ZonedDateTime a = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+02:00[Poland]");
        ZonedDateTime b = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00Z");
        ZonedDateTime c = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+06:00[Europe/Warsaw]");
        ZonedDateTime d = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+17:00[Europe/Warsaw]");
        ZonedDateTime e = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+06:00");
        ZonedDateTime f = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+17:00");
        ZonedDateTime g = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00");
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
        System.out.println(f);
        System.out.println(g);
    }

    @SuppressWarnings({"timezone-explicit", "timezone-hazard"})
    @Test
    public void testParsePolishDateTimeSupressed() {

        ZonedDate date1 = ZonedDate.now().withZoneUtc();

        ZonedDate date2 = ZonedDate.now().plusDays(25);
        ZonedDateTime date3 = ZonedDateTime.now().plusDays(40);
        ZonedDate date4 = ZonedDate.ofEpochSecond(DateTimeUtils.ZONE_PL, 11_800_150L);

        date1.isAfter(date2);
        date1.isAfter(date3);

        ZonedTime time1 = ZonedTime.now();
        ZonedTime time2 = ZonedTime.now().plusMinutes(15);
        ZonedDateTime time3 = ZonedDateTime.now().plusMinutes(30);

        time1.isAfter(time2);
        time1.isAfter(time3);

        ZonedDateTime a = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+02:00[Poland]");
        ZonedDateTime b = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00Z");
        ZonedDateTime c = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+06:00[Europe/Warsaw]");
        ZonedDateTime d = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+17:00[Europe/Warsaw]");
        ZonedDateTime e = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+06:00");
        ZonedDateTime f = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00+17:00");
        ZonedDateTime g = DateTimeParsers.parsePolishDateTime("2020-08-24T08:45:00");
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
        System.out.println(f);
        System.out.println(g);
    }

    @Test
    public void testParseDateTime() {
        ZonedDateTime a = DateTimeParsers.parseDateTime("2020-08-24T08:45:00+02:00[Poland]");
        ZonedDateTime b = DateTimeParsers.parseDateTime("2020-08-24T08:45:00Z");
        ZonedDateTime c = DateTimeParsers.parseDateTime("2020-08-24T08:45:00+06:00[Europe/Warsaw]");
        ZonedDateTime d = DateTimeParsers.parseDateTime("2020-08-24T08:45:00+17:00[Europe/Warsaw]");
        ZonedDateTime e = DateTimeParsers.parseDateTime("2020-08-24T08:45:00+06:00");
        ZonedDateTime f = DateTimeParsers.parseDateTime("2020-08-24T08:45:00+17:00");

        NewAssert.assertThrows(DateTimeParseException.class, () -> {
            ZonedDateTime g = DateTimeParsers.parseDateTime("2020-08-24T08:45:00");
            System.out.println(g);
        });

        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(d);
        System.out.println(e);
        System.out.println(f);
    }


    @Test
    public void testParseDate() {
        ZonedDate a = DateTimeParsers.parseUtcDate("2024-10-16");

        System.out.println(a);
    }
}