Skip to content

Commit

Permalink
Improved handling of multi-day trips
Browse files Browse the repository at this point in the history
  • Loading branch information
mem48 committed Jul 19, 2023
1 parent 238c1e3 commit e67c15d
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions R/gtfs_interpolate_times.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,8 @@ stops_interpolate <- function(x){
newtimes <- lubridate::as.duration(tstart) + interval
newtimes <- lubridate::as.period(newtimes)


# Convert day:hours:min:sec to hours:min:sec
for(j in seq_along(newtimes)){
sub <- newtimes[j]
if(sub >= lubridate::hm("24:00")){
ndys <- lubridate::hours(lubridate::day(sub) * 24)
sub <- sub - lubridate::days(1)
sub <- sub + ndys
newtimes[j] <- sub
}
}
newtimes <- period_days_to_hours(newtimes)

x$arrival_time[x$batch == btch] <- newtimes
}
Expand All @@ -130,3 +121,16 @@ stops_interpolate <- function(x){
x$departure_time <- departure_time
return(x)
}


period_days_to_hours <- function(x){
xday <- lubridate::day(x)
xhour <- lubridate::hour(x)
xmin <- lubridate::minute(x)
xsec <- lubridate::second(x)

y <- lubridate::period(hours = xhour + (xday * 24),
minutes = xmin,
seconds = xsec)
return(y)
}

0 comments on commit e67c15d

Please sign in to comment.