Skip to content

Commit

Permalink
Fix R handling of dates to work for tsibble
Browse files Browse the repository at this point in the history
  • Loading branch information
bletham committed Mar 29, 2021
1 parent 94e5d2e commit 3f4edef
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions R/R/prophet.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 3f4edef

Please sign in to comment.