diff --git a/R/shaft-.R b/R/shaft-.R index 37df2d87..f5d47585 100644 --- a/R/shaft-.R +++ b/R/shaft-.R @@ -277,7 +277,13 @@ pillar_shaft.POSIXt <- function(x, ...) { date <- format(x, format = "%Y-%m-%d") time <- format(x, format = "%H:%M:%OS") - datetime <- paste0(date, ifelse(is.finite(x), paste0(" ", style_subtle(time)), "")) + # R < 4.3 don't support is.finite() for POSIXlt + time_styled <- paste0(" ", style_subtle(time)) + if (inherits(x, "POSIXct")) { + time_styled[!is.finite(x)] <- "" + } + + datetime <- paste0(date, time_styled) datetime[is.na(x)] <- NA new_pillar_shaft_simple(datetime, width = width, align = "left") diff --git a/tests/testthat/test-shaft-.R b/tests/testthat/test-shaft-.R index 35838b67..a11a4f82 100644 --- a/tests/testthat/test-shaft-.R +++ b/tests/testthat/test-shaft-.R @@ -6,6 +6,7 @@ test_that("S4 character class (tidyverse/tibble#1367)", { }) test_that("Infinite times (#645)", { + skip_if(getRversion() < "4.3") expect_snapshot({ pillar(.POSIXct(Inf)) })