Skip to contents

Format time input string into suitable numeric output metric (e.g., seconds). Input follows the SBATCH utility specifications. Accepted time formats include "minutes", "minutes:seconds", "hours:minutes:seconds", "days-hours", "days-hours:minutes" and "days-hours:minutes:seconds".

Usage

timeFormater(time, output = "sec")

Arguments

time

a character string to be formatted. If a numeric vector is supplied then this will be interpreted as seconds.

output

type of numeric output to convert time into. Currently supported are 'sec' for seconds (default), 'min' for minutes, 'hour', and 'day'

Details

For example, max_time = "60" indicates a maximum time of 60 minutes, max_time = "03:00:00" a maximum time of 3 hours, max_time = "4-12" a maximum of 4 days and 12 hours, and max_time = "2-02:30:00" a maximum of 2 days, 2 hours and 30 minutes.

Examples


# Test cases (outputs in seconds)
timeFormater("4-12")        # day-hours
#> [1] 388800
timeFormater("4-12:15")     # day-hours:minutes
#> [1] 389700
timeFormater("4-12:15:30")  # day-hours:minutes:seconds
#> [1] 389730

timeFormater("30")          # minutes
#> [1] 1800
timeFormater("30:30")       # minutes:seconds
#> [1] 1830
timeFormater("4:30:30")     # hours:minutes:seconds
#> [1] 16230

# output in hours
timeFormater("4-12", output = 'hour')
#> [1] 108
timeFormater("4-12:15", output = 'hour')
#> [1] 108.25
timeFormater("4-12:15:30", output = 'hour')
#> [1] 108.2583

timeFormater("30", output = 'hour')
#> [1] 0.5
timeFormater("30:30", output = 'hour')
#> [1] 0.5083333
timeFormater("4:30:30", output = 'hour')
#> [1] 4.508333