package com.njyunzhi.pet_identity.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter;

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

/**
 * 处理 ResquestParam 中的日期格式
 */

@Configuration
public class DateConverterConfig {
    @Bean
    public Converter<String, LocalDateTime> localDateTimeConverter() {
        return new Converter<String, LocalDateTime>() {
            @Override
            public LocalDateTime convert(String source) {
                if ("".equals(source)) {
                    return null;
                }

                String dt = source + "+0800";
                return LocalDateTime.parse(dt, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ssZ"));
            }
        };
    }
}
