From d7fb43ae81d0e3bb9048d2be134ca7aed182f39d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 15 Dec 2024 11:04:45 +0100 Subject: [PATCH] test: Fix tests for older R versions --- R/shaft-.R | 8 +++++++- tests/testthat/test-shaft-.R | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) 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)) })