package com.dji.sample.common.util;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * @author chenshixian
 **/

public class DateUtil {

    public static LocalDate getLocalDateFromDateStr(String date) {
        DateTimeFormatter dayFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return LocalDate.parse(date, dayFormatter);
    }

    public static long getEpochSecondFromDateStr(String date) {
        LocalDate localDate = getLocalDateFromDateStr(date);
        return getEpochSecondFromLocalDate(localDate);
    }

    public static long getEpochSecondFromLocalDate(LocalDate date) {
        return date.toEpochSecond(LocalTime.of(0, 0, 0), ZoneOffset.UTC);
    }


    public static long getTimeStampFromDateStr(String date) {

        return getEpochSecondFromDateStr(date) * 1000;
    }

    public static long getTimeStampFromDateStrNext(String date) {

        LocalDate localDate = getLocalDateFromDateStr(date);
        localDate = localDate.plusDays(1);

        return getEpochSecondFromLocalDate(localDate) * 1000;
    }

    public static String getNowStr() {
        return String.valueOf(new Date().getTime());
    }

}
