Martin Maechler
on Fri, 23 Sep 2022 11:04:12 +0200 writes:
Kurt Hornik
on Fri, 23 Sep 2022 09:57:49 +0200 writes:
> function (x, ...)
> {
> if (any((y <- unclass(x)) > .Machine$integer.max, na.rm = TRUE))
> as.POSIXlt(.POSIXct(y * 86400), tz = "UTC")
> else .Internal(Date2POSIXlt(x))
> }
> function (x, ...)
> .POSIXct(unclass(x) * 86400)
> Adding tz to the latter is easy, and the former could do the if() part
> also with a given tz without needing to change the .Internal?
Genau! Even more elegantly than I first thought when I wrote
"post-processing":
The following even adds internal consistency inside as.POSIXlt.Date() :
as.POSIXlt.Date <- function(x, tz = "UTC", ...) {
as.POSIXlt(if(any((y <- unclass(x)) > .Machine$integer.max, na.rm = TRUE))
.POSIXct(y * 86400)
else
.Internal(Date2POSIXlt(x))
, tz = tz)
}
because now, tz is even *formally* treated the same in both
cases (whereas previously it only appeared visually in one case).
So probably, another reason to go there.
Note that I also think we'd keep the tz = "UTZ"
default argument, even when the
other as.POSIX[cl]t() methods have 'tz = ""'