r-lib / pillar

Format columns with colour
https://pillar.r-lib.org/
Other
178 stars 37 forks source link

FR: don't print seconds in dttm if there is not enough space #647

Open olivroy opened 1 year ago

olivroy commented 1 year ago

Hi, I was wondering if it was possible not to print seconds if there are many columns (i.e. adaptative printing) in tibbles.

I use a custom version of pillar_shaft for dttm, but it never prints seconds.

  pillar_shaft.POSIXct <- function(x, ...) {
    width <- 17L
    date <- format(x, format = "%Y-%m-%d")
    time <- format(x, format = "%H:%M")
    datetime <- paste0(date, " ", pillar::style_subtle(time))
    datetime[is.na(x)] <- NA
    pillar::new_pillar_shaft_simple(datetime, width = width, align = "left")
  }

I was wondering if it would be possible to add this option to https://github.com/r-lib/pillar/blob/92095fcc0fffa6d2b2d42c3ec6017e7501c0c99b/R/shaft-.R#L270