All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.transit.model.timetable.EstimatedTime Maven / Gradle / Ivy

The newest version!
package org.opentripplanner.transit.model.timetable;

import java.time.Duration;
import java.time.ZonedDateTime;
import java.util.Objects;

/**
 * Realtime information about a vehicle at a certain place. This is meant to be used in timetables
 * (not in transit legs).
 */
public class EstimatedTime {

  private final ZonedDateTime time;
  private final Duration delay;

  /**
   * @param delay Delay or "earliness" of a vehicle. Earliness is expressed as a negative number.
   */
  private EstimatedTime(ZonedDateTime time, Duration delay) {
    this.time = Objects.requireNonNull(time);
    this.delay = Objects.requireNonNull(delay);
  }

  public static EstimatedTime of(ZonedDateTime scheduledTime, int delaySecs) {
    var delay = Duration.ofSeconds(delaySecs);
    return new EstimatedTime(scheduledTime.minus(delay), delay);
  }

  public ZonedDateTime time() {
    return time;
  }

  public Duration delay() {
    return delay;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy