Skip to content

Commit 4789cdf

Browse files
author
Bill Evans
committed
fix #6898, disable checking timezone in between()
1 parent c941399 commit 4789cdf

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
3. `print.data.table()` now shows column classes at the bottom of large tables when `class=TRUE` and `col.names="auto"` (default) for tables with more than 20 rows, [#6902](https://github.com/Rdatatable/data.table/issues/6902). This follows the same behavior as column names at the bottom, making it easier to see column types for large tables without scrolling back to the top. Thanks to @TimTaylor for the suggestion and @Mukulyadav2004 for the PR.
1212

13+
4. `between()` gains the argument `ignore_tzone=FALSE`. Normally, a difference in time zone between `lower` and `upper` will produce an error, and a difference in time zone between `x` and either of the others will produce a message. Setting `ignore_tzone=TRUE` bypasses the checks, allowing both comparisons to proceed without error or message about time zones.
14+
1315
## BUG FIXES
1416

1517
1. Custom binary operators from the `lubridate` package now work with objects of class `IDate` as with a `Date` subclass, [#6839](https://github.com/Rdatatable/data.table/issues/6839). Thanks @emallickhossain for the report and @aitap for the fix.

R/between.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# is x[i] in between lower[i] and upper[i] ?
2-
between = function(x, lower, upper, incbounds=TRUE, NAbounds=TRUE, check=FALSE) {
2+
between = function(x, lower, upper, incbounds=TRUE, NAbounds=TRUE, check=FALSE, ignore_tzone=FALSE) {
33
if (is.logical(x)) stopf("between has been passed an argument x of type logical")
44
if (is.logical(lower)) lower = as.integer(lower) # typically NA (which is logical type)
55
if (is.logical(upper)) upper = as.integer(upper) # typically NA (which is logical type)
@@ -16,7 +16,7 @@ between = function(x, lower, upper, incbounds=TRUE, NAbounds=TRUE, check=FALSE)
1616
stopifnot(is.px(x), is.px(lower), is.px(upper)) # nocov # internal
1717
}
1818
# POSIX check timezone match
19-
if (is.px(x) && is.px(lower) && is.px(upper)) {
19+
if (!ignore_tzone && is.px(x) && is.px(lower) && is.px(upper)) {
2020
tzs = sapply(list(x,lower,upper), function(x) {
2121
attr(x, "tzone", exact=TRUE) %||% ""
2222
})

inst/tests/tests.Rraw

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21141,3 +21141,13 @@ dt = data.table(id = 1:25)
2114121141
test(2314.1, any(grepl("<int>", tail(capture.output(print(dt, class = TRUE)), 2))), TRUE)
2114221142
# Test that class=TRUE with col.names="top" doesn't show classes at bottom
2114321143
test(2314.2, !any(grepl("<int>", tail(capture.output(print(dt, class = TRUE, col.names = "top")), 2))), TRUE)
21144+
21145+
# Test that tzone behavior stops warning with ignore_tzone=TRUE
21146+
tm1 = .POSIXct(1, "UTC")
21147+
dt1 = data.table(a = .POSIXct(0), b = .POSIXct(2, "UTC"))
21148+
test(2315.1, dt1[, between(tm1, a, b)], error = "different tzone attributes")
21149+
test(2315.2, dt1[, between(tm1, a, b, ignore_tzone=TRUE)])
21150+
tm2 <- .POSIXct(1)
21151+
dt2 = data.table(a = .POSIXct(0, "UTC"), b = .POSIXct(2, "UTC"))
21152+
test(2315.3, dt2[, between(tm2, a, b)], message = "mismatched tzone attributes")
21153+
test(2315.4, dt2[, between(tm2, a, b)])

man/between.Rd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ interpreted as \code{lower} and \code{y[[2]]} as \code{upper}.}
3535
It is set to \code{TRUE} by default for infix notations.}
3636
\item{NAbounds}{ If \code{lower} (\code{upper}) contains an \code{NA} what should \code{lower<=x} (\code{x<=upper}) return? By default \code{TRUE} so that a missing bound is interpreted as unlimited. }
3737
\item{check}{ Produce error if \code{any(lower>upper)}? \code{FALSE} by default for efficiency, in particular type \code{character}. }
38+
\item{ignore_tzone}{ \code{TRUE} means skip timezone checks among
39+
\code{x}, \code{lower}, and \code{upper}. }
3840
}
3941
\details{
4042

0 commit comments

Comments
 (0)