Convert number of minutes, hours, days or weeks into seconds. If x
is
numeric, it is assumed to be in hours.
Arguments
- x
A character or numeric vector. The units of the input is specified by a single character:
s seconds
m minutes
h hours
d days
w weeks
Value
A named vector where the values are the number of seconds and the names are the equivalent in the units given in the input
Examples
# Numeric inputs are assumed to be in hours
to_seconds(c(0, 1, 2))
#> 0h 1h 2h
#> 0 3600 7200
# The same values given in seconds, minutes and explicitly hours
to_seconds(c("0s", "3600s", "7200s"))
#> 0s 3600s 7200s
#> 0 3600 7200
to_seconds(c("0m", "60m", "120m"))
#> 0m 60m 120m
#> 0 3600 7200
to_seconds(c("0h", "1h", "2h"))
#> 0h 1h 2h
#> 0 3600 7200
# Units can be mixed
to_seconds(c(paste0(24 * 7, "h"), "7d", "1w"))
#> 168h 7d 1w
#> 604800 604800 604800