Pretty Time of Day

Implements an S3 class for storing and formatting time-of-day values, based on the 'difftime' class.


A simple class for storing durations or time-of-day values and displaying them in the hh:mm:ss format. Intended to simplify data exchange with databases, spreadsheets, and other data sources.

The values are stored as a numeric vector that contains the number of seconds since midnight. Supports construction from time values, coercion to and from various data types, and formatting, based on the difftime class. Can be used in a data frame.

Compared to POSIXct, no date is stored, although the values can exceed the 24-hour boundary or be negative. By default, fractional seconds up to a microsecond are displayed.

library(hms)
hms(56, 34, 12)
as.hms(1)
#> 00:00:01
as.hms("12:34:56")
#> 12:34:56
as.hms(Sys.time())
#> 14:41:28.004544
as.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

Install the package from GitHub:

# install.packages("devtools")
devtools::install_github("rstats-db/hms")

News

hms 0.3 (2016-11-22)

  • Fix lubridate test for compatibility with 1.6.0 (#23, @vspinu).
  • NA values are formatted as NA (#22).

hms 0.2 (2016-06-17)

Minor fixes and improvements.

  • Subsetting keeps hms class (#16).
  • format.hms() right-justifies the output by padding with spaces from the left, as.character.hms() remains unchanged.
  • Times larger than 24 hours or with split seconds are now formatted correctly (#12, #13).
  • Sub-second part is printed with up to six digits, for even smaller values trailing zeros are shown (#17).

hms 0.1 (2016-04-30)

First CRAN release.

  • Values are stored as a numeric vector that contains the number of seconds since midnight.
    • Inherits from difftime class.
    • Updating units is a no-op, anything different from "secs" issues a warning.
  • Supports construction from time values, coercion to and from various data types, and formatting.
    • Conversion from numeric treats input as seconds.
    • Negative times are formatted with a leading -.
  • Can be used as a regular column in a data frame.
  • Full test coverage.
    • Test for arithmetic with Date, POSIXt and hms classes.
    • Test basic compatibility with lubridate package (#5).
  • Interface:
    • 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)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("hms")

0.3 by Kirill Müller, 3 months ago


https://github.com/rstats-db/hms


Report a bug at https://github.com/rstats-db/hms/issues


Browse source code at https://github.com/cran/hms


Authors: Kirill Müller [aut, cre], The R Consortium [cph]


Documentation:   PDF Manual  


GPL-3 license


Imports methods

Suggests testthat, lubridate


Imported by feather, haven, readr, tidyverse.

Suggested by scales.


See at CRAN