From c3d1237a78b104a5921e212e6a5f707cdce3de07 Mon Sep 17 00:00:00 2001 From: Zelos Zhu Date: Wed, 30 Aug 2023 12:37:26 -0400 Subject: [PATCH] Closes #316 remove messaging that includes "-" as year not handled (#317) * feat: #316 remove messaging that includes "-" as year not handled * feat: #316 replace warning message * chore: #316 fix warning message and typos * chore: #316 add news blurb --------- Co-authored-by: Zelos Zhu --- NEWS.md | 2 ++ R/warnings.R | 18 ++++-------------- tests/testthat/test-warnings.R | 7 ++++--- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/NEWS.md b/NEWS.md index 97bfa637..1631bf17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,8 @@ ## Updates of Existing Functions +- The messaging for `warn_if_invalid_dtc()` was updated to align with what the date/datetime functions in `admiral` currently do. (#316) + ## Breaking Changes - The following functions/arguments have been deprecated from previous admiral versions using the next phase of the deprecation process: (#288) diff --git a/R/warnings.R b/R/warnings.R index 8f6f3799..08834fc5 100644 --- a/R/warnings.R +++ b/R/warnings.R @@ -69,20 +69,10 @@ warn_if_invalid_dtc <- function(dtc, is_valid = is_valid_dtc(dtc)) { ) info <- paste0( - "The following ISO representations are handled: \n", - "2003-12-15T13:15:17.123\n", - "2003-12-15T13:15:17\n", - "2003-12-15T13:15\n", - "2003-12-15T13\n", - "2003-12-15\n", - "2003-12\n", - "2003\n", - "2003---15\n\n", - "The following ISO representations, and any other representation are NOT handled: \n", - "2003-12-15T-:15:18\n", - "2003-12-15T13:-:19\n", - "--12-15\n", - "-----T07:15" + "ISO representations of the form YYYY-MM-DDThh:mm:ss.ddd are expected, ", + "e.g., 2003-12-15T13:15:17.123. Missing parts at the end can be omitted. ", + "Missing parts in the middle must be represented by a dash, e.g., 2003---15.", + sep = "\n" ) warn(paste(main_msg, tbl, info, sep = "\n")) } diff --git a/tests/testthat/test-warnings.R b/tests/testthat/test-warnings.R index 23df263e..a69d84fd 100644 --- a/tests/testthat/test-warnings.R +++ b/tests/testthat/test-warnings.R @@ -21,11 +21,12 @@ test_that("warn_if_vars_exist Test 1: warning if a variable already exists in th ) }) -# warn_if_invalud_dtc ---- +# warn_if_invalid_dtc ---- ## Test 2: Warning if vector contains unknown datetime format ---- -test_that("warn_if_invalud_dtc Test 2: Warning if vector contains unknown datetime format", { +test_that("warn_if_invalid_dtc Test 2: Warning if vector contains unknown datetime format", { expect_warning( - warn_if_invalid_dtc(dtc = "20210406T12:30:30") + warn_if_invalid_dtc(dtc = "20210406T12:30:30"), + "Dataset contains incorrect datetime format:" ) })