Skip to content

Commit

Permalink
[#149] Merge branch 'main' into 149-release
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbarbone committed Sep 30, 2022
2 parents 0f24e2d + 6ed13e0 commit a1a67c6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* `drop_levels()` is exported [#105](https://github.com/jmbarbone/mark/issues/105)
* `recode_by()` and `recode_only()` handle factors better [#81](https://github.com/jmbarbone/mark/issues/81)
* Functions that made use of `shell.exec()` now try to determine the appropriate method of opening a file base on OS. [#126](https://github.com/jmbarbone/mark/issues/126)
* Internal functions for potentially coercing factor levels into dates no longer try to check for `"%Z"` in the date format [#147](https://github.com/jmbarbone/mark/issues/147)

## Breaking changes

Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ try_formats <- function(date = FALSE) {
NULL
)

c(x, paste(x, "%Z"), if (date) c("%Y-%m-%d", "%Y/%m/%d", "%Y%m%d"))
c(x, if (date) c("%Y-%m-%d", "%Y/%m/%d", "%Y%m%d"))
}

has_char <- function(x) {
Expand Down
6 changes: 4 additions & 2 deletions tests/testthat/test-fact.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ test_that("fact_coerce_levels() works", {

# Be careful about setting a time zone
# Not very good for dealing with local
x <- as.POSIXlt("2021-09-03", tz = "UTC") + 0:2
# NOTE r-dev after 4.2.1 has some weird behavior with the 0 and returns:
# ('2021-09-03', '2021-09-03 00:00:01', '2021-09-03 00:00:02')
x <- as.POSIXlt("2021-09-03", tz = "UTC") + 1:3
expect_equal(fact_coerce_levels(as.character(x)), x)

x <- as.POSIXlt("2021-09-03", tz = "UTC") + 0:2
x <- as.POSIXlt("2021-09-03", tz = "UTC") + 1:3
expect_equal(fact_coerce_levels(as.character(x)), x)
})

Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ test_that("check_interactive()", {
expect_error(check_interactive())
options(op)
})

test_that("try_formats() doesn't cause failure with %Z", {
msg <- "strptime(xx, f, tz = tz)`: use of %Z for input is not supported"
expect_false(tryCatch(
as.POSIXct("date", tryFormats = try_formats()),
error = function(e) {
grepl(msg, e$message, fixed = TRUE)
}
))
})

0 comments on commit a1a67c6

Please sign in to comment.