Skip to content

Commit 87ae359

Browse files
author
maechler
committed
YA tweak at "balanced" in [[.POSIXlt
git-svn-id: https://svn.r-project.org/R/trunk@88450 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent d3d2dd2 commit 87ae359

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

doc/NEWS.Rd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
\subsection{SIGNIFICANT USER-VISIBLE CHANGES}{
1010
\itemize{
1111
\item The R citation now provides a \abbr{DOI}
12-
(\I{10.32614/R.manuals}): please update your
12+
(\I{10.32614/R.manuals}): please update your
1313
bibliographies accordingly.
1414
}
1515
}
@@ -247,6 +247,9 @@
247247
\item Subassigning \code{"POSIXlt"}, i.e., \code{<tdat>[i] <- val}
248248
and \code{<tdat>[[i]] <- val} now rebalance as they should,
249249
thanks to \I{Mikael Jagan}'s \PR{18919}.
250+
251+
\item \code{<POSIXlt>[*]} (re-)setting \code{"balanced"}, fixing
252+
\PR{18681} comment #7, thanks to \I{Mikael Jagan}.
250253
}
251254
}
252255
}

src/library/base/R/datetime.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,8 +1547,9 @@ OlsonNames <- function(tzdir = NULL)
15471547
domain = NA)
15481548
i <- idx
15491549
}
1550-
.POSIXlt(lapply(unCfillPOSIXlt(x), `[[`, i, drop = drop),
1551-
attr(x, "tzone"), oldClass(x))
1550+
`attr<-`(.POSIXlt(lapply(unCfillPOSIXlt(x), `[[`, i, drop = drop),
1551+
attr(x, "tzone"), oldClass(x)),
1552+
"balanced", if(isTRUE(attr(x, "balanced"))) TRUE else NA)
15521553
}
15531554

15541555
as.list.POSIXlt <- function(x, ...)

tests/datetime3.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,16 @@ if(!tz %in% OlsonNames()) {
775775
stopifnot(identical(x1, x), identical(x2, x))
776776
})
777777
## x1, x2 were identical but differing from x
778+
n <- 4L # >= 3 for NA-filling in subassignment
779+
z1 <- z2 <- `attr<-`(z <- as.POSIXlt(.POSIXct(double(n), "UTC")),
780+
"balanced", NULL)
781+
z1$year <- z2$year <- z$year[1L] # "un"balance
782+
z1[n] <- z2[[n]] <- z[[1L]] # check `[<-` and `[[<-`
783+
stopifnot(z2[,"year"] == 70) # was (70 NA NA 70) previously
784+
identicalPlt <- function(x, y, ...)
785+
identical(balancePOSIXlt(x), balancePOSIXlt(y), ...)
786+
stopifnot(identicalPlt(z1, z), identicalPlt(z2, z))
787+
## failed previously, incl in rev 88441
778788

779789

780790

0 commit comments

Comments
 (0)