R/floored.R

Defines functions dtt_floored.hms dtt_floored.POSIXct dtt_floored.Date dtt_floored

Documented in dtt_floored dtt_floored.Date dtt_floored.hms dtt_floored.POSIXct

#' Test Floored
#'
#' Test whether a date time vector is floored.
#'
#' @inheritParams params
#' @param x A Date, POSIXct or hms vector.
#'
#' @return A flag indicating whether floored.
#' @family floor
#' @export
#'
#' @examples
#' dtt_floored(as.Date("2002-02-01"))
dtt_floored <- function(x, ...) {
  UseMethod("dtt_floored")
}

#' @describeIn dtt_floored Test if Date vector is floored
#' @export
dtt_floored.Date <- function(x, units = "days", ...) {
  isTRUE(all.equal(dtt_floor(x, units), x))
}

#' @describeIn dtt_floored Test if POSIXct vector is floored
#' @export
dtt_floored.POSIXct <- function(x, units = "seconds", ...) {
  isTRUE(all.equal(dtt_floor(x, units), x))
}

#' @describeIn dtt_floored Test if hms vector is floored
#' @export
dtt_floored.hms <- function(x, units = "seconds", ...) {
  isTRUE(all.equal(dtt_floor(x, units), x))
}

Try the dttr2 package in your browser

Any scripts or data that you put into this service are public.

dttr2 documentation built on Sept. 14, 2024, 1:08 a.m.