package com.ysu.zyw.tc.base.utils;

import lombok.SneakyThrows;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

import javax.annotation.Nonnull;
import java.util.Date;

import static com.google.common.base.Preconditions.checkNotNull;

@Slf4j
@UtilityClass
public class TcDateUtils {

    public static final String FULL_DATE_FORMAT_VALUE = "yyyy-MM-dd HH:mm:ss.SSS";

    public static final String SIMPLE_DATE_FORMAT_VALUE = "yyyy-MM-dd HH:mm:ss";

    public static final String[] DATE_FORMATS =
            {
                    FULL_DATE_FORMAT_VALUE,
                    SIMPLE_DATE_FORMAT_VALUE
            };

    @SneakyThrows
    public static Date parse(@Nonnull String text) {
        checkNotNull(text);
        return DateUtils.parseDate(text, DATE_FORMATS);
    }

    public static String format(@Nonnull Date date) {
        checkNotNull(date);
        return format(date, FULL_DATE_FORMAT_VALUE);
    }

    public static String format(@Nonnull Date date, @Nonnull String format) {
        checkNotNull(date);
        checkNotNull(format);
        return DateFormatUtils.format(date, format);
    }

    public static long duration(Date d1, Date d2) {
        checkNotNull(d1);
        checkNotNull(d2);
        return d2.getTime() - d1.getTime();
    }

}

@@ -1281,19 +1281,26 @@
 ate 
-d1
+before
 , Date 
-d2
+after
 ) %7B%0A
@@ -1320,18 +1320,22 @@
 NotNull(
-d1
+before
 );%0A     
@@ -1350,18 +1350,21 @@
 NotNull(
-d2
+after
 );%0A     
@@ -1377,10 +1377,13 @@
 urn 
-d2
+after
 .get
@@ -1395,10 +1395,14 @@
 ) - 
-d1
+before
 .get

optimize (46)