//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.base.plan.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
import java.util.Date;
import java.util.TimeZone;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class DateTool {
    static final ZoneId zoneid_utc = ZoneId.of("UTC");
    static final DateTimeFormatter dateTimeFormatter;
    static final DateTimeFormatter dateTimeFormatter_iso;

    static {
        dateTimeFormatter = (new DateTimeFormatterBuilder()).appendPattern("yyyy-MM-dd HH:mm:ss").appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true).toFormatter();
        dateTimeFormatter_iso = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
    }

    public DateTool() {
    }

    public static XMLGregorianCalendar getXMLTime() {
        String format = "yyyy-MM-dd'T'hh:mm:ss'Z'";
        SimpleDateFormat formater = new SimpleDateFormat(format);
        formater.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = formater.format(new Date());
        XMLGregorianCalendar date = null;

        try {
            date = DatatypeFactory.newInstance().newXMLGregorianCalendar(s);
        } catch (DatatypeConfigurationException var5) {
            var5.printStackTrace();
        }

        return date;
    }

    public static String getTime1() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String getTime2() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String getTime3() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String getTime4() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String getTime5() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String getTime6() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String getLaterTime1(int space) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date d = new Date();
        long t = d.getTime() / 1000L + (long) (space * 60 * 60);
        d.setTime(t * 1000L);
        String laterTime = df.format(d);
        return laterTime;
    }

    public static String getLaterSecond(int space) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date d = new Date();
        long t = d.getTime() / 1000L + (long) space;
        d.setTime(t * 1000L);
        String laterTime = df.format(d);
        return laterTime;
    }

    public static String getLaterTime3(int space) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date d = new Date();
        long t = d.getTime() / 1000L + (long) (space * 60 * 60);
        d.setTime(t * 1000L);
        String laterTime = df.format(d);
        return laterTime;
    }

    public static String getDate() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static Date StringToDate(String s) throws ParseException {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        Date d = df.parse(s);
        return d;
    }

    public static String DateToString(Date d) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String DateToString_full(Date d) {
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static String getDateYYMMDD() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyMMdd");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static long getDuration(String t1, String t2) {
        Date date1 = StringToDate1(t1);
        Date date2 = StringToDate1(t2);
        long result = date1.getTime() - date2.getTime();
        return result;
    }

    public static String getMonth() {
        Date d = new Date();
        SimpleDateFormat df = new SimpleDateFormat("yyMM");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(d);
        return s;
    }

    public static Date StringToDate1(String s) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            Date d = df.parse(s);
            return d;
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static Date StringToDateByLocalTZ(String s) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            df.setTimeZone(TimeZone.getTimeZone("GMT+08:00"));
            Date d = df.parse(s);
            return d;
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static Date StringToDate6(String s) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            Date d = df.parse(s);
            return d;
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static Date StringToDate3(String s) {
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyy MM dd HH:mm:ss");
            df.setTimeZone(TimeZone.getTimeZone("UTC"));
            Date d = df.parse(s);
            return d;
        } catch (Exception var3) {
            var3.printStackTrace();
            return null;
        }
    }

    public static int DateCompare(Date date1, Date date2) {
        long result = date1.getTime() - date2.getTime();
        if (result > 0L) {
            return 1;
        } else {
            return result == 0L ? 0 : -1;
        }
    }

    public static boolean ifSameMonth(String yyyy_MM_dd1, String yyyy_MM_dd2) {
        return yyyy_MM_dd1.subSequence(5, 6).equals(yyyy_MM_dd2.subSequence(5, 6));
    }

    public static int DateCompare(String time, String format) {
        Date date = getTimebyType(format, time);
        return DateCompare(date, new Date());
    }

    public static Date getTimebyType(String format, String time) {
        String year = time.substring(format.indexOf("yyyy"), format.indexOf("yyyy") + 4);
        String month = time.substring(format.indexOf("MM"), format.indexOf("MM") + 2);
        String day = time.substring(format.indexOf("dd"), format.indexOf("dd") + 2);
        String hour = time.substring(format.indexOf("HH"), format.indexOf("HH") + 2);
        String minitue = time.substring(format.indexOf("mm"), format.indexOf("mm") + 2);
        String second = time.substring(format.indexOf("ss"), format.indexOf("ss") + 2);
        if (year != null && month != null && day != null && hour != null && minitue != null && second != null) {
            String timenew = year + month + day + hour + minitue + second;

            try {
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
                df.setTimeZone(TimeZone.getTimeZone("UTC"));
                Date d = df.parse(timenew);
                return d;
            } catch (Exception var11) {
                var11.printStackTrace();
                return null;
            }
        } else {
            return null;
        }
    }

    public static Boolean DateCompare1(String start1, String end1, String start2, String end2) {
        Date s1 = StringToDate1(start1);
        Date e1 = StringToDate1(end1);
        Date s2 = StringToDate1(start2);
        Date e2 = StringToDate1(end2);
        if (s1.after(s2) && s1.after(e2)) {
            return false;
        } else {
            return !e1.after(s2) && !e1.after(e2) ? false : true;
        }
    }

    public static Boolean DateCompare3(String start1, String end1, String start2, String end2) {
        Date s1 = StringToDate3(start1);
        Date e1 = StringToDate3(end1);
        Date s2 = StringToDate3(start2);
        Date e2 = StringToDate3(end2);
        if (s1.after(s2) && s1.after(e2)) {
            return false;
        } else {
            return e1.after(s2) || e1.after(e2);
        }
    }

    public static Boolean DateCompare1(String start, String end) {
        Date s = StringToDate1(start);
        Date e = StringToDate1(end);
        return s.after(e);
    }

    public static Boolean DateCompare3(String start, String end) {
        Date s = StringToDate3(start);
        Date e = StringToDate3(end);
        return s.after(e);
    }

    public static Boolean DateComparetoSystem1(String end) {
        Date e = StringToDate1(end);
        Date sys = StringToDate1(getTime6());
        return sys.after(e);
    }

    public static Boolean DateComparetoSystem3(String end) {
        Date e = StringToDate3(end);
        Date sys = StringToDate3(getTime3());
        return sys.after(e);
    }

    public static Boolean DateCompareSpace1(String start) {
        Date e = StringToDate1(start);
        Date sys = StringToDate1(getTime6());
        long s = (e.getTime() - sys.getTime()) / 1000L;
        return s <= 0L ? false : true;
    }

    public static Boolean DateCompareSpace3(String start) {
        Date e = StringToDate3(start);
        Date sys = StringToDate3(getTime3());
        long s = (e.getTime() - sys.getTime()) / 1000L;
        return s <= 0L ? false : true;
    }

    public static Boolean DateCompareSpace4(String start, int space) {
        Date e = StringToDate3(start);
        Date sys = StringToDate3(getTime3());
        long s = e.getTime() - sys.getTime() - (long) (space * 1000);
        return s <= 0L ? false : true;
    }

    public static String getDelayDateStr(Date d, long delay) {
        long l = d.getTime();
        l += delay;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(l);
        return s;
    }

    public static String getDelayDate(Date d, int delayDay) {
        long l = d.getTime();
        l += (long) (delayDay * 86400);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        df.setTimeZone(TimeZone.getTimeZone("UTC"));
        String s = df.format(l);
        return s;
    }

    public static String dirProcess(String dir) {
        String s = dir.trim();
        s = dir.replace("/", "\\");
        s = s.replace("\\\\", "\\");
        if (s.substring(s.length() - 1).equals("\\")) {
            s = s.substring(0, s.length() - 1);
        }

        return s;
    }

    public static ZonedDateTime parseZonedDateTime(String datetimestring) {
        return LocalDateTime.from(dateTimeFormatter.withZone(zoneid_utc).parse(datetimestring)).atZone(zoneid_utc);
    }

    public static OffsetDateTime parseOffsetDateTime(String datetimestring) {
        OffsetDateTime datetime = null;

        try {
            datetime = LocalDateTime.from(dateTimeFormatter.withZone(zoneid_utc).parse(datetimestring)).atOffset(ZoneOffset.UTC);
        } catch (Exception var3) {
        }

        return datetime;
    }

    public static String OffsetDateTimetoFullDateTimeStr(OffsetDateTime date) {
        String str_date = null;
        if (date != null) {
            str_date = dateTimeFormatter.format(date);
        }

        return str_date;
    }

    public static String UTCOffsetDateTimeToLocalFullDateTimeStr(OffsetDateTime datetime_UTC) {
        LocalDateTime localDateTime = datetime_UTC.atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();
        return localDateTime.format(dateTimeFormatter);
    }

    public static String UTCFullDateTimeStrToLocalFullDateTimeStr(String datetime_UTC) {
        OffsetDateTime offsetDateTime = parseOffsetDateTime(datetime_UTC);
        LocalDateTime localDateTime = offsetDateTime.atZoneSameInstant(ZoneId.systemDefault()).toLocalDateTime();
        return localDateTime.format(dateTimeFormatter);
    }

    public static String LocalFullDateTimeStrToUTCFullDateTimeStr(String datetime_local) {
        OffsetDateTime offsetDateTime = LocalDateTime.from(dateTimeFormatter.parse(datetime_local)).atZone(ZoneOffset.systemDefault()).toOffsetDateTime();
        LocalDateTime localDateTime = offsetDateTime.atZoneSameInstant(ZoneId.of("UTC")).toLocalDateTime();
        return localDateTime.format(dateTimeFormatter);
    }

    public static OffsetDateTime parseStrToOffsetDateTime(String datetimestring, int timezoneOffset) {
        return LocalDateTime.from(dateTimeFormatter.parse(datetimestring)).atOffset(ZoneOffset.ofHours(timezoneOffset));
    }

    public static String OffsetDateTimetoFullDateTimeStrAtGivenZone(OffsetDateTime date, int zoneOffset) {
        ZoneId zoneid_offset = ZoneOffset.ofHours(zoneOffset).normalized();
        DateTimeFormatter dateTimeFormatter_offset = (new DateTimeFormatterBuilder()).appendPattern("yyyy-MM-dd HH:mm:ss").appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true).toFormatter().withZone(zoneid_offset);
        return dateTimeFormatter_offset.format(date);
    }

    public static String OffsetDateTimetoISODateTimeStrAtGivenZone(OffsetDateTime date, int zoneOffset) {
        ZoneId zoneid_offset = ZoneOffset.ofHours(zoneOffset).normalized();
        return dateTimeFormatter_iso.withZone(zoneid_offset).format(date);
    }

    public static boolean isIntersection(Long start1, Long end1, Long start2, Long end2) {
        return ((start1 >= start2)
                && start1 < end2)
                || ((start1 <= start2)
                && start1 <= end2)
                || ((start2 >= start1)
                && start2 < end1)
                || ((start2 > start1)
                && start2 <= end1);
    }

    public static boolean isIntersectionnew(Long start1, Long end1, Long start2, Long end2) {

        if (end1<start2||end2<start1){
            return false;
        }else {
            return true;
        }
    }

}
