[Rd] Date method of as.POSIXct does not respect tz
Martin Maechler
m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Sat Sep 24 22:07:53 CEST 2022
>>>>> Martin Maechler
>>>>> on Fri, 23 Sep 2022 11:04:12 +0200 writes:
>>>>> Kurt Hornik
>>>>> on Fri, 23 Sep 2022 09:57:49 +0200 writes:
>>>>> Martin Maechler writes:
> > Currently in R-devel,
>
> R> as.POSIXlt.Date
> > function (x, ...)
> > {
> > if (any((y <- unclass(x)) > .Machine$integer.max, na.rm = TRUE))
> > as.POSIXlt(.POSIXct(y * 86400), tz = "UTC")
> > else .Internal(Date2POSIXlt(x))
> > }
>
> R> as.POSIXct.Date
> > 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 = ""'
Hmm, good plan, but not working for the (more important) second
branch:
as.POSIXlt(<POSIXlt>, tz = "..")
immediately returns the first argument without ever looking if
there are further arguments, in this case 'tz'..
--> we would also have to slightly change as.POSIXlt.default(x)
such that it obeyed a 'tz = ".."' in the case of x being
"POSIXlt".
Almost surely this will break some code which had relied on the
current -- a bit surpristing to me -- behavior.
Well,... I think we *should* want the above {setting a "tz"} for
POSIXlt to work.
Martin
More information about the R-devel
mailing list