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

#' Floored
#'
#' Test whether a date time vector is floored.
#' @param x A Date, POSIXct or hms vector.
#' @param units A string of the time units to floor by.
#' @param ... Unused.
#' @return A flag indicating whether floored.
#' @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 July 10, 2020, 5:06 p.m.