Modernize java.time API usages

See gh-35861
Signed-off-by: Vincent Potucek <vpotucek@me.com>
This commit is contained in:
Vincent Potucek
2025-11-25 14:42:05 +01:00
committed by Sébastien Deleuze
parent 3686b89ab5
commit 83bbf16e6c
14 changed files with 31 additions and 32 deletions
@@ -27,6 +27,7 @@ import java.text.DecimalFormatSymbols;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
@@ -414,7 +415,7 @@ public class HttpHeaders implements Serializable {
private static final DecimalFormatSymbols DECIMAL_FORMAT_SYMBOLS = new DecimalFormatSymbols(Locale.ROOT);
private static final ZoneId GMT = ZoneId.of("GMT");
private static final ZoneId GMT = ZoneOffset.UTC;
/**
* Date formats with time zone as specified in the HTTP RFC to use for formatting.
@@ -1516,7 +1517,7 @@ public class HttpHeaders implements Serializable {
* @since 5.1.4
*/
public void setInstant(String headerName, Instant date) {
setZonedDateTime(headerName, ZonedDateTime.ofInstant(date, GMT));
setZonedDateTime(headerName, date.atZone(GMT));
}
/**
@@ -2172,7 +2173,7 @@ public class HttpHeaders implements Serializable {
// Package-private: used in ResponseCookie
static String formatDate(long date) {
Instant instant = Instant.ofEpochMilli(date);
ZonedDateTime time = ZonedDateTime.ofInstant(instant, GMT);
ZonedDateTime time = instant.atZone(GMT);
return DATE_FORMATTER.format(time);
}
@@ -19,7 +19,6 @@ package org.springframework.web.server.session;
import java.time.Clock;
import java.time.Duration;
import java.time.Instant;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.Collections;
import java.util.Iterator;
@@ -51,7 +50,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
private int maxSessions = 10000;
private Clock clock = Clock.system(ZoneId.of("GMT"));
private Clock clock = Clock.systemUTC();
private final Map<String, InMemoryWebSession> sessions = new ConcurrentHashMap<>();
@@ -20,7 +20,7 @@ import java.net.InetSocketAddress;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
@@ -370,7 +370,7 @@ class HttpHeadersTests {
@Test
void expiresZonedDateTime() {
ZonedDateTime zonedDateTime = ZonedDateTime.of(2008, 12, 18, 10, 20, 0, 0, ZoneId.of("GMT"));
ZonedDateTime zonedDateTime = ZonedDateTime.of(2008, 12, 18, 10, 20, 0, 0, ZoneOffset.UTC);
headers.setExpires(zonedDateTime);
assertThat(headers.getExpires()).as("Invalid Expires header").isEqualTo(zonedDateTime.toInstant().toEpochMilli());
assertThat(headers.getFirst("expires")).as("Invalid Expires header").isEqualTo("Thu, 18 Dec 2008 10:20:00 GMT");
@@ -605,7 +605,7 @@ class HttpHeadersTests {
@Test
void firstZonedDateTime() {
ZonedDateTime date = ZonedDateTime.of(2017, 6, 2, 2, 22, 0, 0, ZoneId.of("GMT"));
ZonedDateTime date = ZonedDateTime.of(2017, 6, 2, 2, 22, 0, 0, ZoneOffset.UTC);
headers.setZonedDateTime(HttpHeaders.DATE, date);
assertThat(headers.getFirst(HttpHeaders.DATE)).isEqualTo("Fri, 02 Jun 2017 02:22:00 GMT");
assertThat(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date)).isTrue();
@@ -24,7 +24,7 @@ import java.lang.annotation.Target;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -184,7 +184,7 @@ class ClientHttpConnectorTests {
@ParameterizedConnectorTest
void cookieExpireValueSetAsMaxAge(ClientHttpConnector connector) {
ZonedDateTime tomorrow = ZonedDateTime.now(ZoneId.of("UTC")).plusDays(1);
ZonedDateTime tomorrow = ZonedDateTime.now(ZoneOffset.UTC).plusDays(1);
String formattedDate = tomorrow.format(DateTimeFormatter.RFC_1123_DATE_TIME);
prepareResponse(builder -> builder
@@ -16,7 +16,7 @@
package org.springframework.web.server.i18n;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.Locale;
import java.util.TimeZone;
@@ -61,7 +61,7 @@ class FixedLocaleContextResolverTests {
@Test
void resolveCustomizedAndTimeZoneLocale() {
TimeZone timeZone = TimeZone.getTimeZone(ZoneId.of("UTC"));
TimeZone timeZone = TimeZone.getTimeZone(ZoneOffset.UTC);
FixedLocaleContextResolver resolver = new FixedLocaleContextResolver(FRANCE, timeZone);
TimeZoneAwareLocaleContext context = (TimeZoneAwareLocaleContext) resolver.resolveLocaleContext(exchange());
assertThat(context.getLocale()).isEqualTo(FRANCE);