Implements an S3 class for storing and formatting time-of-day values, based on the 'difftime' class.
The hms package provides a simple class for storing durations or time-of-day values and displaying them in the hh:mm:ss format. This class is intended to simplify data exchange with databases, spreadsheets, and other data sources:
POSIXt
difftime
class"digits.secs"
optioninstall.packages("tidyverse")# Alternatively, install just hms:install.packages("hms")# Or the the development version from GitHub:# install.packages("devtools")devtools::install_github("tidyverse/hms")
The following example showcases ways of using the hms
class standalone or as a data frame column.
library(hms)hms(56, 34, 12)#> 12:34:56as.hms(1)#> 00:00:01as.hms("12:34:56")#> 12:34:56as.hms(Sys.time())#> 16:45:12.828186as.POSIXct(hms(1))#> [1] "1970-01-01 00:00:01 UTC"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
NA
when converting to character
(#51, @jeroen).as.hms.POSIXt()
now defaults to the current time zone, the previous default was "UTC"
and can be restored by calling pkgconfig::set_config("hms::default_tz", "UTC")
.hms
columns in tibbles in color on terminals
that support it (#43).round_hms()
and trunc_hms()
for rounding or truncating to a given multiple of seconds (#31).parse_hms()
and parse_hm()
to parse strings in "HH:MM:SS" and "HH:MM" formats (#30).as.hms.POSIXt()
gains tz
argument, default "UTC"
(#28).as.hms.character()
and parse_hms()
accept fractional seconds (#33).hms()
now works correctly if all four components (days, hours, minutes, seconds) are passed (#49).hms()
creates a zero-length object of class hms
that prints as "hms()"
.hms(integer())
and as.hms(integer())
both work and are identical to hms()
.c()
now returns a hms (#41, @qgeissmann).?hms
.hms()
with a character argument (#29).lubridate
test for compatibility with 1.6.0 (#23, @vspinu).NA
(#22).Minor fixes and improvements.
hms
class (#16).format.hms()
right-justifies the output by padding with spaces from the left, as.character.hms()
remains unchanged.First CRAN release.
difftime
class."secs"
issues a warning.-
.Date
, POSIXt
and hms
classes.lubridate
package (#5).hms()
(with rigorous argument checks)as.hms()
for character
, numeric
, POSIXct
and POSIXlt
as.xxx.hms()
for character
, numeric
(implicitly), POSIXct
and
POSIXlt
is.hms()
as.data.frame.hms()
(forwards to as.data.frame.difftime()
)format.hms()
print.hms()
(returns unchanged input invisibly)