From 3f4edef7f5d7f749c5524384dad02fc5e3ecf6a7 Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Mon, 29 Mar 2021 15:06:09 -0700 Subject: [PATCH] Fix R handling of dates to work for tsibble --- R/R/prophet.R | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/R/R/prophet.R b/R/R/prophet.R index fb7892e..1f5af86 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -260,17 +260,19 @@ set_date <- function(ds) { ds <- as.character(ds) } - # Type should be either character, or an object compatible with lubridate - if (is.character(ds)) { + # If a datetime, strip timezone and replace with GMT. + if (lubridate::is.instant(ds)) { + ds <- as.POSIXct(lubridate::force_tz(ds, "GMT"), tz = "GMT") + } + else { + # Assume it can be coerced into POSIXct if (min(nchar(ds), na.rm=TRUE) < 12) { ds <- as.POSIXct(ds, format = "%Y-%m-%d", tz = "GMT") } else { ds <- as.POSIXct(ds, format = "%Y-%m-%d %H:%M:%S", tz = "GMT") } - } else { - # Strip timezone and replace with GMT - ds <- as.POSIXct(lubridate::force_tz(ds, "GMT"), tz = "GMT") } + attr(ds, "tzone") <- "GMT" return(ds) }