Skip to content

Commit 8953cbc

Browse files
committed
Simplify format.POSIXlt() to improve bugzilla issue 17350
there is also a bit of whitespace change as the indentation was off for under Emacs/ESS which is unusual for base R code.
1 parent 9ad8999 commit 8953cbc

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/library/base/R/datetime.R

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -384,19 +384,12 @@ format.POSIXlt <- function(x, format = "", usetz = FALSE,
384384
if(!inherits(x, "POSIXlt")) stop("wrong class")
385385
if(any(f0 <- format == "")) {
386386
## need list [ method here.
387-
times <- unlist(unclass(x)[1L:3L])[f0]
388-
secs <- x$sec[f0]; secs <- secs[is.finite(secs)]
387+
times <- unlist(unclass(x)[1L:3L])[f0]
389388
np <- if(is.null(digits)) 0L else min(6L, digits)
390-
if(np >= 1L) # no unnecessary trailing '0' :
391-
for (i in seq_len(np)- 1L)
392-
if(all( abs(secs - round(secs, i)) < 1e-6 )) {
393-
np <- i
394-
break
395-
}
396-
format[f0] <-
397-
if(all(times[is.finite(times)] == 0)) "%Y-%m-%d"
398-
else if(np == 0L) "%Y-%m-%d %H:%M:%S"
399-
else paste0("%Y-%m-%d %H:%M:%OS", np)
389+
format[f0] <-
390+
if(all(times[is.finite(times)] == 0)) "%Y-%m-%d"
391+
else if(np == 0L) "%Y-%m-%d %H:%M:%S"
392+
else paste0("%Y-%m-%d %H:%M:%OS", np)
400393
}
401394
.Internal(format.POSIXlt(x, format, usetz))
402395
}

0 commit comments

Comments
 (0)