R/accessors-dst.r

Defines functions dst.default dst

Documented in dst

#' Get **d**aylight **s**avings **t**ime indicator of a date-time
#'
#' Date-time must be a POSIXct, POSIXlt, Date, chron, yearmon, yearqtr, zoo,
#' zooreg, timeDate, xts, its, ti, jul, timeSeries, and fts objects.
#'
#' A date-time's daylight savings flag can not be set because it depends on the
#' date-time's year, month, day, and hour values.
#'
#' @export
#' @param x a date-time object
#' @return A logical. TRUE if DST is in force, FALSE if not, NA if unknown.
#' @keywords utilities chron methods
#' @examples
#' x <- ymd("2012-03-26")
#' dst(x)
dst <- function(x) {
  UseMethod("dst")
}

#' @export
dst.default <- function(x) {
  c(NA, FALSE, TRUE)[as.POSIXlt(x)$isdst + 2]
}
hadley/lubridate documentation built on Feb. 3, 2024, 9:37 a.m.