Skip to content

Commit d87c456

Browse files
author
Vincent Potucek
committed
[picnic] apply TimeRules
Signed-off-by: Vincent Potucek <[email protected]>
1 parent 4bc97ad commit d87c456

File tree

14 files changed

+31
-32
lines changed

14 files changed

+31
-32
lines changed

spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeConverters.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ private static ZonedDateTime calendarToZonedDateTime(Calendar source) {
8181
return gc.toZonedDateTime();
8282
}
8383
else {
84-
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(source.getTimeInMillis()),
85-
source.getTimeZone().toZoneId());
84+
return Instant.ofEpochMilli(source.getTimeInMillis()).atZone(source.getTimeZone().toZoneId());
8685
}
8786
}
8887

spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public String getExpression() {
115115
public @Nullable Instant nextExecution(TriggerContext triggerContext) {
116116
Instant timestamp = determineLatestTimestamp(triggerContext);
117117
ZoneId zone = (this.zoneId != null ? this.zoneId : triggerContext.getClock().getZone());
118-
ZonedDateTime zonedTimestamp = ZonedDateTime.ofInstant(timestamp, zone);
118+
ZonedDateTime zonedTimestamp = timestamp.atZone(zone);
119119
ZonedDateTime nextTimestamp = this.expression.next(zonedTimestamp);
120120
return (nextTimestamp != null ? nextTimestamp.toInstant() : null);
121121
}

spring-context/src/test/java/org/springframework/scheduling/concurrent/DefaultManagedTaskSchedulerTests.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.time.Duration;
2020
import java.time.Instant;
21-
import java.time.temporal.ChronoUnit;
2221

2322
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
2423
import org.junit.jupiter.api.Test;
@@ -53,28 +52,28 @@ void scheduleWithInstantAndNoScheduledExecutorProvidesDedicatedException() {
5352
void scheduleAtFixedRateWithStartTimeAndDurationAndNoScheduledExecutorProvidesDedicatedException() {
5453
DefaultManagedTaskScheduler scheduler = new DefaultManagedTaskScheduler();
5554
assertNoExecutorException(() -> scheduler.scheduleAtFixedRate(
56-
NO_OP, Instant.now(), Duration.of(1, ChronoUnit.MINUTES)));
55+
NO_OP, Instant.now(), Duration.ofMinutes(1)));
5756
}
5857

5958
@Test
6059
void scheduleAtFixedRateWithDurationAndNoScheduledExecutorProvidesDedicatedException() {
6160
DefaultManagedTaskScheduler scheduler = new DefaultManagedTaskScheduler();
6261
assertNoExecutorException(() -> scheduler.scheduleAtFixedRate(
63-
NO_OP, Duration.of(1, ChronoUnit.MINUTES)));
62+
NO_OP, Duration.ofMinutes(1)));
6463
}
6564

6665
@Test
6766
void scheduleWithFixedDelayWithStartTimeAndDurationAndNoScheduledExecutorProvidesDedicatedException() {
6867
DefaultManagedTaskScheduler scheduler = new DefaultManagedTaskScheduler();
6968
assertNoExecutorException(() -> scheduler.scheduleWithFixedDelay(
70-
NO_OP, Instant.now(), Duration.of(1, ChronoUnit.MINUTES)));
69+
NO_OP, Instant.now(), Duration.ofMinutes(1)));
7170
}
7271

7372
@Test
7473
void scheduleWithFixedDelayWithDurationAndNoScheduledExecutorProvidesDedicatedException() {
7574
DefaultManagedTaskScheduler scheduler = new DefaultManagedTaskScheduler();
7675
assertNoExecutorException(() -> scheduler.scheduleWithFixedDelay(
77-
NO_OP, Duration.of(1, ChronoUnit.MINUTES)));
76+
NO_OP, Duration.ofMinutes(1)));
7877
}
7978

8079
private void assertNoExecutorException(ThrowingCallable callable) {

spring-test/src/main/java/org/springframework/test/http/HttpHeadersAssert.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.time.Instant;
2020
import java.time.ZoneId;
21+
import java.time.ZoneOffset;
2122
import java.time.ZonedDateTime;
2223
import java.time.temporal.ChronoUnit;
2324
import java.util.Arrays;
@@ -42,7 +43,7 @@
4243
*/
4344
public class HttpHeadersAssert extends AbstractObjectAssert<HttpHeadersAssert, HttpHeaders> {
4445

45-
private static final ZoneId GMT = ZoneId.of("GMT");
46+
private static final ZoneId GMT = ZoneOffset.UTC;
4647

4748

4849
private final AbstractCollectionAssert<?, Collection<? extends String>, String, ObjectAssert<String>> namesAssert;
@@ -173,7 +174,7 @@ public HttpHeadersAssert hasValue(String name, Instant value) {
173174
containsHeader(name);
174175
Assertions.assertThat(this.actual.getFirstZonedDateTime(name))
175176
.as("check primary date value for HTTP header '%s'", name)
176-
.isCloseTo(ZonedDateTime.ofInstant(value, GMT), Assertions.within(999, ChronoUnit.MILLIS));
177+
.isCloseTo(value.atZone(GMT), Assertions.within(999, ChronoUnit.MILLIS));
177178
return this.myself;
178179
}
179180

spring-test/src/test/java/org/springframework/test/web/servlet/client/RestTestClientTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.net.URI;
2020
import java.nio.charset.StandardCharsets;
21-
import java.time.ZoneId;
21+
import java.time.ZoneOffset;
2222
import java.time.ZonedDateTime;
2323
import java.util.Map;
2424

@@ -263,7 +263,7 @@ void testAcceptCharset() {
263263
@Test
264264
void testIfModifiedSince() {
265265
RestTestClientTests.this.client.get().uri("/test")
266-
.ifModifiedSince(ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneId.of("GMT")))
266+
.ifModifiedSince(ZonedDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC))
267267
.exchange()
268268
.expectStatus().isOk()
269269
.expectBody().jsonPath("$.headers.If-Modified-Since").isEqualTo("Thu, 01 Jan 1970 00:00:00 GMT");

spring-test/src/test/java/org/springframework/test/web/servlet/result/HeaderResultMatchersTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.test.web.servlet.result;
1818

19-
import java.time.ZoneId;
19+
import java.time.ZoneOffset;
2020
import java.time.ZonedDateTime;
2121

2222
import org.junit.jupiter.api.Test;
@@ -45,7 +45,7 @@ public class HeaderResultMatchersTests {
4545
@Test // SPR-17330
4646
public void matchDateFormattedWithHttpHeaders() throws Exception {
4747

48-
long epochMilli = ZonedDateTime.of(2018, 10, 5, 0, 0, 0, 0, ZoneId.of("GMT")).toInstant().toEpochMilli();
48+
long epochMilli = ZonedDateTime.of(2018, 10, 5, 0, 0, 0, 0, ZoneOffset.UTC).toInstant().toEpochMilli();
4949
HttpHeaders headers = new HttpHeaders();
5050
headers.setDate("myDate", epochMilli);
5151
this.response.setHeader("d", headers.getFirst("myDate"));

spring-test/src/test/java/org/springframework/test/web/support/HeaderAssertionTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.test.web.support;
1818

1919
import java.net.URI;
20-
import java.time.ZoneId;
20+
import java.time.ZoneOffset;
2121
import java.time.ZonedDateTime;
2222
import java.util.concurrent.TimeUnit;
2323

@@ -272,7 +272,7 @@ void contentType() {
272272
@Test
273273
void expires() {
274274
HttpHeaders headers = new HttpHeaders();
275-
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
275+
ZonedDateTime expires = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
276276
headers.setExpires(expires);
277277
TestHeaderAssertions assertions = new TestHeaderAssertions(headers);
278278
assertions.expires(expires.toInstant().toEpochMilli());
@@ -285,7 +285,7 @@ void expires() {
285285
@Test
286286
void lastModified() {
287287
HttpHeaders headers = new HttpHeaders();
288-
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"));
288+
ZonedDateTime lastModified = ZonedDateTime.of(2018, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC);
289289
headers.setLastModified(lastModified.toInstant().toEpochMilli());
290290
TestHeaderAssertions assertions = new TestHeaderAssertions(headers);
291291
assertions.lastModified(lastModified.toInstant().toEpochMilli());

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.time.Duration;
2828
import java.time.Instant;
2929
import java.time.ZoneId;
30+
import java.time.ZoneOffset;
3031
import java.time.ZonedDateTime;
3132
import java.time.format.DateTimeFormatter;
3233
import java.time.format.DateTimeParseException;
@@ -414,7 +415,7 @@ public class HttpHeaders implements Serializable {
414415

415416
private static final DecimalFormatSymbols DECIMAL_FORMAT_SYMBOLS = new DecimalFormatSymbols(Locale.ROOT);
416417

417-
private static final ZoneId GMT = ZoneId.of("GMT");
418+
private static final ZoneId GMT = ZoneOffset.UTC;
418419

419420
/**
420421
* Date formats with time zone as specified in the HTTP RFC to use for formatting.
@@ -1516,7 +1517,7 @@ public void setZonedDateTime(String headerName, ZonedDateTime date) {
15161517
* @since 5.1.4
15171518
*/
15181519
public void setInstant(String headerName, Instant date) {
1519-
setZonedDateTime(headerName, ZonedDateTime.ofInstant(date, GMT));
1520+
setZonedDateTime(headerName, date.atZone(GMT));
15201521
}
15211522

15221523
/**
@@ -2172,7 +2173,7 @@ private static MultiValueMap<String, String> unwrap(HttpHeaders headers) {
21722173
// Package-private: used in ResponseCookie
21732174
static String formatDate(long date) {
21742175
Instant instant = Instant.ofEpochMilli(date);
2175-
ZonedDateTime time = ZonedDateTime.ofInstant(instant, GMT);
2176+
ZonedDateTime time = instant.atZone(GMT);
21762177
return DATE_FORMATTER.format(time);
21772178
}
21782179

spring-web/src/main/java/org/springframework/web/server/session/InMemoryWebSessionStore.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.time.Clock;
2020
import java.time.Duration;
2121
import java.time.Instant;
22-
import java.time.ZoneId;
2322
import java.time.temporal.ChronoUnit;
2423
import java.util.Collections;
2524
import java.util.Iterator;
@@ -51,7 +50,7 @@ public class InMemoryWebSessionStore implements WebSessionStore {
5150

5251
private int maxSessions = 10000;
5352

54-
private Clock clock = Clock.system(ZoneId.of("GMT"));
53+
private Clock clock = Clock.systemUTC();
5554

5655
private final Map<String, InMemoryWebSession> sessions = new ConcurrentHashMap<>();
5756

spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.net.URI;
2121
import java.nio.charset.Charset;
2222
import java.nio.charset.StandardCharsets;
23-
import java.time.ZoneId;
23+
import java.time.ZoneOffset;
2424
import java.time.ZonedDateTime;
2525
import java.util.ArrayList;
2626
import java.util.Arrays;
@@ -370,7 +370,7 @@ void expiresLong() {
370370

371371
@Test
372372
void expiresZonedDateTime() {
373-
ZonedDateTime zonedDateTime = ZonedDateTime.of(2008, 12, 18, 10, 20, 0, 0, ZoneId.of("GMT"));
373+
ZonedDateTime zonedDateTime = ZonedDateTime.of(2008, 12, 18, 10, 20, 0, 0, ZoneOffset.UTC);
374374
headers.setExpires(zonedDateTime);
375375
assertThat(headers.getExpires()).as("Invalid Expires header").isEqualTo(zonedDateTime.toInstant().toEpochMilli());
376376
assertThat(headers.getFirst("expires")).as("Invalid Expires header").isEqualTo("Thu, 18 Dec 2008 10:20:00 GMT");
@@ -605,7 +605,7 @@ void firstDate() {
605605

606606
@Test
607607
void firstZonedDateTime() {
608-
ZonedDateTime date = ZonedDateTime.of(2017, 6, 2, 2, 22, 0, 0, ZoneId.of("GMT"));
608+
ZonedDateTime date = ZonedDateTime.of(2017, 6, 2, 2, 22, 0, 0, ZoneOffset.UTC);
609609
headers.setZonedDateTime(HttpHeaders.DATE, date);
610610
assertThat(headers.getFirst(HttpHeaders.DATE)).isEqualTo("Fri, 02 Jun 2017 02:22:00 GMT");
611611
assertThat(headers.getFirstZonedDateTime(HttpHeaders.DATE).isEqual(date)).isTrue();

0 commit comments

Comments
 (0)