format_time: Standardize some input time to an HH:MM:SS format.

Description Usage Arguments Details Value Examples

Description

format_time takes either a numeric or character input s, corresponding to some time, and returns a string that is formatted to a consistent HH:MM:SS format.

Usage

1

Arguments

time

Either a single numeric, corresponding to some number of seconds, or a character string where hours, minutes, and/or seconds are separated by a colon (:).

Details

format_time is flexible with regard to the format of time, but if hours and/or minutes are supplied in addition to seconds, they must be some form where mintues precede seconds, and hours precede minutes. Thus, to indicate 1 hour, 30 minutes, 5 seconds, the following values of time are all acceptable: "1:30:05", 5405, "5405", "30:3605", "1.5:0:5". However, 1.5:05, is not.

Value

a character string of the form HH:MM:SS.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
format_time(2.5) # fractions are okay

# Many different ways to express "01:30:05":
format_time("1:30:05")  # 1 hour, 30 minutes, 5 seconds
format_time(5405)       # 5405 seconds (numeric)
format_time("5405")     # 5405 seconds (string)
format_time("30:3605")  # 30 minutes, 3605 seconds
format_time("1.5:0:5")  # 1.5 hours, 0 minutes, 5 seconds

# Order is important
format_time("1.5:5")    # 1.5 minutes, 5 seconds

bochocki/slackrsheets documentation built on May 8, 2019, 9:46 a.m.