package com.fs.app.utils;

import com.fs.common.exception.CustomException;
import com.fs.common.utils.StringUtils;

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class ValidateUtil {
    public static void validate(String startTime, String endTime) throws CustomException {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)){
            try {
                formatter.parse(startTime);
            } catch (DateTimeParseException e) {
                throw new CustomException("开始时间格式不正确，应为 yyyy-MM-dd HH:mm:ss");
            }

            try {
                formatter.parse(endTime);
            } catch (DateTimeParseException e) {
                throw new CustomException("结束时间格式不正确，应为 yyyy-MM-dd HH:mm:ss");
            }
        }

    }
}
