Skip to content

Commit 19c2c5c

Browse files
Merge pull request #11 from opentripplanner/truncate
Add static initializer for truncating times to millis
2 parents 7eb6f5c + c1aa15c commit 19c2c5c

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/main/java/org/opentripplanner/ojp/time/XmlDateTime.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.time.ZoneId;
55
import java.time.ZonedDateTime;
66
import java.time.format.DateTimeFormatter;
7+
import java.time.temporal.ChronoUnit;
78
import java.util.Objects;
89

910
/**
@@ -23,6 +24,13 @@ public XmlDateTime(LocalDateTime localDateTime) {
2324
this.localDateTime = Objects.requireNonNull(localDateTime);
2425
}
2526

27+
/**
28+
* Return a truncated version of the given date time with millisecond precision.
29+
*/
30+
public static XmlDateTime truncatedToMillis(ZonedDateTime dateTime) {
31+
return new XmlDateTime(dateTime.truncatedTo(ChronoUnit.MILLIS));
32+
}
33+
2634
/**
2735
* Converts the abstract XML dateTime into a {@link ZonedDateTime}. If the underlying date time
2836
* was already zoned, then it is converted to the same instant but in the specified zone.

0 commit comments

Comments
 (0)