Browse Source

Polish "Preserve milliseconds in build info timestamp"

See gh-43612
pull/43904/head
Stéphane Nicoll 1 year ago
parent
commit
7e9fda8216
  1. 6
      spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/MavenBuildOutputTimestamp.java
  2. 12
      spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/MavenBuildOutputTimestampTests.java

6
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/MavenBuildOutputTimestamp.java

@ -21,7 +21,6 @@ import java.time.Instant; @@ -21,7 +21,6 @@ import java.time.Instant;
import java.time.OffsetDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import org.springframework.util.StringUtils;
@ -86,10 +85,7 @@ class MavenBuildOutputTimestamp { @@ -86,10 +85,7 @@ class MavenBuildOutputTimestamp {
return null;
}
try {
Instant instant = OffsetDateTime.parse(this.timestamp)
.withOffsetSameInstant(ZoneOffset.UTC)
.truncatedTo(ChronoUnit.MILLIS)
.toInstant();
Instant instant = OffsetDateTime.parse(this.timestamp).withOffsetSameInstant(ZoneOffset.UTC).toInstant();
if (instant.isBefore(DATE_MIN) || instant.isAfter(DATE_MAX)) {
throw new IllegalArgumentException(
String.format("'%s' is not within the valid range %s to %s", instant, DATE_MIN, DATE_MAX));

12
spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/MavenBuildOutputTimestampTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@ -48,17 +48,17 @@ class MavenBuildOutputTimestampTests { @@ -48,17 +48,17 @@ class MavenBuildOutputTimestampTests {
@Test
void shouldParseIso8601() {
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30Z"));
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30.000Z"));
}
@Test
void shouldParseIso8601WithSeconds_whenMillisecondsNotPresent() {
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30Z"));
void shouldParseIso8601WithMilliseconds() {
assertThat(parse("2011-12-03T10:15:30.123Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30.123Z"));
}
@Test
void shouldParseIso8601WithMillisecondsPreserved_whenPresent() {
assertThat(parse("2024-12-19T19:59:39.040Z")).isEqualTo(Instant.parse("2024-12-19T19:59:39.040Z"));
void shouldParseIso8601WithSeconds() {
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30.000Z"));
}
@Test

Loading…
Cancel
Save