org.opentripplanner.routing.algorithm.raptor.transit.mappers.DateMapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.routing.algorithm.raptor.transit.mappers;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
public class DateMapper {
public static ZonedDateTime asStartOfService(ZonedDateTime date) {
return date.truncatedTo(ChronoUnit.HOURS)
.withHour(12)
.minusHours(12);
}
public static ZonedDateTime asStartOfService(LocalDate localDate, ZoneId zoneId) {
return ZonedDateTime.of(localDate, LocalTime.NOON, zoneId)
.minusHours(12);
}
public static int secondsSinceStartOfTime(ZonedDateTime startOfTime, LocalDate localDate) {
ZonedDateTime startOfDay = asStartOfService(localDate, startOfTime.getZone());
return (int) Duration.between(startOfTime, startOfDay).getSeconds();
}
public static int secondsSinceStartOfTime(ZonedDateTime startOfTime, Instant instant) {
return (int) Duration.between(startOfTime.toInstant(), instant).getSeconds();
}
}