From 16aa4e1fba976c33bc598595ed8346371f10012a Mon Sep 17 00:00:00 2001 From: Bill Denney Date: Tue, 19 Nov 2024 12:34:56 -0500 Subject: [PATCH] Ensure that `tz` is respected in `sas_numeric_to_date()`; test update for recent change; clarify minor breaking change for `sas_numeric_to_date()` --- NEWS.md | 3 +-- R/sas_dates.R | 2 +- tests/testthat/test-sas_dates.R | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 195f003..3346e46 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ These are all minor breaking changes resulting from enhancements and are not exp * When `tabyl()` is called on a data.frame containing labels, it now displays the label attribute as the name of the first column in the the resulting `tabyl` object (@olivroy, #394). This may break subsequent code that refers to the output of such a `tabyl` by column name. To maintain the previous behavior of ignoring variable labels, you can remove the labels with a function like `haven::zap_labels()` or `labelled::remove_labels()` before calling `tabyl()`. +* `sas_numeric_to_date()` now warns for timezones other than "UTC" due to the way that SAS loads timezones, and the default timezone for `sas_numeric_to_date()` is now "UTC" instead of "" (#583, @billdenney) ## New features @@ -33,8 +34,6 @@ These are all minor breaking changes resulting from enhancements and are not exp * Restyle the package and vignettes according to the [tidyverse style guide](https://style.tidyverse.org) (#548, @olivroy) -* `sas_numeric_to_date()` now warns for timezones other than "UTC" due to potential misinterpretation (#583, @billdenney) - # janitor 2.2.0 (2023-02-02) ## Breaking changes diff --git a/R/sas_dates.R b/R/sas_dates.R index e1d6682..f1e4935 100644 --- a/R/sas_dates.R +++ b/R/sas_dates.R @@ -46,7 +46,7 @@ sas_numeric_to_date <- function(date_num, datetime_num, time_num, tz = "UTC") { has_datetime <- TRUE } if (has_datetime) { - ret <- as.POSIXct(datetime_num, origin = "1960-01-01", tz = "UTC") + ret <- as.POSIXct(datetime_num, origin = "1960-01-01", tz = tz) } else if (has_date) { ret <- as.Date(date_num, origin = "1960-01-01") } else if (has_time) { diff --git a/tests/testthat/test-sas_dates.R b/tests/testthat/test-sas_dates.R index 3c5c598..1814c08 100644 --- a/tests/testthat/test-sas_dates.R +++ b/tests/testthat/test-sas_dates.R @@ -27,7 +27,7 @@ test_that("sas_numeric_to_date", { # Timezone warning (#583) expect_warning( sas_numeric_to_date(date_num = 1, time_num = 1, tz = "America/New_York"), - regexp = "`tz` in SAS does not appear to be stored with the source data; please verify timezone conversion is correct", + regexp = "SAS may not properly store timezones other than UTC. Consider confirming the accuracy of the resulting data.", fixed = TRUE ) })