R/month-decimal.R

Defines functions dtt_month_decimal.POSIXct dtt_month_decimal.Date dtt_month_decimal

Documented in dtt_month_decimal dtt_month_decimal.Date dtt_month_decimal.POSIXct

#' Get Decimal Month Values
#'
#' Gets decimal month values for date/time vectors.
#'
#' @inheritParams params
#'
#' @return A numeric vector.
#' @family decimal
#' @seealso [dtt_month()]
#' @export
#'
#' @examples
#' x <- as.POSIXct("1990-01-03 10:00:01")
#' dtt_month_decimal(x)
dtt_month_decimal <- function(x, ...) {
  UseMethod("dtt_month_decimal")
}

#' @describeIn dtt_month_decimal Get numeric vector of decimal year values for a
#'   Date vector
#' @export
dtt_month_decimal.Date <- function(x, ...) {
  dtt_month(x) + (dtt_day_decimal(x) - 1) / dtt_days_in_month(x)
}

#' @describeIn dtt_month_decimal Get numeric vector of decimal year values for a
#'   POSIXct vector
#' @export
dtt_month_decimal.POSIXct <- function(x, ...) {
  dtt_month(x) + (dtt_day_decimal(x) - 1) / dtt_days_in_month(x)
}

Try the dttr2 package in your browser

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

dttr2 documentation built on Nov. 14, 2023, 5:10 p.m.