- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1k
Closed
Description
Hi,
format.ITime returns incorrect output for negative values. E.g. in the following example you'd expect -1 second but you get -01:59:59 because the %/% used in format.ITime does not work as intended for values <0.
diff(as.ITime(c(3,2),origin="1970-01-01",tz="UTC"))
# [1] "-1:59:59"A solution could look like this:
function (x, ...) 
{
  neg<-x<0
  x <- abs(unclass(x))
  hh <- x%/%3600
  mm <- (x - hh * 3600)%/%60
  ss <- trunc(x - hh * 3600 - 60 * 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[neg]<-paste0("-",res[neg])
  res
}EDIT: tested with a current cvs version of data.table.
Thx
Stefan