Merge branch 'timerange' into gpsfixstore-independent-of-race

This commit is contained in:
Fredrik Teschke committed 2014-02-02 15:37:46 +01:00
commit c1c60dbeb2
2 files changed
+16

No files matched your search

@@ -34,4 +34,13 @@ public interface TimeRange extends Comparable<TimeRange>, Serializable {
boolean startsBefore(TimeRange other);
boolean endsAfter(TimeRange other);
/**
* Get time-difference between the timepoint and this timerange.
* It will be 0 if the timepoint lies within the timerange, otherwise the time-difference
* to either the start or end of the timerange, depending on which is closer
* @param timePoint
* @return
*/
long timeDifference(TimePoint timePoint);
}
@@ -57,4 +57,11 @@ public class TimeRangeImpl extends Pair<TimePoint, TimePoint> implements TimeRan
public boolean endsAfter(TimeRange other) {
return to().after(other.to());
}
@Override
public long timeDifference(TimePoint timePoint) {
if (includes(timePoint)) return 0;
if (timePoint.before(from())) return from().asMillis() - timePoint.asMillis();
return to().asMillis() - timePoint.asMillis();
}
}