Skip to content

Commit

Permalink
amend c84679; min(.)/max(.) accidentally used finite=FALSE, i.e., 0
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@84693 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
maechler committed Jul 15, 2023
1 parent e337066 commit e7cdc5d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
4 changes: 3 additions & 1 deletion src/library/base/R/datetime.R
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,9 @@ Summary.POSIXlt <- function (..., na.rm, finite = FALSE)
args <- list(...)
tz <- do.call(.check_tzones, args)
args <- lapply(args, as.POSIXct)
val <- do.call(.Generic, c(args, na.rm = na.rm, finite = finite))
val <- switch(.Generic,
max = , min = do.call(.Generic, c(args, na.rm = na.rm)), # not (yet?) finite
range = do.call(range, c(args, na.rm = na.rm, finite = finite)))
as.POSIXlt(.POSIXct(val, tz))
}

Expand Down
14 changes: 8 additions & 6 deletions tests/datetime3.R
Original file line number Diff line number Diff line change
Expand Up @@ -529,18 +529,19 @@ stopifnot(exprs = {
stopifnot(b1 == b2)


## range(<Date>|<PoSIXt>, finite = TRUE) [R-devel mails, Davis Vaughan and MM, April 28, 2023ff]
d <- .Date(c(0, Inf, 1, 2, Inf))
## range(<Date>|<POSIXt>, finite = TRUE) [R-devel mails, Davis Vaughan and MM, April 28, 2023ff]
d <- .Date(c(10, Inf, 11, 12, Inf))
(dN <- c(d, .Date(c(NA, NaN))))
## Just the numbers :
str(x <- unclass(d))
str(xN <- unclass(dN), vec.len=9)
stopifnot(exprs = {
identical(print(range(d)), .Date(range(unclass(d))))# "1970-01-01" "Inf"
identical3(print(range(d)), .Date(range(unclass(d))),# "1970-01-11" "Inf"
c(min(d),max(d)))
is.na(range(dN))
identical3(range(d, finite = TRUE), .Date(range(x, finite=TRUE)),
range(dN,finite = TRUE) -> rd)
identical(rd, structure(c(0, 2), class = "Date"))
identical(rd, structure(c(10, 12), class = "Date"))
})
## POSIXct/lt -----
ct <- as.POSIXct(d)
Expand All @@ -555,10 +556,11 @@ stopifnot(exprs = {
range(ctN,finite = TRUE) -> rct)
is.na(range(ctN))
identical(range(ctN, na.rm=TRUE), range(ct))
identical(rct, structure(c(0, 2 * 24*60*60),
identical(rct, structure(c(10, 12) * 24*60*60,
class = c("POSIXct", "POSIXt"), tzone = "UTC"))
## POSIXlt
identical(print(range(lt)), as.POSIXlt(range(ct)))# "1970-01-01" "Inf"
identical3(print(range(lt)), as.POSIXlt(range(ct)), # "1970-01-11" "Inf"
c(min(lt), max(lt))) # failed for a few days
identical3(range(lt, finite = TRUE), as.POSIXlt(rct),
range(ltN,finite = TRUE))
is.na(range(ltN))
Expand Down

0 comments on commit e7cdc5d

Please sign in to comment.