Skip to content

Commit

Permalink
use %OS for printing time (#81)
Browse files Browse the repository at this point in the history
- Date columns now show sub-seconds if the `digits.secs` option is set (#74).
  • Loading branch information
krlmlr authored Jan 11, 2018
1 parent a88ab6b commit 66e3cd4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/shaft.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pillar_shaft.Date <- function(x, ...) {
#' @rdname pillar_shaft
pillar_shaft.POSIXt <- function(x, ...) {
date <- format(x, format = "%Y-%m-%d")
time <- format(x, format = "%H:%M:%S")
time <- format(x, format = "%H:%M:%OS")

datetime <- paste0(date, " " , style_subtle(time))
datetime[is.na(x)] <- NA
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/helper-output.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ df_all <- list(
d = c("a", "b", NA),
e = factor(c("a", "b", NA)),
f = as.Date("2015-12-09") + c(1:2, NA),
g = as.POSIXct("2015-12-09 10:51:34 UTC") + c(1:2, NA),
g = as.POSIXct("2015-12-09 10:51:34.5678 UTC") + c(1:2, NA),
h = as.list(c(1:2, NA)),
i = list(list(1, 2:3), list(4:6), list(NA))
)
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/out/tibble-all-digits-secs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
g
 <dttm> 
1 2015-12-09 10:51:35.56780
2 2015-12-09 10:51:36.56780
3 NA
12 changes: 12 additions & 0 deletions tests/testthat/test-format_multi.R
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,15 @@ test_that("empty", {
structure(character(), class = "pillar_vertical")
)
})


test_that("option(digits.secs) (#74)", {
withr::with_options(
list(digits.secs = 5),
expect_pillar_output(
crayon = FALSE,
xf = colonnade(df_all["g"]),
filename = "tibble-all-digits-secs.txt"
)
)
})

0 comments on commit 66e3cd4

Please sign in to comment.