package com.jwipc.config;

import cn.hutool.core.util.StrUtil;
import com.jwipc.util.DateUtils;
import org.springframework.stereotype.Component;

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

/**
 * <p> </p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Component
public class MapperStructConfig {
    public static String asString(LocalDateTime localDateTime) {
        return Objects.nonNull(localDateTime) ? localDateTime.format(
                DateTimeFormatter.ofPattern(DateUtils.YYYY_MMDD_HMS)) : null;
    }

    public static LocalDateTime asLocalDateTime(String localDateTime) {
        return StrUtil.isNotEmpty(localDateTime) ? cn.hutool.core.date.DateUtil.parseLocalDateTime(localDateTime,
                DateUtils.yyyyMMddDash) : null;
    }

}
