Preserve milliseconds in build info timestamp

See gh-43612
This commit is contained in:
Gaurav
2024-12-26 00:48:01 +01:00
committed by Stéphane Nicoll
parent b5893133cf
commit 0944b07c90
2 changed files with 8 additions and 3 deletions

View File

@@ -88,7 +88,7 @@ class MavenBuildOutputTimestamp {
try {
Instant instant = OffsetDateTime.parse(this.timestamp)
.withOffsetSameInstant(ZoneOffset.UTC)
.truncatedTo(ChronoUnit.SECONDS)
.truncatedTo(ChronoUnit.MILLIS)
.toInstant();
if (instant.isBefore(DATE_MIN) || instant.isAfter(DATE_MAX)) {
throw new IllegalArgumentException(

View File

@@ -52,8 +52,13 @@ class MavenBuildOutputTimestampTests {
}
@Test
void shouldParseIso8601WithMilliseconds() {
assertThat(parse("2011-12-03T10:15:30.12345Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30Z"));
void shouldParseIso8601WithSeconds_whenMillisecondsNotPresent() {
assertThat(parse("2011-12-03T10:15:30Z")).isEqualTo(Instant.parse("2011-12-03T10:15:30Z"));
}
@Test
void shouldParseIso8601WithMillisecondsPreserved_whenPresent() {
assertThat(parse("2024-12-19T19:59:39.040Z")).isEqualTo(Instant.parse("2024-12-19T19:59:39.040Z"));
}
@Test