Skip to content

Commit

Permalink
Implement as_date
Browse files Browse the repository at this point in the history
  • Loading branch information
imanuelcostigan committed Mar 6, 2016
1 parent 5b95083 commit eeb785c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions R/coercion.r
Original file line number Diff line number Diff line change
Expand Up @@ -548,3 +548,28 @@ setMethod("as.character", signature(x = "Duration"), function(x, ...){
setMethod("as.character", signature(x = "Interval"), function(x, ...){
format(x)
})



#' Coerce to a Date
#'
#' @param x a POSIXct, POSIXt date
#'
#' @return a \code{\link{Date}} object that corresponds to the day of the year
#' in the time zone of \code{x}.
#' @export
#'
#' @examples
#' dt1 <- as.POSIXct("2010-08-03 00:59:59.23")
#' as_date(dt1)
#' dt2 <- as.POSIXct("2010-08-03 00:59:59.23", tz="Europe/London")
#' as_date(dt2)
setGeneric(name = "as_date", def = function(x) standardGeneric("as_date"))

#' @export
setMethod(f = "as_date", signature = "POSIXt", definition = function (x) {
as.Date(x, tz(x))
})



0 comments on commit eeb785c

Please sign in to comment.