diff --git a/src/main/java/org/opentripplanner/ojp/time/XmlDateTime.java b/src/main/java/org/opentripplanner/ojp/time/XmlDateTime.java index eff695f..7a0f7b9 100644 --- a/src/main/java/org/opentripplanner/ojp/time/XmlDateTime.java +++ b/src/main/java/org/opentripplanner/ojp/time/XmlDateTime.java @@ -4,6 +4,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.Objects; /** @@ -23,6 +24,13 @@ public XmlDateTime(LocalDateTime localDateTime) { this.localDateTime = Objects.requireNonNull(localDateTime); } + /** + * Return a truncated version of the given date time with millisecond precision. + */ + public static XmlDateTime truncatedToMillis(ZonedDateTime dateTime) { + return new XmlDateTime(dateTime.truncatedTo(ChronoUnit.MILLIS)); + } + /** * Converts the abstract XML dateTime into a {@link ZonedDateTime}. If the underlying date time * was already zoned, then it is converted to the same instant but in the specified zone.