
Convert seconds after midnight to time strings
Source:R/convert_seconds_to_time.R
convert_seconds_to_time.RdConverts times in seconds after midnight to strings in the "HH:MM:SS"
format, as used in stop_times and frequencies. It is the counterpart of
convert_time_to_seconds(), useful to write back times calculated from the
_secs columns.
Value
A character vector with the same length as seconds. NAs are
converted to "", as blank times in GTFS. Times past midnight keep
counting the hours (e.g. "25:30:00"). Names are dropped.
Examples
convert_seconds_to_time(c(0, 3600, 91800, NA))
#> [1] "00:00:00" "01:00:00" "25:30:00" ""
data_path <- system.file("extdata/spo_gtfs.zip", package = "gtfstools")
gtfs <- read_gtfs(data_path)
gtfs <- convert_time_to_seconds(gtfs, file = "stop_times")
# delay every departure by 5 minutes
delayed_departure <- convert_seconds_to_time(
gtfs$stop_times$departure_time_secs + 300
)
head(delayed_departure)
#> [1] "04:05:00" "04:13:00" "04:21:00" "04:29:00" "04:37:00" "04:45:00"