1#' @include periods.r 2NULL 3 4#' Get/set hours component of a date-time 5#' 6#' Date-time must be a POSIXct, POSIXlt, Date, Period, chron, yearmon, yearqtr, zoo, 7#' zooreg, timeDate, xts, its, ti, jul, timeSeries, and fts objects. 8#' 9#' @export 10#' @param x a date-time object 11#' @keywords utilities manip chron methods 12#' @return the hours element of x as a decimal number 13#' @examples 14#' x <- ymd("2012-03-26") 15#' hour(x) 16#' hour(x) <- 1 17#' hour(x) <- 25 18#' hour(x) > 2 19hour <- function(x) 20 UseMethod("hour") 21 22#' @export 23hour.default <- function(x) 24 as.POSIXlt(x, tz = tz(x))$hour 25 26#' @export 27hour.Period <- function(x) 28 slot(x, "hour") 29 30#' @export 31#' @param value numeric value to be assigned to the `hour` component 32#' @rdname hour 33"hour<-" <- function(x, value) 34 x <- x + hours(value - hour(x)) 35 36setGeneric("hour<-") 37 38#' @export 39setMethod("hour<-", signature("Period"), function(x, value) { 40 slot(x, "hour") <- value 41 x 42}) 43