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

nl.vpro.jackson2.NattySupport Maven / Gradle / Ivy

There is a newer version: 5.3.2
Show newest version
package nl.vpro.jackson2;

import java.time.Instant;
import java.util.*;

import org.natty.DateGroup;
import org.natty.Parser;

import nl.vpro.util.BindingUtils;
import nl.vpro.util.DateUtils;

/**
 * The dependency on natty in {@link StringInstantToJsonTimestamp} is optional. Put support for it in this class, so we can just catch the resulting NoClassDefFoundError.
 * @author Michiel Meeuwissen
 * @since 2.14
 */

class NattySupport {
    private static final Parser PARSER = new Parser(TimeZone.getTimeZone(BindingUtils.DEFAULT_ZONE));


    static Optional parseDate(String value) {
        List groups = PARSER.parse(value);
        if (groups.size() == 1) {
            return Optional.ofNullable(DateUtils.toInstant(groups.get(0).getDates().get(0)));
        }
        return Optional.empty();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy