R/getters.R

Defines functions get_index.default get_nanosecond.default get_microsecond.default get_millisecond.default get_second.default get_minute.default get_hour.default get_day.default get_week.default get_month.default get_quarter.default get_year.default get_index get_nanosecond get_microsecond get_millisecond get_second get_minute get_hour get_day get_week get_month get_quarter get_year

Documented in get_day get_hour get_index get_microsecond get_millisecond get_minute get_month get_nanosecond get_quarter get_second get_week get_year

#' Calendar getters
#'
#' @description
#' This family of functions extract fields from a calendar vector. Each
#' calendar has its own set of supported getters, which are documented on
#' their own help page:
#'
#' - [year-month-day][year-month-day-getters]
#'
#' - [year-month-weekday][year-month-weekday-getters]
#'
#' - [year-week-day][year-week-day-getters]
#'
#' - [iso-year-week-day][iso-year-week-day-getters]
#'
#' - [year-quarter-day][year-quarter-day-getters]
#'
#' - [year-day][year-day-getters]
#'
#' There are also convenience methods for extracting certain components
#' directly from R's native date and date-time types.
#'
#' - [dates (Date)][Date-getters]
#'
#' - [date-times (POSIXct / POSIXlt)][posixt-getters]
#'
#' @details
#' You cannot extract components directly from a time point type, such as
#' sys-time or naive-time. Convert it to a calendar type first. Similarly,
#' a zoned-time must be converted to either a sys-time or naive-time, and
#' then to a calendar type, to be able to extract components from it.
#'
#' @param x `[object]`
#'
#'   An object to get the component from.
#'
#' @return The component.
#'
#' @name clock-getters
#' @examples
#' x <- year_month_day(2019, 1:3, 5:7, 1, 20, 30)
#' get_month(x)
#' get_day(x)
#' get_second(x)
NULL

#' @rdname clock-getters
#' @export
get_year <- function(x) {
  UseMethod("get_year")
}

#' @rdname clock-getters
#' @export
get_quarter <- function(x) {
  UseMethod("get_quarter")
}

#' @rdname clock-getters
#' @export
get_month <- function(x) {
  UseMethod("get_month")
}

#' @rdname clock-getters
#' @export
get_week <- function(x) {
  UseMethod("get_week")
}

#' @rdname clock-getters
#' @export
get_day <- function(x) {
  UseMethod("get_day")
}

#' @rdname clock-getters
#' @export
get_hour <- function(x) {
  UseMethod("get_hour")
}

#' @rdname clock-getters
#' @export
get_minute <- function(x) {
  UseMethod("get_minute")
}

#' @rdname clock-getters
#' @export
get_second <- function(x) {
  UseMethod("get_second")
}

#' @rdname clock-getters
#' @export
get_millisecond <- function(x) {
  UseMethod("get_millisecond")
}

#' @rdname clock-getters
#' @export
get_microsecond <- function(x) {
  UseMethod("get_microsecond")
}

#' @rdname clock-getters
#' @export
get_nanosecond <- function(x) {
  UseMethod("get_nanosecond")
}

#' @rdname clock-getters
#' @export
get_index <- function(x) {
  UseMethod("get_index")
}

# ------------------------------------------------------------------------------

#' @export
get_year.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_quarter.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_month.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_week.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_day.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_hour.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_minute.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_second.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_millisecond.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_microsecond.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_nanosecond.default <- function(x) {
  stop_clock_unsupported(x)
}

#' @export
get_index.default <- function(x) {
  stop_clock_unsupported(x)
}

Try the clock package in your browser

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

clock documentation built on May 31, 2023, 9:39 p.m.