hms/ 0000755 0001762 0000144 00000000000 14124146222 011037 5 ustar ligges users hms/NAMESPACE 0000644 0001762 0000144 00000002617 14124140353 012263 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method("[<-",hms)
S3method("[[",hms)
S3method("units<-",hms)
S3method(as.POSIXct,hms)
S3method(as.POSIXlt,hms)
S3method(as.character,hms)
S3method(as.hms,POSIXlt)
S3method(as.hms,POSIXt)
S3method(as.hms,default)
S3method(as_hms,default)
S3method(c,hms)
S3method(format,hms)
S3method(print,hms)
S3method(unique,hms)
S3method(vec_cast,hms)
S3method(vec_cast.POSIXct,hms)
S3method(vec_cast.POSIXlt,hms)
S3method(vec_cast.character,hms)
S3method(vec_cast.difftime,hms)
S3method(vec_cast.double,hms)
S3method(vec_cast.hms,POSIXct)
S3method(vec_cast.hms,POSIXlt)
S3method(vec_cast.hms,character)
S3method(vec_cast.hms,default)
S3method(vec_cast.hms,difftime)
S3method(vec_cast.hms,double)
S3method(vec_cast.hms,hms)
S3method(vec_cast.hms,integer)
S3method(vec_cast.integer,hms)
S3method(vec_ptype2,hms)
S3method(vec_ptype2.difftime,hms)
S3method(vec_ptype2.hms,default)
S3method(vec_ptype2.hms,difftime)
S3method(vec_ptype2.hms,hms)
S3method(vec_ptype_abbr,hms)
S3method(vec_ptype_full,hms)
export(as.hms)
export(as_hms)
export(hms)
export(is.hms)
export(is_hms)
export(new_hms)
export(parse_hm)
export(parse_hms)
export(round_hms)
export(trunc_hms)
export(vec_cast.hms)
export(vec_ptype2.hms)
import(ellipsis)
import(rlang)
import(vctrs)
importFrom(lifecycle,deprecate_soft)
importFrom(lifecycle,expect_deprecated)
importFrom(methods,setOldClass)
importFrom(pkgconfig,get_config)
hms/LICENSE 0000644 0001762 0000144 00000000051 14124140353 012037 0 ustar ligges users YEAR: 2020
COPYRIGHT HOLDER: hms authors
hms/README.md 0000644 0001762 0000144 00000014366 14124140353 012327 0 ustar ligges users # hms
[](https://lifecycle.r-lib.org/articles/stages.html) [](https://github.com/tidyverse/hms/actions) [](https://codecov.io/gh/tidyverse/hms) [](https://cran.r-project.org/package=hms)
## Overview
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:
- Stores values as a numeric vector that contains the number of seconds since midnight
- Supports construction from explicit hour, minute, or second values
- Supports coercion to and from various data types, including `POSIXt`
- Can be used as column in a data frame
- Based on the `difftime` class
- Values can exceed the 24-hour boundary or be negative
- By default, fractional seconds up to a microsecond are displayed, regardless of the value of the `"digits.secs"` option
## Installation
# The easiest way to get hms is to install the whole tidyverse: install.packages("tidyverse") # Alternatively, install just hms: install.packages("hms") # Or the the development version from GitHub: # install.packages("devtools") devtools::install_github("tidyverse/hms")## Usage 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:56 as_hms(Sys.time()) #> 11:55:02.553476 parse_hms("12:34:56") #> 12:34:56 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## Internal representation Objects of the `hms` and its underlying `difftime` classes are stored as number of seconds since `00:00:00`. Use [`as.numeric()`](https://rdrr.io/r/base/numeric.html) and [`as_hms()`](https://hms.tidyverse.org/reference/hms.html) to convert to and from numbers.
times <- parse_hms(c("00:00:00.25", "00:00:01", "00:01:30", "01:00:00")) times #> 00:00:00.25 #> 00:00:01.00 #> 00:01:30.00 #> 01:00:00.00 times_num <- as.numeric(times) times_num #> [1] 0.25 1.00 90.00 3600.00 as_hms(times_num) #> 00:00:00.25 #> 00:00:01.00 #> 00:01:30.00 #> 01:00:00.00------------------------------------------------------------------------ Please note that the ‘hms’ project is released with a [Contributor Code of Conduct](https://github.com/tidyverse/hms/blob/master/CODE_OF_CONDUCT.md). By contributing to this project, you agree to abide by its terms. hms/man/ 0000755 0001762 0000144 00000000000 14124140353 011611 5 ustar ligges users hms/man/vec_cast.hms.Rd 0000644 0001762 0000144 00000001135 14124140353 014455 0 ustar ligges users % Generated by roxygen2: do not edit by hand % Please edit documentation in R/cast.R \name{vec_cast.hms} \alias{vec_cast.hms} \title{Casting} \usage{ \method{vec_cast}{hms}(x, to, ...) } \arguments{ \item{x}{Vectors to cast.} \item{to}{Type to cast to. If \code{NULL}, \code{x} will be returned as is.} \item{...}{For \code{vec_cast_common()}, vectors to cast. For \code{vec_cast()}, \code{vec_cast_default()}, and \code{vec_restore()}, these dots are only for future extensions and should be empty.} } \description{ Double dispatch methods to support \code{\link[vctrs:vec_cast]{vctrs::vec_cast()}}. } hms/man/hms-package.Rd 0000644 0001762 0000144 00000001601 14124140353 014256 0 ustar ligges users % Generated by roxygen2: do not edit by hand % Please edit documentation in R/hms.R \docType{package} \name{hms-package} \alias{hms-package} \title{hms: Pretty Time of Day} \description{ \if{html}{\figure{logo.png}{options: align='right' alt='logo' width='120'}} Implements an S3 class for storing and formatting time-of-day values, based on the 'difftime' class. } \details{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#stable}{\figure{lifecycle-stable.svg}{options: alt='[Stable]'}}}{\strong{[Stable]}} } \seealso{ Useful links: \itemize{ \item \url{https://hms.tidyverse.org/} \item \url{https://github.com/tidyverse/hms} \item Report bugs at \url{https://github.com/tidyverse/hms/issues} } } \author{ \strong{Maintainer}: Kirill Müller \email{krlmlr+r@mailbox.org} Other contributors: \itemize{ \item R Consortium [funder] \item RStudio [funder] } } hms/man/hms.Rd 0000644 0001762 0000144 00000004266 14124140353 012677 0 ustar ligges users % Generated by roxygen2: do not edit by hand % Please edit documentation in R/hms.R \name{hms} \alias{hms} \alias{new_hms} \alias{is_hms} \alias{as_hms} \alias{as.POSIXct.hms} \alias{as.POSIXlt.hms} \alias{as.character.hms} \alias{format.hms} \alias{print.hms} \title{A simple class for storing time-of-day values} \usage{ hms(seconds = NULL, minutes = NULL, hours = NULL, days = NULL) new_hms(x = numeric()) is_hms(x) as_hms(x, ...) \method{as.POSIXct}{hms}(x, ...) \method{as.POSIXlt}{hms}(x, ...) \method{as.character}{hms}(x, ...) \method{format}{hms}(x, ...) \method{print}{hms}(x, ...) } \arguments{ \item{seconds, minutes, hours, days}{Time since midnight. No bounds checking is performed.} \item{x}{An object.} \item{...}{additional arguments to be passed to or from methods.} } \description{ The values are stored as a \link{difftime} vector with a custom class, and always with "seconds" as unit for robust coercion to numeric. Supports construction from time values, coercion to and from various data types, and formatting. Can be used as a regular column in a data frame. \code{hms()} is a high-level constructor that accepts second, minute, hour and day components as numeric vectors. \code{new_hms()} is a low-level constructor that only checks that its input has the correct base type, \link{numeric}. \code{is_hms()} checks if an object is of class \code{hms}. \code{as_hms()} is a generic that supports conversions beyond casting. The default method forwards to \code{\link[=vec_cast]{vec_cast()}}. } \details{ For \code{hms}, all arguments must have the same length or be \code{NULL}. Odd combinations (e.g., passing only \code{seconds} and \code{hours} but not \code{minutes}) are rejected. For arguments of type \link{POSIXct} and \link{POSIXlt}, \code{as_hms()} does not perform timezone conversion. Use \code{\link[lubridate:with_tz]{lubridate::with_tz()}} and \code{\link[lubridate:force_tz]{lubridate::force_tz()}} as necessary. } \examples{ hms(56, 34, 12) hms() new_hms(as.numeric(1:3)) # Supports numeric only! try(new_hms(1:3)) as_hms(1) as_hms("12:34:56") as_hms(Sys.time()) as.POSIXct(hms(1)) data.frame(a = hms(1)) d <- data.frame(hours = 1:3) d$hours <- hms(hours = d$hours) d } hms/man/vec_ptype2.hms.Rd 0000644 0001762 0000144 00000001601 14124140353 014744 0 ustar ligges users % Generated by roxygen2: do not edit by hand % Please edit documentation in R/coerce.R \name{vec_ptype2.hms} \alias{vec_ptype2.hms} \title{Coercion} \usage{ \method{vec_ptype2}{hms}(x, y, ..., x_arg = "", y_arg = "") } \arguments{ \item{x}{Vector types.} \item{y}{Vector types.} \item{...}{These dots are for future extensions and must be empty.} \item{x_arg}{Argument names for \code{x} and \code{y}. These are used in error messages to inform the user about the locations of incompatible types (see \code{\link[vctrs:vctrs-conditions]{stop_incompatible_type()}}).} \item{y_arg}{Argument names for \code{x} and \code{y}. These are used in error messages to inform the user about the locations of incompatible types (see \code{\link[vctrs:vctrs-conditions]{stop_incompatible_type()}}).} } \description{ Double dispatch methods to support \code{\link[vctrs:vec_ptype2]{vctrs::vec_ptype2()}}. } hms/man/round_hms.Rd 0000644 0001762 0000144 00000001663 14124140353 014104 0 ustar ligges users % Generated by roxygen2: do not edit by hand % Please edit documentation in R/round.R \name{round_hms} \alias{round_hms} \alias{trunc_hms} \title{Round or truncate to a multiple of seconds} \usage{ round_hms(x, secs = NULL, digits = NULL) trunc_hms(x, secs = NULL, digits = NULL) } \arguments{ \item{x}{A vector of class \link{hms}} \item{secs}{Multiple of seconds, a positive numeric. Values less than one are supported} \item{digits}{Number of digits, a whole number. Negative numbers are supported.} } \value{ The input, rounded or truncated to the nearest multiple of \code{secs} (or number of \code{digits}) } \description{ Convenience functions to round or truncate to a multiple of seconds. } \examples{ round_hms(as_hms("12:34:56"), 5) round_hms(as_hms("12:34:56"), 60) round_hms(as_hms("12:34:56.78"), 0.25) round_hms(as_hms("12:34:56.78"), digits = 1) round_hms(as_hms("12:34:56.78"), digits = -2) trunc_hms(as_hms("12:34:56"), 60) } hms/man/Deprecated.Rd 0000644 0001762 0000144 00000002354 14124140353 014144 0 ustar ligges users % Generated by roxygen2: do not edit by hand % Please edit documentation in R/hms.R \name{Deprecated} \alias{Deprecated} \alias{is.hms} \alias{as.hms} \alias{as.hms.default} \alias{as.hms.POSIXt} \alias{as.hms.POSIXlt} \title{Deprecated functions} \usage{ is.hms(x) as.hms(x, ...) \method{as.hms}{default}(x, ...) \method{as.hms}{POSIXt}(x, tz = pkgconfig::get_config("hms::default_tz", ""), ...) \method{as.hms}{POSIXlt}(x, tz = pkgconfig::get_config("hms::default_tz", ""), ...) } \arguments{ \item{x}{An object.} \item{...}{Arguments passed on to further methods.} \item{tz}{The time zone in which to interpret a POSIXt time for extracting the time of day. The default is now the zone of \code{x} but was \code{"UTC"} for v0.3 and earlier. The previous behavior can be restored by calling \code{pkgconfig::set_config("hms::default_tz", "UTC")}, see \code{\link[pkgconfig:set_config]{pkgconfig::set_config()}}.} } \description{ \code{is.hms()} has been replaced by \code{\link[=is_hms]{is_hms()}}. \code{as.hms()} has been replaced by \code{\link[=as_hms]{as_hms()}}, which does not have a \code{tz} argument. Change the timezone before converting if necessary, e.g. using \code{\link[lubridate:with_tz]{lubridate::with_tz()}}. } \keyword{internal} hms/man/figures/ 0000755 0001762 0000144 00000000000 14124140353 013255 5 ustar ligges users hms/man/figures/lifecycle-defunct.svg 0000644 0001762 0000144 00000001704 14124140353 017365 0 ustar ligges users