From db42e9feda03b96e0054026fe35542d2cf0ca355 Mon Sep 17 00:00:00 2001 From: stefan-fleck Date: Tue, 11 Oct 2022 14:10:06 +0200 Subject: [PATCH] replace as.character.POSIX & co with format.POSIX & co for compat with new R version --- DESCRIPTION | 2 +- NEWS.md | 6 ++++++ R/BackupQueue.R | 10 +++++----- R/Cache.R | 2 +- R/parsers.R | 8 ++++---- R/utils-predicates.R | 6 +++--- cran-comments.md | 3 ++- tests/testthat/test_BackupQueue.R | 8 ++++---- tests/testthat/test_parsers.R | 2 +- tests/testthat/test_rotate.R | 2 +- tests/testthat/test_rotate_time.R | 2 +- 11 files changed, 29 insertions(+), 22 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index eff9d01..a5c2abe 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: rotor Title: Log Rotation and Conditional Backups -Version: 0.3.6 +Version: 0.3.7 Authors@R: person(given = "Stefan", family = "Fleck", diff --git a/NEWS.md b/NEWS.md index 265a544..f0879fe 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# rotor 0.3.7 + +* Some internal changes to date formatting for compatibility with + R-devel revision >= r82904 (2022-09-24 19:32:52). + + # rotor 0.3.6 * `rotate()`, `backup()` and co. no longer fail on filenames that diff --git a/R/BackupQueue.R b/R/BackupQueue.R index 26d8233..0b2c127 100644 --- a/R/BackupQueue.R +++ b/R/BackupQueue.R @@ -584,7 +584,7 @@ BackupQueueDateTime <- R6::R6Class( self$files$path, self$files$timestamp, max_age = max_backups, - now = as.Date(as.character(self$last_rotation)) + now = as.Date(format(self$last_rotation)) ) } @@ -813,7 +813,7 @@ BackupQueueDate <- R6::R6Class( if (nrow(bus) < 1) { NULL } else { - as.Date(as.character(max(get("files", envir = self)$timestamp))) + as.Date(format(max(get("files", envir = self)$timestamp))) } } ) @@ -933,7 +933,7 @@ select_prune_files_by_age <- function( if (is_parsable_date(max_age)){ limit <- parse_date(max_age) - to_remove <- path[as.Date(as.character(timestamp)) < limit] + to_remove <- path[as.Date(format(timestamp)) < limit] } else if (is_parsable_datetime(max_age)){ limit <- parse_datetime(max_age) @@ -956,10 +956,10 @@ select_prune_files_by_age <- function( limit <- dint::first_of_isoweek(dint::as_date_yw(now) - max_age$value + 1L) } else if (identical(max_age[["unit"]], "day")){ - limit <- as.Date(as.character(now)) - max_age$value + 1L + limit <- as.Date(format(now)) - max_age$value + 1L } - to_remove <- path[as.Date(as.character(timestamp)) < limit] + to_remove <- path[as.Date(format(timestamp)) < limit] } else { stop(ValueError(paste0(preview_object(max_age), " is not a valid timestamp or interval. See ?rotate_time for more info."))) } diff --git a/R/Cache.R b/R/Cache.R index 17766ba..c97b560 100644 --- a/R/Cache.R +++ b/R/Cache.R @@ -147,7 +147,7 @@ Cache <- R6::R6Class( assert(is.null(max_files) || is.infinite(max_files) || is_n0(max_files)) files <- self$files files <- files[order(files$mtime), ] - now <- as.Date(as.character(now)) + now <- as.Date(format(now)) rem <- list() diff --git a/R/parsers.R b/R/parsers.R index e94e0d6..8527249 100644 --- a/R/parsers.R +++ b/R/parsers.R @@ -76,7 +76,7 @@ parse_date <- function(x){ return(x) } else if (is_POSIXct(x)){ - return(as.Date(as.character(x))) + return(as.Date(format(x))) } else if (!is.character(x) && !is_integerish(x)) { stop( @@ -100,7 +100,7 @@ parse_datetime <- function(x){ if (is_POSIXct(x)){ return(x) } else if (is_Date(x)) { - return(as.POSIXct(as.character(x))) + return(as.POSIXct(format(x))) } else if (!is.character(x) && !is_integerish(x)) { stop( "`", deparse(substitute(x)), "` must be a character, Date, or POSIXt, ", @@ -145,14 +145,14 @@ prep_hms <- function(.x){ standardize_datetime_stamp <- function(x){ - gsub("T|-|_|\\s", "", as.character(x)) + gsub("T|-|_|\\s", "", format(x)) } standardize_date_stamp <- function(x){ - gsub("-|_|\\s", "", as.character(x)) + gsub("-|_|\\s", "", format(x)) } diff --git a/R/utils-predicates.R b/R/utils-predicates.R index e4c0e47..f561d27 100644 --- a/R/utils-predicates.R +++ b/R/utils-predicates.R @@ -184,7 +184,7 @@ is_backup_older_than_datetime <- function( verbose = FALSE ){ if (is_Date(backup_date)) - backup_date <- as.POSIXct(as.character(backup_date)) + backup_date <- as.POSIXct(format(backup_date)) assert(is_scalar_POSIXct(backup_date)) assert(is_parsable_datetime(datetime)) @@ -212,10 +212,10 @@ is_backup_older_than_interval <- function( verbose = FALSE ){ if (is_POSIXct(backup_date)) - backup_date <- as.Date(as.character(backup_date)) + backup_date <- as.Date(format(backup_date)) if (is_POSIXct(now)){ - now <- as.Date(as.character(now)) + now <- as.Date(format(now)) } else if (is.character(now)){ now <- as.Date(parse_datetime(now)) } diff --git a/cran-comments.md b/cran-comments.md index 7066829..a0eff59 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -2,4 +2,5 @@ 0 errors | 0 warnings | 0 notes -Rebuild help files for new R 4.2.0 +Fix issues related to the change in behaviour of `as.character.POSIXct()` & co +in r-devel. diff --git a/tests/testthat/test_BackupQueue.R b/tests/testthat/test_BackupQueue.R index a14f5ec..0ff00bd 100644 --- a/tests/testthat/test_BackupQueue.R +++ b/tests/testthat/test_BackupQueue.R @@ -710,7 +710,7 @@ test_that("BackupQueueDatetime works with supported timestamp formats", { ) expect_identical( - as.character(bq$files$timestamp), + format(bq$files$timestamp), eres ) @@ -719,7 +719,7 @@ test_that("BackupQueueDatetime works with supported timestamp formats", { file.create(noback) expect_identical( - as.character(bq$files$timestamp), + format(bq$files$timestamp), eres ) @@ -955,7 +955,7 @@ test_that("BackupQueueDateTime: `age` works with no backups", { file.create(tf) on.exit(unlink(tf), add = TRUE) - now <- as.Date(as.character(file.info(tf)$ctime)) + now <- as.Date(format(file.info(tf)$ctime)) bq <- BackupQueueDateTime$new(tf) expect_false(bq$should_rotate(age = "10 day", now = now, size = 0)) expect_true(bq$should_rotate(age = "0 day", now = now, size = 0)) @@ -1377,7 +1377,7 @@ test_that("BackupQueueDateTime: `age` works with no backups", { file.create(tf) on.exit(unlink(tf), add = TRUE) - now <- as.Date(as.character(file.info(tf)$ctime)) + now <- as.Date(format(file.info(tf)$ctime)) bq <- BackupQueueDate$new(tf) expect_false(bq$should_rotate(age = "10 day", now = now, size = 0)) expect_true(bq$should_rotate(age = "0 day", now = now, size = 0)) diff --git a/tests/testthat/test_parsers.R b/tests/testthat/test_parsers.R index 8edef90..17e8190 100644 --- a/tests/testthat/test_parsers.R +++ b/tests/testthat/test_parsers.R @@ -50,7 +50,7 @@ test_that("parse_size throws warning when it encounters floats", { test_that("parse_datetime works as expected", { d <- as.Date("2019-12-01") - expect_equal(parse_datetime(d), as.POSIXct(as.character(d))) + expect_equal(parse_datetime(d), as.POSIXct(format(d))) expect_equal(parse_datetime("2018-12-01"), as.POSIXct("2018-12-01")) expect_equal(parse_datetime("20181201"), as.POSIXct("2018-12-01")) diff --git a/tests/testthat/test_rotate.R b/tests/testthat/test_rotate.R index f4d8776..737d994 100644 --- a/tests/testthat/test_rotate.R +++ b/tests/testthat/test_rotate.R @@ -43,7 +43,7 @@ test_that("backup/rotate happy path", { expect_identical(bq$n, 3L) expect_equal(file.size(tf), 0) expect_equal(file.size(bq$files$path[[1]]), tf_size) - expect_equal(bq$files$sfx, as.character(1:3)) + expect_equal(bq$files$sfx, format(1:3)) bq$prune(0) file.remove(tf) diff --git a/tests/testthat/test_rotate_time.R b/tests/testthat/test_rotate_time.R index 2e5f77e..6c3648e 100644 --- a/tests/testthat/test_rotate_time.R +++ b/tests/testthat/test_rotate_time.R @@ -35,7 +35,7 @@ test_that("backup_time common usecases", { expect_identical(bq$n, 4L) expect_equal(bq$last_rotation, as.POSIXct("2019-03-01 00:00:01")) expect_identical( - as.character(min(bq$files$timestamp)), + format(min(bq$files$timestamp)), "2019-01-01" )