mirror of
https://github.com/saymrwulf/prophet.git
synced 2026-11-18 08:53:42 +00:00
Fix R handling of dates to work for tsibble
This commit is contained in:
parent
94e5d2e80a
commit
3f4edef7f5
1 changed files with 7 additions and 5 deletions
|
|
@ -260,17 +260,19 @@ set_date <- function(ds) {
|
||||||
ds <- as.character(ds)
|
ds <- as.character(ds)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Type should be either character, or an object compatible with lubridate
|
# If a datetime, strip timezone and replace with GMT.
|
||||||
if (is.character(ds)) {
|
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) {
|
if (min(nchar(ds), na.rm=TRUE) < 12) {
|
||||||
ds <- as.POSIXct(ds, format = "%Y-%m-%d", tz = "GMT")
|
ds <- as.POSIXct(ds, format = "%Y-%m-%d", tz = "GMT")
|
||||||
} else {
|
} else {
|
||||||
ds <- as.POSIXct(ds, format = "%Y-%m-%d %H:%M:%S", tz = "GMT")
|
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"
|
attr(ds, "tzone") <- "GMT"
|
||||||
return(ds)
|
return(ds)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue