import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
import java.util.LinkedHashSet;
import java.util.Locale;
}
//
try {
- DateTimeFormatter.ofPattern(dateFormat);
+ DateTimeFormatter.ofPattern(dateFormat).withResolverStyle(ResolverStyle.STRICT);
}
catch (IllegalArgumentException exception) {
throw new IllegalArgumentException(String.format("Invalid 'dateFormat': %s.", dateFormat)); // no need to propagate exception
//
LocalDate d = null;
try {
- d = LocalDate.parse(x, DateTimeFormatter.ofPattern(inputDateFormat, inputLocale));
+ d = LocalDate.parse(x, DateTimeFormatter.ofPattern(inputDateFormat, inputLocale).withResolverStyle(ResolverStyle.STRICT));
}
catch (DateTimeParseException exception) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDateFormat)); // no need to propagate exception
throw new IllegalArgumentException("Invalid 'outputLocale': null.");
}
//
- return date.format(DateTimeFormatter.ofPattern(outputDateFormat, outputLocale));
+ return date.format(DateTimeFormatter.ofPattern(outputDateFormat, outputLocale).withResolverStyle(ResolverStyle.STRICT));
}
public LocalDate getDateFromString(String x) throws MInvalidConversionFormatException {
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
+import java.time.format.ResolverStyle;
import java.util.LinkedHashSet;
import java.util.Locale;
}
//
try {
- DateTimeFormatter.ofPattern(datetimeFormat);
+ DateTimeFormatter.ofPattern(datetimeFormat).withResolverStyle(ResolverStyle.STRICT);
}
catch (IllegalArgumentException exception) {
throw new IllegalArgumentException(String.format("Invalid 'datetimeFormat': %s.", datetimeFormat)); // no need to propagate exception
//
LocalDateTime dt = null;
try {
- dt = LocalDateTime.parse(x, DateTimeFormatter.ofPattern(inputDatetimeFormat, inputLocale));
+ dt = LocalDateTime.parse(x, DateTimeFormatter.ofPattern(inputDatetimeFormat, inputLocale).withResolverStyle(ResolverStyle.STRICT));
}
catch (DateTimeParseException exception) {
throw new MInvalidConversionFormatException(String.format("Invalid 'x' or parsing: %s (input format: %s).", x, inputDatetimeFormat)); // no need to propagate exception
throw new IllegalArgumentException("Invalid 'outputLocale': null.");
}
//
- return datetime.format(DateTimeFormatter.ofPattern(outputDatetimeFormat, outputLocale));
+ return datetime.format(DateTimeFormatter.ofPattern(outputDatetimeFormat, outputLocale).withResolverStyle(ResolverStyle.STRICT));
}
public LocalDateTime getDatetimeFromString(String x) throws MInvalidConversionFormatException {