From a039fc03710d465c7528913e898ef2381438d8ea Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Mon, 18 Nov 2024 14:39:30 -0500 Subject: [PATCH] Remove timezones no longer supported by Debian (fix #582) --- R/sas_dates.R | 8 +++++--- tests/testthat/test-convert_to_date.R | 12 ++++++------ tests/testthat/test-excel_time_to_numeric.R | 8 ++++---- tests/testthat/test-sas_dates.R | 8 ++++---- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/R/sas_dates.R b/R/sas_dates.R index da4c6370..be13d89d 100644 --- a/R/sas_dates.R +++ b/R/sas_dates.R @@ -37,9 +37,11 @@ sas_numeric_to_date <- function(date_num, datetime_num, time_num, tz = "") { if (!all(mask_na_match)) { stop("The same values are not NA for both `date_num` and `time_num`") } - ret <- as.POSIXct(86400 * date_num + time_num, origin = "1960-01-01", tz = tz) - } else if (has_datetime) { - ret <- as.POSIXct(datetime_num, origin = "1960-01-01", tz = tz) + datetime_num <- 86400 * date_num + time_num + has_datetime <- TRUE + } + if (has_datetime) { + ret <- as.POSIXct(datetime_num, origin = "1960-01-01", tz = "UTC") } else if (has_date) { ret <- as.Date(date_num, origin = "1960-01-01") } else if (has_time) { diff --git a/tests/testthat/test-convert_to_date.R b/tests/testthat/test-convert_to_date.R index fb7e8e98..cfb48b8a 100644 --- a/tests/testthat/test-convert_to_date.R +++ b/tests/testthat/test-convert_to_date.R @@ -48,8 +48,8 @@ test_that("convert_datetime works", { as.POSIXct("2009-07-06 12:13:14", tz = "UTC") ) expect_equal( - convert_to_datetime("2009-07-06 12:13:14", tz = "EST"), - as.POSIXct("2009-07-06 12:13:14", tz = "EST"), + convert_to_datetime("2009-07-06 12:13:14", tz = "Etc/GMT-5"), + as.POSIXct("2009-07-06 12:13:14", tz = "Etc/GMT-5"), info = "The tz argument is respected" ) expect_equal( @@ -61,8 +61,8 @@ test_that("convert_datetime works", { as.POSIXct("2009-07-06 02:24", tz = "UTC") ) expect_equal( - convert_to_datetime(40000.1, tz = "EST"), - as.POSIXct("2009-07-06 02:24", tz = "EST") + convert_to_datetime(40000.1, tz = "Etc/GMT-5"), + as.POSIXct("2009-07-06 02:24", tz = "Etc/GMT-5") ) expect_equal( convert_to_datetime("40000"), @@ -73,8 +73,8 @@ test_that("convert_datetime works", { as.POSIXct("2009-07-06 02:24", tz = "UTC") ) expect_equal( - convert_to_datetime("40000.1", tz = "EST"), - as.POSIXct("2009-07-06 02:24", tz = "EST") + convert_to_datetime("40000.1", tz = "Etc/GMT-5"), + as.POSIXct("2009-07-06 02:24", tz = "Etc/GMT-5") ) expect_equal( convert_to_datetime(factor("40000.1")), diff --git a/tests/testthat/test-excel_time_to_numeric.R b/tests/testthat/test-excel_time_to_numeric.R index 42d7ac93..907a7976 100644 --- a/tests/testthat/test-excel_time_to_numeric.R +++ b/tests/testthat/test-excel_time_to_numeric.R @@ -13,11 +13,11 @@ test_that("excel_time_to_numeric POSIX objects extract the correct part of the t }) test_that("excel_time_to_numeric POSIX objects ignore the time zone", { - expect_equal(excel_time_to_numeric(as.POSIXct("1899-12-31 13:00", tz = "EST")), 13 * 3600) + expect_equal(excel_time_to_numeric(as.POSIXct("1899-12-31 13:00", tz = "Etc/GMT-5")), 13 * 3600) expect_equal(excel_time_to_numeric(as.POSIXct("1899-12-31 13:00", tz = "UTC")), 13 * 3600) expect_equal( excel_time_to_numeric( - as.POSIXct(c("1899-12-31 13:00", "1899-12-31 13:00"), tz = "EST") + as.POSIXct(c("1899-12-31 13:00", "1899-12-31 13:00"), tz = "Etc/GMT-5") ), rep(13 * 3600, 2) ) @@ -25,8 +25,8 @@ test_that("excel_time_to_numeric POSIX objects ignore the time zone", { test_that("excel_time_to_numeric POSIXlt works like POSIXct", { expect_equal( - excel_time_to_numeric(as.POSIXct("1899-12-31 13:00", tz = "EST")), - excel_time_to_numeric(as.POSIXlt("1899-12-31 13:00", tz = "EST")) + excel_time_to_numeric(as.POSIXct("1899-12-31 13:00", tz = "Etc/GMT-5")), + excel_time_to_numeric(as.POSIXlt("1899-12-31 13:00", tz = "Etc/GMT-5")) ) }) diff --git a/tests/testthat/test-sas_dates.R b/tests/testthat/test-sas_dates.R index ab34e21b..9157b335 100644 --- a/tests/testthat/test-sas_dates.R +++ b/tests/testthat/test-sas_dates.R @@ -17,12 +17,12 @@ test_that("sas_numeric_to_date", { ) # NA management expect_equal( - sas_numeric_to_date(date_num = c(NA, 1), time_num = c(NA, 1), tz = "EST"), - as.POSIXct(c(NA, "1960-01-01 19:00:01"), tz = "EST") + sas_numeric_to_date(date_num = c(NA, 1), time_num = c(NA, 1), tz = "Etc/GMT-5"), + as.POSIXct(c(NA, "1960-01-01 19:00:01"), tz = "Etc/GMT-5") ) expect_equal( - sas_numeric_to_date(date_num = NA, time_num = NA, tz = "EST"), - as.POSIXct(NA, tz = "EST") + sas_numeric_to_date(date_num = NA, time_num = NA, tz = "Etc/GMT-5"), + as.POSIXct(NA, tz = "Etc/GMT-5") ) })