ca.gc.aafc.dina.validation.ISOPartialDateValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dina-base-api Show documentation
Show all versions of dina-base-api Show documentation
Base DINA API package for Java built on SpringBoot and Crnk
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