4.4 hms
The hms
package provides a simple class for storing durations or time-of-day values and displaying them in the hh:mm:ss format.
# order: seconds, minutes, hours
hms(56, 34, 12)
#> 12:34:56
hms(56, 34, 12) %>% class
#> [1] "hms" "difftime"
data.frame(hours = 1:3, hms = hms(hours = 1:3))
#> hours hms
#> 1 1 01:00:00
#> 2 2 02:00:00
#> 3 3 03:00:00
as_hms(1)
#> 00:00:01
as_hms("12:34:56")
#> 12:34:56
hms()
is a constructor that accepts second, minute, hour and day components as numeric vectors.
round_hms()
and trunc_hms()
are onvenience functions to round or truncate to a multiple of seconds. They are similar to floor_date()
and ceiling_date()
in Section 4.2.2, but the time unit can only be seconds