Skip to content

Commit

Permalink
Allow for docker timestamps with timezone offsets
Browse files Browse the repository at this point in the history
Docker prefers to use UTC time when making images/containers,
but it's happy to parse non-UTC times too. It will then pass those on in its
output.

DateTimeFormatter.ISO_OFFSET_DATE_TIME accepts a superset of what
DateTimeFormatter.ISO_INSTANT accepts, so replace use of
ISO_INSTANT with ISO_OFFSET_DATE_TIME.
  • Loading branch information
candrews committed May 10, 2021
1 parent cf6d15c commit 05dcc79
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static boolean isContainerRunning(InspectContainerResponse.ContainerState
if (minimumRunningDuration == null) {
return true;
}
Instant startedAt = DateTimeFormatter.ISO_INSTANT.parse(
Instant startedAt = DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(
state.getStartedAt(), Instant::from);

if (startedAt.isBefore(now.minus(minimumRunningDuration))) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public static boolean isDockerTimestampNonEmpty(String dockerTimestamp) {
return dockerTimestamp != null
&& !dockerTimestamp.isEmpty()
&& !dockerTimestamp.equals(DOCKER_TIMESTAMP_ZERO)
&& DateTimeFormatter.ISO_INSTANT.parse(dockerTimestamp, Instant::from).getEpochSecond() >= 0L;
&& DateTimeFormatter.ISO_OFFSET_DATE_TIME.parse(dockerTimestamp, Instant::from).getEpochSecond() >= 0L;
}

public static boolean isContainerExitCodeSuccess(InspectContainerResponse.ContainerState state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void testStopped() throws Exception {
}

private static String buildTimestamp(Instant instant) {
return DateTimeFormatter.ISO_INSTANT.format(instant);
return DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(instant);
}

// ContainerState is a non-static inner class, with private member variables, in a different package.
Expand Down

0 comments on commit 05dcc79

Please sign in to comment.