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

com.github.restup.bind.converter.StringToLocalDateTimeConverter Maven / Gradle / Ivy

There is a newer version: 0.0.5
Show newest version
package com.github.restup.bind.converter;

import java.time.LocalDateTime;
import java.util.function.Function;

import org.apache.commons.lang3.StringUtils;

public class StringToLocalDateTimeConverter implements Function {

    private static final String DEFAULT_TIME = "T00:00:00";

    private final boolean lenient;

    public StringToLocalDateTimeConverter() {
        this(true);
    }

    public StringToLocalDateTimeConverter(boolean lenient) {
        this.lenient = lenient;
    }

    @Override
    public LocalDateTime apply(String s) {
        String d = s;
        if (lenient) {
            if (s.length() == 10) {
                d = StringUtils.join(s, DEFAULT_TIME);
            }
        }
        return LocalDateTime.parse(d);

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy