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

ca.gc.aafc.dina.validation.ISOPartialDateValidator Maven / Gradle / Ivy

There is a newer version: 0.132
Show newest version
package ca.gc.aafc.dina.validation;

import java.time.format.DateTimeParseException;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import ca.gc.aafc.dina.datetime.ISODateTime;
import ca.gc.aafc.dina.datetime.ISODateTime.Format;

public class ISOPartialDateValidator implements ConstraintValidator {

  @Override
  public boolean isValid(String value, ConstraintValidatorContext context) {
    try {
      if (value != null) {
        ISODateTime isoDateTime = ISODateTime.parse(value);
        Format format = isoDateTime.getFormat();
        return format.getPrecision() <= Format.YYYY_MM_DD.getPrecision();
      }
      return true;
    } catch (DateTimeParseException e) {
      return false;
    }
  }
  
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy