Skip to content

Commit

Permalink
Closes #2171 -- edge case missed in fix to #2032
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed May 19, 2017
1 parent 21d7aef commit 3e8bf24
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

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.

8. Error printing 0-length `ITime` objects, [#2032](https://github.com/Rdatatable/data.table/issues/2032). Thanks Michael Chirico for the pull request.
8. Error printing 0-length `ITime` and `NA` objects, [#2032](https://github.com/Rdatatable/data.table/issues/2032) and [#2171](https://github.com/Rdatatable/data.table/issues/2171). Thanks Michael Chirico for the pull requests and @franknarf1 for pointing out a shortcoming of the initial fix.

9. `as.IDate.POSIXct` error with `NULL` timezone, [#1973](https://github.com/Rdatatable/data.table/issues/1973). Thanks @lbilli for reporting and Michael Chirico for the pull request.

Expand Down
5 changes: 4 additions & 1 deletion R/IDateTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ as.character.ITime <- format.ITime <- function(x, ...) {
x <- abs(unclass(x))
hh <- x %/% 3600L
mm <- (x - hh * 3600L) %/% 60L
ss <- trunc(x - hh * 3600L - 60L * mm)
# #2171 -- trunc gives numeric but %02d requires integer;
# as.integer is also faster (but doesn't handle integer overflow)
# http://stackoverflow.com/questions/43894077
ss <- as.integer(x - hh * 3600L - 60L * mm)
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
Expand Down
4 changes: 3 additions & 1 deletion inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -9909,7 +9909,9 @@ 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)")
test(1764.1, format(as.ITime(character(0))), character(0))
# Edge case from #2171
test(1764.2, format(structure(NA_integer_, class = "ITime")), NA_character_)

# IDateTime error when tzone is NULL, #1973
x = as.POSIXct('2017-03-17')
Expand Down

0 comments on commit 3e8bf24

Please sign in to comment.