Format the elapsed time between two POSIXct timestamps as HH:MM:SS.
hms_span <- function(start, end) {
dsec <- as.numeric(difftime(end, start, unit = "secs"))
hours <- floor(dsec / 3600)
minutes <- floor((dsec - 3600 * hours) / 60)
seconds <- dsec - 3600 * hours - 60 * minutes
paste0(
sapply(c(hours, minutes, seconds), function(x) {
formatC(x, width = 2, format = "d", flag = "0")
}),
collapse = ":"
)
}