Skip to content

Commit ddfc47b

Browse files
ewoelfelMediaMarco
authored andcommitted
fix: handle epoch milliseconds in DateTimeUtil.parse()
Spring Boot's GitProperties.coercePropertyToEpoch() replaces commit.time ISO strings with epoch milliseconds (e.g. '1747827915000'). DateTimeUtil only handled ISO formats, causing a DateTimeParseException that crashed the status.html Thymeleaf template with a 500 error. Fix: detect all-digit strings and parse them as epoch ms (UTC) before attempting ISO format parsing. Closes #2271
1 parent 9934a81 commit ddfc47b

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

edison-core/src/main/java/de/otto/edison/util/DateTimeUtil.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package de.otto.edison.util;
22

3+
import java.time.Instant;
34
import java.time.OffsetDateTime;
5+
import java.time.ZoneOffset;
46
import java.time.format.DateTimeFormatter;
57
import java.time.format.DateTimeFormatterBuilder;
68

79
/**
810
* Utility for parsing date-time strings that may use different offset formats,
9-
* e.g. "+02:00" (ISO-8601) or "+0200" (as produced by git-commit-id-plugin).
11+
* e.g. "+02:00" (ISO-8601) or "+0200" (as produced by git-commit-id-plugin),
12+
* or epoch milliseconds (as produced by Spring Boot's {@code GitProperties} coercion).
1013
*/
1114
public final class DateTimeUtil {
1215

@@ -29,14 +32,21 @@ public final class DateTimeUtil {
2932
private DateTimeUtil() {}
3033

3134
/**
32-
* Parses a date-time string to {@link OffsetDateTime}, tolerating both
33-
* {@code +0200} and {@code +02:00} offset styles. Returns {@code null}
34-
* for {@code null} or empty input instead of throwing.
35+
* Parses a date-time string to {@link OffsetDateTime}. Handles:
36+
* <ul>
37+
* <li>Epoch milliseconds (e.g. {@code "1747827915000"}) — as returned by Spring Boot's
38+
* {@code GitProperties} coercion of {@code commit.time}. Interpreted as UTC.</li>
39+
* <li>ISO date-time with {@code +0200} or {@code +02:00} offset styles.</li>
40+
* </ul>
41+
* Returns {@code null} for {@code null} or empty input instead of throwing.
3542
*/
3643
public static OffsetDateTime parse(final String dateTime) {
3744
if (dateTime == null || dateTime.isEmpty()) {
3845
return null;
3946
}
47+
if (dateTime.chars().allMatch(Character::isDigit)) {
48+
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(dateTime)), ZoneOffset.UTC);
49+
}
4050
return OffsetDateTime.parse(dateTime, LENIENT_FORMATTER);
4151
}
4252
}

edison-core/src/test/java/de/otto/edison/util/DateTimeUtilTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ static Stream<Arguments> knownFormats() {
4545
"ISO-8601 with UTC Z",
4646
"2026-03-31T08:47:00Z",
4747
OffsetDateTime.of(2026, 3, 31, 8, 47, 0, 0, ZoneOffset.UTC)
48+
),
49+
arguments(
50+
"epoch milliseconds — as coerced by Spring Boot GitProperties",
51+
"1743404778000",
52+
OffsetDateTime.of(2025, 3, 31, 7, 6, 18, 0, ZoneOffset.UTC)
4853
)
4954
);
5055
}

0 commit comments

Comments
 (0)