Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ S3method(rep, IDate)
S3method(rep, ITime)
S3method(round, IDate)
S3method(round, ITime)
S3method(is.numeric, IDate)
S3method(is.numeric, ITime)
S3method(trunc, ITime)
S3method(seq, IDate)
S3method(seq, ITime)
Expand Down
15 changes: 14 additions & 1 deletion R/IDateTime.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ as.Date.IDate = function(x, ...) {
}

mean.IDate =
function(x, ...) {
x = unclass(x)
as.IDate(NextMethod())
}
seq.IDate =
c.IDate =
cut.IDate =
Expand Down Expand Up @@ -90,6 +94,8 @@ round.IDate = function(x, digits=c("weeks", "months", "quarters", "years"), ...)
quarters = ISOdate(year(x), 3L * (quarter(x)-1L) + 1L, 1L),
years = ISOdate(year(x), 1L, 1L)))
}
# Dates aren't simple numbers, and round.IDate doesn't accept numeric 'digits'.
is.numeric.IDate = function(x) FALSE

chooseOpsMethod.IDate = function(x, y, mx, my, cl, reverse) inherits(y, "Date")

Expand Down Expand Up @@ -248,6 +254,9 @@ round.ITime = function(x, digits = c("hours", "minutes"), ...)
"class", "ITime"))
}

# Day times aren't simple numbers, and round.ITime doesn't accept numeric 'digits'.
is.numeric.ITime = function(x) FALSE

trunc.ITime = function(x, units = c("hours", "minutes"), ...)
{
(setattr(switch(match.arg(units),
Expand All @@ -272,7 +281,11 @@ unique.ITime = function(x, ...) {
}

# various methods to ensure ITime class is retained, #3628
mean.ITime = seq.ITime = c.ITime = function(x, ...) as.ITime(NextMethod())
mean.ITime = function(x, ...) {
x = unclass(x)
as.ITime(NextMethod())
}
c.ITime = seq.ITime = function(...) as.ITime(NextMethod())


# create a data.table with IDate and ITime columns
Expand Down
1 change: 1 addition & 0 deletions inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -15090,6 +15090,7 @@ test(2054, DT[order(C)[1:5], B, verbose=TRUE], c('b', 'b', 'c', 'c', 'a'),
test(2055.1, seq(from = as.ITime('00:00:00'), to = as.ITime('00:00:05'), by = 5L), as.ITime(c(0, 5L)))
test(2055.2, c(as.ITime(0L), as.ITime(1L)), as.ITime(c(0L, 1L)))
test(2055.3, mean(as.ITime(c(0L, 0L))), as.ITime(0L))
test(2055.4, mean(as.IDate(c(0L, 0L))), as.IDate(0L))

# as.data.table.array some of dimnames are NULL, #3636
a = array(1:8, dim=c(2L,2L,2L), dimnames=list(NULL, NULL, as.character(1:2)))
Expand Down
Loading