Skip to content

Commit

Permalink
Remove timezones no longer supported by Debian (fix #582)
Browse files Browse the repository at this point in the history
  • Loading branch information
billdenney committed Nov 18, 2024
1 parent 709b2ab commit a039fc0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
8 changes: 5 additions & 3 deletions R/sas_dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-convert_to_date.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"),
Expand All @@ -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")),
Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-excel_time_to_numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ 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)
)
})

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"))
)
})

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-sas_dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
})

Expand Down

0 comments on commit a039fc0

Please sign in to comment.