org.opentripplanner.ext.transmodelapi.mapping.ServiceDateMapper 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.ext.transmodelapi.mapping;
import org.opentripplanner.model.calendar.ServiceDate;
import java.time.LocalDate;
import java.util.Date;
import java.util.TimeZone;
public class ServiceDateMapper {
private final TimeZone timeZone;
public ServiceDateMapper(TimeZone timeZone) {
this.timeZone = timeZone;
}
public Long serviceDateToSecondsSinceEpoch(ServiceDate serviceDate) {
if (serviceDate == null) {
return null;
}
return LocalDate.of(serviceDate.getYear(), serviceDate.getMonth(), serviceDate.getDay())
.atStartOfDay(timeZone.toZoneId()).toEpochSecond();
}
public ServiceDate secondsSinceEpochToServiceDate(Long secondsSinceEpoch) {
if (secondsSinceEpoch == null) {
return new ServiceDate();
}
return new ServiceDate(new Date(secondsSinceEpoch * 1000));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy