Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright (c) 2013, Francis Galiegue <fgaliegue@gmail.com>
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the Lesser GNU General Public License as
  * published by the Free Software Foundation, either version 3 of the
  * License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Lesser GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.github.fge.jsonschema.format.helpers;
Abstract class for date/time related format attributes

Joda Time is used for date and time parsing: it can handle all defined formats, and catches more errors than the standard JDK's java.text.SimpleDateFormat does.

Furthermore (and more importantly), unlike java.text.SimpleDateFormat, Joda Time's org.joda.time.format.DateTimeFormatter is thread-safe!

public abstract class AbstractDateFormatAttribute
    extends AbstractFormatAttribute
    private final String format;
    protected AbstractDateFormatAttribute(final String fmtfinal String format)
    {
        super(fmt.);
        this. = format;
    }
    protected abstract DateTimeFormatter getFormatter();
    @Override
    public final void validate(final ProcessingReport report,
        final FullData data)
        throws ProcessingException
    {
        final JsonNode instance = data.getInstance().getNode();
        final DateTimeFormatter formatter = getFormatter();
        try {
            formatter.parseDateTime(instance.textValue());
        } catch (IllegalArgumentException ignored) {
            report.error(newMsg(data"invalidDateFormat")
                .put("expected"));
        }
    }
New to GrepCode? Check out our FAQ X