package com.friday.custody.utils;

import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class DateFormaterUtil {


    public static String changeFormaer(String value, String oldFormater, String newFormater) {
        LocalDateTime startDateTime =
                LocalDateTime.parse(value, DateTimeFormatter.ofPattern(oldFormater));
       return startDateTime.format(DateTimeFormatter.ofPattern(newFormater));

    }

    public static String formatterDateTime(String originDateStr, String originFormat, String targetFormat) {
        if (StringUtils.isBlank(originDateStr)) return null;
            LocalDateTime parse = LocalDateTime.parse(originDateStr, DateTimeFormatter.ofPattern(originFormat));
            return parse.format(DateTimeFormatter.ofPattern(targetFormat));
    }
    public static String removeZero(String value) {
        if (StringUtils.isBlank(value)) return null;
        return value.split("\\.")[0];

    }

    public static String removeTimeAndConnectionSymbol(String originDateStr,String connectionSymbol) {
        if (StringUtils.isBlank(originDateStr)) {
            return null;
        }
       return originDateStr.split(" ")[0].replace(connectionSymbol, "");
    }

}
