Skip to content

Commit db42e9f

Browse files
committed
replace as.character.POSIX & co with format.POSIX & co for compat with new R version
1 parent 41cd049 commit db42e9f

File tree

11 files changed

+29
-22
lines changed

11 files changed

+29
-22
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: rotor
33
Title: Log Rotation and Conditional Backups
4-
Version: 0.3.6
4+
Version: 0.3.7
55
Authors@R:
66
person(given = "Stefan",
77
family = "Fleck",

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# rotor 0.3.7
2+
3+
* Some internal changes to date formatting for compatibility with
4+
R-devel revision >= r82904 (2022-09-24 19:32:52).
5+
6+
17
# rotor 0.3.6
28

39
* `rotate()`, `backup()` and co. no longer fail on filenames that

R/BackupQueue.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ BackupQueueDateTime <- R6::R6Class(
584584
self$files$path,
585585
self$files$timestamp,
586586
max_age = max_backups,
587-
now = as.Date(as.character(self$last_rotation))
587+
now = as.Date(format(self$last_rotation))
588588
)
589589
}
590590

@@ -813,7 +813,7 @@ BackupQueueDate <- R6::R6Class(
813813
if (nrow(bus) < 1) {
814814
NULL
815815
} else {
816-
as.Date(as.character(max(get("files", envir = self)$timestamp)))
816+
as.Date(format(max(get("files", envir = self)$timestamp)))
817817
}
818818
}
819819
)
@@ -933,7 +933,7 @@ select_prune_files_by_age <- function(
933933

934934
if (is_parsable_date(max_age)){
935935
limit <- parse_date(max_age)
936-
to_remove <- path[as.Date(as.character(timestamp)) < limit]
936+
to_remove <- path[as.Date(format(timestamp)) < limit]
937937

938938
} else if (is_parsable_datetime(max_age)){
939939
limit <- parse_datetime(max_age)
@@ -956,10 +956,10 @@ select_prune_files_by_age <- function(
956956
limit <- dint::first_of_isoweek(dint::as_date_yw(now) - max_age$value + 1L)
957957

958958
} else if (identical(max_age[["unit"]], "day")){
959-
limit <- as.Date(as.character(now)) - max_age$value + 1L
959+
limit <- as.Date(format(now)) - max_age$value + 1L
960960
}
961961

962-
to_remove <- path[as.Date(as.character(timestamp)) < limit]
962+
to_remove <- path[as.Date(format(timestamp)) < limit]
963963
} else {
964964
stop(ValueError(paste0(preview_object(max_age), " is not a valid timestamp or interval. See ?rotate_time for more info.")))
965965
}

R/Cache.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Cache <- R6::R6Class(
147147
assert(is.null(max_files) || is.infinite(max_files) || is_n0(max_files))
148148
files <- self$files
149149
files <- files[order(files$mtime), ]
150-
now <- as.Date(as.character(now))
150+
now <- as.Date(format(now))
151151

152152
rem <- list()
153153

R/parsers.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ parse_date <- function(x){
7676
return(x)
7777

7878
} else if (is_POSIXct(x)){
79-
return(as.Date(as.character(x)))
79+
return(as.Date(format(x)))
8080

8181
} else if (!is.character(x) && !is_integerish(x)) {
8282
stop(
@@ -100,7 +100,7 @@ parse_datetime <- function(x){
100100
if (is_POSIXct(x)){
101101
return(x)
102102
} else if (is_Date(x)) {
103-
return(as.POSIXct(as.character(x)))
103+
return(as.POSIXct(format(x)))
104104
} else if (!is.character(x) && !is_integerish(x)) {
105105
stop(
106106
"`", deparse(substitute(x)), "` must be a character, Date, or POSIXt, ",
@@ -145,14 +145,14 @@ prep_hms <- function(.x){
145145

146146

147147
standardize_datetime_stamp <- function(x){
148-
gsub("T|-|_|\\s", "", as.character(x))
148+
gsub("T|-|_|\\s", "", format(x))
149149
}
150150

151151

152152

153153

154154
standardize_date_stamp <- function(x){
155-
gsub("-|_|\\s", "", as.character(x))
155+
gsub("-|_|\\s", "", format(x))
156156
}
157157

158158

R/utils-predicates.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ is_backup_older_than_datetime <- function(
184184
verbose = FALSE
185185
){
186186
if (is_Date(backup_date))
187-
backup_date <- as.POSIXct(as.character(backup_date))
187+
backup_date <- as.POSIXct(format(backup_date))
188188

189189
assert(is_scalar_POSIXct(backup_date))
190190
assert(is_parsable_datetime(datetime))
@@ -212,10 +212,10 @@ is_backup_older_than_interval <- function(
212212
verbose = FALSE
213213
){
214214
if (is_POSIXct(backup_date))
215-
backup_date <- as.Date(as.character(backup_date))
215+
backup_date <- as.Date(format(backup_date))
216216

217217
if (is_POSIXct(now)){
218-
now <- as.Date(as.character(now))
218+
now <- as.Date(format(now))
219219
} else if (is.character(now)){
220220
now <- as.Date(parse_datetime(now))
221221
}

cran-comments.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
0 errors | 0 warnings | 0 notes
44

5-
Rebuild help files for new R 4.2.0
5+
Fix issues related to the change in behaviour of `as.character.POSIXct()` & co
6+
in r-devel.

tests/testthat/test_BackupQueue.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ test_that("BackupQueueDatetime works with supported timestamp formats", {
710710
)
711711

712712
expect_identical(
713-
as.character(bq$files$timestamp),
713+
format(bq$files$timestamp),
714714
eres
715715
)
716716

@@ -719,7 +719,7 @@ test_that("BackupQueueDatetime works with supported timestamp formats", {
719719
file.create(noback)
720720

721721
expect_identical(
722-
as.character(bq$files$timestamp),
722+
format(bq$files$timestamp),
723723
eres
724724
)
725725

@@ -955,7 +955,7 @@ test_that("BackupQueueDateTime: `age` works with no backups", {
955955
file.create(tf)
956956
on.exit(unlink(tf), add = TRUE)
957957

958-
now <- as.Date(as.character(file.info(tf)$ctime))
958+
now <- as.Date(format(file.info(tf)$ctime))
959959
bq <- BackupQueueDateTime$new(tf)
960960
expect_false(bq$should_rotate(age = "10 day", now = now, size = 0))
961961
expect_true(bq$should_rotate(age = "0 day", now = now, size = 0))
@@ -1377,7 +1377,7 @@ test_that("BackupQueueDateTime: `age` works with no backups", {
13771377
file.create(tf)
13781378
on.exit(unlink(tf), add = TRUE)
13791379

1380-
now <- as.Date(as.character(file.info(tf)$ctime))
1380+
now <- as.Date(format(file.info(tf)$ctime))
13811381
bq <- BackupQueueDate$new(tf)
13821382
expect_false(bq$should_rotate(age = "10 day", now = now, size = 0))
13831383
expect_true(bq$should_rotate(age = "0 day", now = now, size = 0))

tests/testthat/test_parsers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ test_that("parse_size throws warning when it encounters floats", {
5050

5151
test_that("parse_datetime works as expected", {
5252
d <- as.Date("2019-12-01")
53-
expect_equal(parse_datetime(d), as.POSIXct(as.character(d)))
53+
expect_equal(parse_datetime(d), as.POSIXct(format(d)))
5454

5555
expect_equal(parse_datetime("2018-12-01"), as.POSIXct("2018-12-01"))
5656
expect_equal(parse_datetime("20181201"), as.POSIXct("2018-12-01"))

tests/testthat/test_rotate.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test_that("backup/rotate happy path", {
4343
expect_identical(bq$n, 3L)
4444
expect_equal(file.size(tf), 0)
4545
expect_equal(file.size(bq$files$path[[1]]), tf_size)
46-
expect_equal(bq$files$sfx, as.character(1:3))
46+
expect_equal(bq$files$sfx, format(1:3))
4747

4848
bq$prune(0)
4949
file.remove(tf)

0 commit comments

Comments
 (0)