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

org.everit.json.schema.internal.TimeFormatValidator Maven / Gradle / Ivy

Go to download

Implementation of the JSON Schema Core Draft v4 specification built with the org.json API

There is a newer version: 1.14.4
Show newest version
package org.everit.json.schema.internal;

import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.util.Arrays;
import java.util.List;

/**
 * Implementation of the "time" format value.
 */
public class TimeFormatValidator extends TemporalFormatValidator {
    private static final String FORMATS_ACCEPTED = Arrays.asList(
            "HH:mm:ssZ",
            "HH:mm:ss.[0-9]{1,9}Z",
            "HH:mm:ss[+-]HH:mm",
            "HH:mm:ss.[0-9]{1,9}[+-]HH:mm"
    ).toString();

    private static final String PARTIAL_TIME_PATTERN = "HH:mm:ss";

    private static final DateTimeFormatter FORMATTER;

    static {
        final DateTimeFormatterBuilder builder = new DateTimeFormatterBuilder()
                .appendPattern(PARTIAL_TIME_PATTERN)
                .appendOptional(SECONDS_FRACTION_FORMATTER)
                .appendPattern(ZONE_OFFSET_PATTERN);

        FORMATTER = builder.toFormatter();
    }

    public TimeFormatValidator() {
        super(FORMATTER, FORMATS_ACCEPTED);
    }

    @Override
    public String formatName() {
        return "time";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy