diff --git a/R/R/prophet.R b/R/R/prophet.R index 05d531f..fb7892e 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -243,8 +243,8 @@ validate_column_name <- function( #' Convert date vector #' -#' Convert the date to POSIXct object. Dates without a specified timezone will -#' be given system time zone. Dates with specified timezone will keep it. +#' Convert the date to POSIXct object. Timezones are stripped and replaced +#' with GMT. #' #' @param ds Date vector #' @@ -263,17 +263,15 @@ set_date <- function(ds) { # Type should be either character, or an object compatible with lubridate if (is.character(ds)) { if (min(nchar(ds), na.rm=TRUE) < 12) { - ds <- as.POSIXct(ds, format = "%Y-%m-%d") + ds <- as.POSIXct(ds, format = "%Y-%m-%d", tz = "GMT") } else { - ds <- as.POSIXct(ds, format = "%Y-%m-%d %H:%M:%S") + ds <- as.POSIXct(ds, format = "%Y-%m-%d %H:%M:%S", tz = "GMT") } } else { - if (is.null(attr(ds, "tzone"))) { - # Make sure we don't default to GMT timezone - ds <- lubridate::force_tz(ds) - } - ds <- as.POSIXct(ds) + # Strip timezone and replace with GMT + ds <- as.POSIXct(lubridate::force_tz(ds, "GMT"), tz = "GMT") } + attr(ds, "tzone") <- "GMT" return(ds) } @@ -1678,6 +1676,7 @@ make_future_dataframe <- function(m, periods, freq = 'day', dates <- dates[2:(periods + 1)] # Drop the first, which is max(history$ds) if (include_history) { dates <- c(m$history.dates, dates) + attr(dates, "tzone") <- "GMT" } return(data.frame(ds = dates)) } diff --git a/R/tests/testthat/test_prophet.R b/R/tests/testthat/test_prophet.R index b154da3..88469dc 100644 --- a/R/tests/testthat/test_prophet.R +++ b/R/tests/testthat/test_prophet.R @@ -213,12 +213,12 @@ test_that("fourier_series_weekly", { true.values <- c(0.7818315, 0.6234898, 0.9749279, -0.2225209, 0.4338837, -0.9009689) mat <- prophet:::fourier_series(DATA$ds, 7, 3) - expect_equal(true.values, mat[177, ], tolerance = 1e-6) + expect_equal(true.values, mat[1, ], tolerance = 1e-6) }) test_that("fourier_series_yearly", { - true.values <- c(0.70112651, -0.71303690, -0.99985814, 0.01684324, 0.72474500, - 0.68901719) + true.values <- c(0.7006152, -0.7135393, -0.9998330, 0.01827656, 0.7262249, + 0.6874572) mat <- prophet:::fourier_series(DATA$ds, 365.25, 3) expect_equal(true.values, mat[1, ], tolerance = 1e-6) })