From e86fdede1374491130de28d16e5b2423af0201e1 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Mon, 2 Feb 2015 10:11:19 +0100 Subject: [PATCH] Implement methods for duration of a trip. --- enabler/src/de/schildbach/pte/dto/Trip.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/enabler/src/de/schildbach/pte/dto/Trip.java b/enabler/src/de/schildbach/pte/dto/Trip.java index ce983a12..92311f53 100644 --- a/enabler/src/de/schildbach/pte/dto/Trip.java +++ b/enabler/src/de/schildbach/pte/dto/Trip.java @@ -113,6 +113,25 @@ public final class Trip implements Serializable return null; } + /** Duration of whole trip in milliseconds, including leading and trailing individual legs. */ + public long getDuration() + { + final Date first = getFirstDepartureTime(); + final Date last = getLastArrivalTime(); + return last.getTime() - first.getTime(); + } + + /** + * Duration of the public leg part in milliseconds. This includes individual legs between public legs, but excludes + * individual legs that lead or trail the trip. + */ + public long getPublicDuration() + { + final Date first = getFirstPublicLegDepartureTime(); + final Date last = getLastPublicLegArrivalTime(); + return last.getTime() - first.getTime(); + } + /** Minimum time occuring in this trip. */ public Date getMinTime() {