Skip to contents

Converts a start and end value to a readable time format.

Usage

pretty_time_taken(start_time, end_time)

Arguments

start_time

start time readable by as.POSIXct

end_time

end time readable by as.POSIXct

Value

string containing prettified elapsed time

Details

Designed to be used with Sys.time() when tracking start and end times.

Shows as seconds up until 119 seconds, then minutes until 119 minutes, then hours for anything larger.

Input start and end times must be convertible to POSIXct format.

Examples

pretty_time_taken(
  "2024-03-23 07:05:53 GMT",
  "2024-03-23 12:09:56 GMT"
)
#> [1] "5 hours 4 minutes 3 seconds"

# Track the start and end time of a process
start <- Sys.time()
Sys.sleep(0.1)
end <- Sys.time()

# Use this function to present it prettily
pretty_time_taken(start, end)
#> [1] "0.1 seconds"