return compare(value, compare, Calendar.YEAR);
}
/**
* <p>Convert the parsed {@code Date} to a {@link Calendar}.</p>
*
* @param value The parsed {@code Date} object created.
* @param formatter The Format used to parse the value with.
* @return The parsed value converted to a {@link Calendar}.
*/
@Override
protected Object processParsedValue(final Object value, final Format formatter) {
return ((DateFormat) formatter).getCalendar();
}
/**
* <p>Validate/convert a {@link Calendar} using the default
* {@link Locale} and {@code TimeZone}.
*
* @param value The value validation is being performed on.
* @return The parsed {@link Calendar} if valid or {@code null}
* if invalid.
*/
public Calendar validate(final String value) {
return (Calendar) parse(value, (String) null, (Locale) null, (TimeZone) null);
}
/**
* <p>Validate/convert a {@link Calendar} using the specified
* {@link Locale} and default {@code TimeZone}.
*
* @param value The value validation is being performed on.
* @param locale The locale to use for the date format, system default if null.
* @return The parsed {@link Calendar} if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final Locale locale) {
return (Calendar) parse(value, (String) null, locale, (TimeZone) null);
}
/**
* <p>Validate/convert a {@link Calendar} using the specified
* {@link Locale} and {@code TimeZone}.
*
* @param value The value validation is being performed on.
* @param locale The locale to use for the date format, system default if null.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed {@link Calendar} if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final Locale locale, final TimeZone timeZone) {
return (Calendar) parse(value, (String) null, locale, timeZone);
}
/**
* <p>Validate/convert a {@link Calendar} using the specified
* <em>pattern</em> and default {@code TimeZone}.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against.
* @return The parsed {@link Calendar} if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern) {
return (Calendar) parse(value, pattern, (Locale) null, (TimeZone) null);
}
/**
* <p>Validate/convert a {@link Calendar} using the specified pattern
* and {@link Locale} and the default {@code TimeZone}.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against, or the
* default for the {@link Locale} if {@code null}.
* @param locale The locale to use for the date format, system default if null.
* @return The parsed {@link Calendar} if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern, final Locale locale) {
return (Calendar) parse(value, pattern, locale, (TimeZone) null);
}
/**
* <p>Validate/convert a {@link Calendar} using the specified
* pattern, and {@link Locale} and {@code TimeZone}.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against, or the
* default for the {@link Locale} if {@code null}.
* @param locale The locale to use for the date format, system default if null.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed {@link Calendar} if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern, final Locale locale, final TimeZone timeZone) {
return (Calendar) parse(value, pattern, locale, timeZone);
}
/**
* <p>Validate/convert a {@link Calendar} using the specified
* <em>pattern</em> and {@code TimeZone}.
*
* @param value The value validation is being performed on.
* @param pattern The pattern used to validate the value against.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed {@link Calendar} if valid or {@code null} if invalid.
*/
public Calendar validate(final String value, final String pattern, final TimeZone timeZone) {
return (Calendar) parse(value, pattern, (Locale) null, timeZone);
}
/**
* <p>Validate/convert a {@link Calendar} using the specified
* {@code TimeZone} and default {@link Locale}.
*
* @param value The value validation is being performed on.
* @param timeZone The Time Zone used to parse the date, system default if null.
* @return The parsed {@link Calendar} if valid or {@code null}
* if invalid.
*/
public Calendar validate(final String value, final TimeZone timeZone) {
return (Calendar) parse(value, (String) null, (Locale) null, timeZone);
}
} |