All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.bootystar.autoconfigure.databind.converter.String2LocalDateConverter Maven / Gradle / Ivy

The newest version!
package io.github.bootystar.autoconfigure.databind.converter;

import io.github.bootystar.autoconfigure.databind.constant.DateConst;
import org.springframework.core.convert.converter.Converter;

import java.time.LocalDate;

/**
 * @author booty
 * @since 2023/10/27
 */
public class String2LocalDateConverter implements Converter {


    @Override
    public LocalDate convert(String source) {
        if (source.isEmpty()) {
            return null;
        }
        int length = source.length();
        switch (length) {
            case 4:
                source += "-01-01";
                break;
            case 7:
                source += "-01";
                break;
            default:
                break;
        }
        return LocalDate.parse(source, DateConst.LOCAL_DATE_FORMATTER);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy