Skip to content

Commit 7e9fda8

Browse files
committed
Polish "Preserve milliseconds in build info timestamp"
See gh-43612
1 parent 0944b07 commit 7e9fda8

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.time.OffsetDateTime;
2222
import java.time.ZoneOffset;
2323
import java.time.format.DateTimeParseException;
24-
import java.time.temporal.ChronoUnit;
2524

2625
import org.springframework.util.StringUtils;
2726

@@ -86,10 +85,7 @@ Instant toInstant() {
8685
return null;
8786
}
8887
try {
89-
Instant instant = OffsetDateTime.parse(this.timestamp)
90-
.withOffsetSameInstant(ZoneOffset.UTC)
91-
.truncatedTo(ChronoUnit.MILLIS)
92-
.toInstant();
88+
Instant instant = OffsetDateTime.parse(this.timestamp).withOffsetSameInstant(ZoneOffset.UTC).toInstant();
9389
if (instant.isBefore(DATE_MIN) || instant.isAfter(DATE_MAX)) {
9490
throw new IllegalArgumentException(
9591
String.format("'%s' is not within the valid range %s to %s", instant, DATE_MIN, DATE_MAX));

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -48,17 +48,17 @@ void shouldNotParseSingleCharacter() {
4848

4949
@Test
5050
void shouldParseIso8601() {
51-
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30Z"));
51+
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30.000Z"));
5252
}
5353

5454
@Test
55-
void shouldParseIso8601WithSeconds_whenMillisecondsNotPresent() {
56-
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30Z"));
55+
void shouldParseIso8601WithMilliseconds() {
56+
assertThat(parse("2011-12-03T10:15:30.123Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30.123Z"));
5757
}
5858

5959
@Test
60-
void shouldParseIso8601WithMillisecondsPreserved_whenPresent() {
61-
assertThat(parse("2024-12-19T19:59:39.040Z")).isEqualTo(Instant.parse("2024-12-19T19:59:39.040Z"));
60+
void shouldParseIso8601WithSeconds() {
61+
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30.000Z"));
6262
}
6363

6464
@Test

0 commit comments

Comments
 (0)