Merge branch '6.1.x'

This commit is contained in:
Sam Brannen
2024-07-05 19:01:21 +02:00
5 changed files with 26 additions and 23 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ import org.springframework.util.Assert;
/**
* Configures basic date formatting for use with Spring, primarily for
* {@link org.springframework.format.annotation.DateTimeFormat} declarations.
* Applies to fields of type {@link Date}, {@link Calendar} and {@code long}.
* Applies to fields of type {@link Date}, {@link Calendar}, and {@code long}.
*
* <p>Designed for direct instantiation but also exposes the static
* {@link #addDateConverters(ConverterRegistry)} utility method for

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,8 +77,8 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
/**
* Set whether standard ISO formatting should be applied to all date/time types.
* Default is "false" (no).
* <p>If set to "true", the "dateStyle", "timeStyle" and "dateTimeStyle"
* <p>Default is "false" (no).
* <p>If set to "true", the "dateStyle", "timeStyle", and "dateTimeStyle"
* properties are effectively ignored.
*/
public void setUseIsoFormat(boolean useIsoFormat) {
@@ -89,7 +89,7 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
/**
* Set the default format style of {@link java.time.LocalDate} objects.
* Default is {@link java.time.format.FormatStyle#SHORT}.
* <p>Default is {@link java.time.format.FormatStyle#SHORT}.
*/
public void setDateStyle(FormatStyle dateStyle) {
this.factories.get(Type.DATE).setDateStyle(dateStyle);
@@ -97,7 +97,7 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
/**
* Set the default format style of {@link java.time.LocalTime} objects.
* Default is {@link java.time.format.FormatStyle#SHORT}.
* <p>Default is {@link java.time.format.FormatStyle#SHORT}.
*/
public void setTimeStyle(FormatStyle timeStyle) {
this.factories.get(Type.TIME).setTimeStyle(timeStyle);
@@ -105,7 +105,7 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
/**
* Set the default format style of {@link java.time.LocalDateTime} objects.
* Default is {@link java.time.format.FormatStyle#SHORT}.
* <p>Default is {@link java.time.format.FormatStyle#SHORT}.
*/
public void setDateTimeStyle(FormatStyle dateTimeStyle) {
this.factories.get(Type.DATE_TIME).setDateTimeStyle(dateTimeStyle);
@@ -139,7 +139,7 @@ public class DateTimeFormatterRegistrar implements FormatterRegistrar {
/**
* Set the formatter that will be used for objects representing date and time values.
* <p>This formatter will be used for {@link LocalDateTime}, {@link ZonedDateTime}
* <p>This formatter will be used for {@link LocalDateTime}, {@link ZonedDateTime},
* and {@link OffsetDateTime} types. When specified, the
* {@link #setDateTimeStyle dateTimeStyle} and
* {@link #setUseIsoFormat useIsoFormat} properties will be ignored.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,10 +29,18 @@ import org.springframework.util.StringUtils;
*/
abstract class DateTimeFormatterUtils {
/**
* Create a {@link DateTimeFormatter} for the supplied pattern, configured with
* {@linkplain ResolverStyle#STRICT strict} resolution.
* <p>Note that the strict resolution does not affect the parsing.
* @param pattern the pattern to use
* @return a new {@code DateTimeFormatter}
* @see ResolverStyle#STRICT
*/
static DateTimeFormatter createStrictDateTimeFormatter(String pattern) {
// Using strict parsing to align with Joda-Time and standard DateFormat behavior:
// Using strict resolution to align with Joda-Time and standard DateFormat behavior:
// otherwise, an overflow like e.g. Feb 29 for a non-leap-year wouldn't get rejected.
// However, with strict parsing, a year digit needs to be specified as 'u'...
// However, with strict resolution, a year digit needs to be specified as 'u'...
String patternToUse = StringUtils.replace(pattern, "yy", "uu");
return DateTimeFormatter.ofPattern(patternToUse).withResolverStyle(ResolverStyle.STRICT);
}