From 96717fd9b13c5148969310e5277b754ebbee017f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Wed, 22 Dec 2021 09:50:31 +0100 Subject: [PATCH 1/2] Fix nanotime support --- DESCRIPTION | 1 + R/shaft-.R | 4 ++ tests/testthat/_snaps/format_integer64.md | 69 +++++++++++++++++++++++ tests/testthat/test-format_integer64.R | 20 +++++++ 4 files changed, 94 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index c4bcfdd50..3d85f5945 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,6 +36,7 @@ Suggests: ggplot2, knitr, lubridate, + nanotime, nycflights13, palmerpenguins, rmarkdown, diff --git a/R/shaft-.R b/R/shaft-.R index d45db3013..e8bfc78de 100644 --- a/R/shaft-.R +++ b/R/shaft-.R @@ -207,6 +207,10 @@ pillar_shaft_number <- function(x, sigfig, digits, notation, fixed_exponent, ext # registered in .onLoad() pillar_shaft.integer64 <- function(x, ..., sigfig = NULL) { + if (class(x)[[1]] != "integer64") { + return(NextMethod()) + } + pillar_shaft_number(x, sigfig, digits = NULL, notation = NULL, fixed_exponent = NULL, extra_sigfig = NULL) } diff --git a/tests/testthat/_snaps/format_integer64.md b/tests/testthat/_snaps/format_integer64.md index 807e2c611..02c4d7687 100644 --- a/tests/testthat/_snaps/format_integer64.md +++ b/tests/testthat/_snaps/format_integer64.md @@ -82,3 +82,72 @@ 1000000000002 NA +# nanotime works (#378) + + Code + pillar(x, width = 16) + Output + + + 2011-12-05T08:3~ + Code + pillar(x, width = 17) + Output + + + 2011-12-05T08:30~ + Code + pillar(x, width = 18) + Output + + + 2011-12-05T08:30:~ + Code + pillar(x, width = 19) + Output + + + 2011-12-05T08:30:0~ + Code + pillar(x, width = 20) + Output + + + 2011-12-05T08:30:00~ + Code + pillar(x, width = 21) + Output + + + 2011-12-05T08:30:00+~ + Code + pillar(x, width = 22) + Output + + + 2011-12-05T08:30:00+0~ + Code + pillar(x, width = 23) + Output + + + 2011-12-05T08:30:00+00~ + Code + pillar(x, width = 24) + Output + + + 2011-12-05T08:30:00+00:~ + Code + pillar(x, width = 25) + Output + + + 2011-12-05T08:30:00+00:00 + Code + pillar(x, width = 26) + Output + + + 2011-12-05T08:30:00+00:00 + diff --git a/tests/testthat/test-format_integer64.R b/tests/testthat/test-format_integer64.R index 01ea6fe0e..c54f2a97e 100644 --- a/tests/testthat/test-format_integer64.R +++ b/tests/testthat/test-format_integer64.R @@ -15,3 +15,23 @@ test_that("integer64 output will use scientific if necessary", { pillar(add_special(x), width = 14) }) }) + +test_that("nanotime works (#378)", { + skip_if_not_installed("nanotime") + + # 0 tests for NA warning too + x <- nanotime::nanotime('2011-12-05 08:30:00.000', format ="%Y-%m-%d %H:%M:%E9S", tz ="GMT") + expect_snapshot({ + pillar(x, width = 16) + pillar(x, width = 17) + pillar(x, width = 18) + pillar(x, width = 19) + pillar(x, width = 20) + pillar(x, width = 21) + pillar(x, width = 22) + pillar(x, width = 23) + pillar(x, width = 24) + pillar(x, width = 25) + pillar(x, width = 26) + }) +}) From 8a90c90cedb844dbd8ec28284517edb5044d4bed Mon Sep 17 00:00:00 2001 From: krlmlr Date: Wed, 22 Dec 2021 08:54:32 +0000 Subject: [PATCH 2/2] Auto-update from GitHub Actions Run: https://github.com/r-lib/pillar/actions/runs/1610539199 --- tests/testthat/test-format_integer64.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-format_integer64.R b/tests/testthat/test-format_integer64.R index c54f2a97e..13ef27742 100644 --- a/tests/testthat/test-format_integer64.R +++ b/tests/testthat/test-format_integer64.R @@ -20,7 +20,7 @@ test_that("nanotime works (#378)", { skip_if_not_installed("nanotime") # 0 tests for NA warning too - x <- nanotime::nanotime('2011-12-05 08:30:00.000', format ="%Y-%m-%d %H:%M:%E9S", tz ="GMT") + x <- nanotime::nanotime('2011-12-05 08:30:00.000', format = "%Y-%m-%d %H:%M:%E9S", tz = "GMT") expect_snapshot({ pillar(x, width = 16) pillar(x, width = 17)