Skip to content

Commit

Permalink
Merge pull request #2035 from MichaelChirico/formatITime
Browse files Browse the repository at this point in the history
Closes #2032 -- error in format.ITime edge case (0-length input)
  • Loading branch information
mattdowle committed May 11, 2017
2 parents 03ee346 + 67d31d1 commit 37e5851
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

7. Seg fault in `rbindlist()` when one or more items are empty, [#2019](https://github.com/Rdatatable/data.table/issues/2019). Thanks Michael Lang for the pull request.

2. Fixed an error in `format.ITime` that was preventing printing of 0-length `ITime` objects, [#2032](https://github.com/Rdatatable/data.table/issues/2032). Thanks @MichaelChirico.

#### NOTES


Expand Down
4 changes: 1 addition & 3 deletions R/IDateTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,7 @@ as.character.ITime <- format.ITime <- function(x, ...) {
hh <- x %/% 3600L
mm <- (x - hh * 3600L) %/% 60L
ss <- trunc(x - hh * 3600L - 60L * mm)
res = paste(substring(paste("0", hh, sep = ""), nchar(paste(hh))),
substring(paste("0", mm, sep = ""), nchar(paste(mm))),
substring(paste("0", ss, sep = ""), nchar(paste(ss))), sep = ":")
res = sprintf('%02d:%02d:%02d', hh, mm, ss)
# Fix for #1354, so that "NA" input is handled correctly.
if (is.na(any(neg))) res[is.na(x)] = NA
neg = which(neg)
Expand Down
3 changes: 3 additions & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -9907,6 +9907,9 @@ x = list(list(a = 1), list(), list(a = 2))
ans = data.table(id=c(1L,3L),a=c(1,2))
for (i in 1:100) test(1763, rbindlist(x, idcol="id"), ans)

# as.ITime(character(0)) used to fail, #2032
test(1764, capture.output(format(as.ITime(character(0)))), "character(0)")

##########################

# TODO: Tests involving GForce functions needs to be run with optimisation level 1 and 2, so that both functions are tested all the time.
Expand Down

0 comments on commit 37e5851

Please sign in to comment.