From m@ech|er @end|ng |rom @t@t@m@th@ethz@ch  Fri Oct  2 09:37:16 2020
From: m@ech|er @end|ng |rom @t@t@m@th@ethz@ch (Martin Maechler)
Date: Fri, 2 Oct 2020 09:37:16 +0200
Subject: [Rd] timezone tests and R-devel
In-Reply-To: <CAC2h7utR775fMZfFv50Zg9SC8fpoZq=sWcQyOEZKOhJnupabUA@mail.gmail.com>
References: <CAC2h7utR775fMZfFv50Zg9SC8fpoZq=sWcQyOEZKOhJnupabUA@mail.gmail.com>
Message-ID: <24438.55468.345544.482717@stat.math.ethz.ch>

>>>>> Kasper Daniel Hansen 
>>>>>     on Thu, 1 Oct 2020 20:31:12 +0200 writes:

    > The return value of Sys.time() today with a timezone of US/Eastern is
    > unchanged between 4.0.3-patched and devel, but on devel the following test
    > fails
    > all.equal(x, as.POSIXlt(x))
    > with
    > x = Sys.time()

    > This means that devel does not complete make tests (failure on
    > tests/reg-tests-2.R)

    > It is entirely possible that it is an error on my end, I use
    > export TZ="US/Eastern"
    > but I have been using this for a while, and R-4.0.3-patched built today
    > passes make tests.

    > Details below, and I am happy to provide more information.

    > Build platform: inside a conda environment on linux. I have been doing this
    > for a while, but it is certainly a non-standard setup. GCC 7.3

    > Best,
    > Kasper

    > On R version 4.0.3 beta (2020-10-01 r79286) I get

    >> x = Sys.time()
    >> attributes(x)
    > $class
    > [1] "POSIXct" "POSIXt"

    >> attributes(as.POSIXlt(x))
    > $names
    > [1] "sec"    "min"    "hour"   "mday"   "mon"    "year"   "wday"   "yday"
    > [9] "isdst"  "zone"   "gmtoff"

    > $class
    > [1] "POSIXlt" "POSIXt"

    > $tzone
    > [1] "US/Eastern" "EST"        "EDT"

    >> all.equal(x, as.POSIXlt(x))
    > [1] TRUE

    > On R Under development (unstable) (2020-10-01 r79286) I get
    >> x = Sys.time()
    >> all.equal(x,x)
    > [1] TRUE
    >> attributes(as.POSIXlt(x))
    > $names
    > [1] "sec"    "min"    "hour"   "mday"   "mon"    "year"   "wday"   "yday"
    > [9] "isdst"  "zone"   "gmtoff"

    > $class
    > [1] "POSIXlt" "POSIXt"

    > $tzone
    > [1] "US/Eastern" "EST"        "EDT"

    >> all.equal(x, as.POSIXlt(x))
    > [1] "'tzone' attributes are inconsistent ('' and 'US/Eastern')"

Yes, this is a new feature, actually a __bug fix__ in R-devel,
see NEWS :

    ? all.equal.POSIXt() no longer warns about and subsequently ignores
      inconsistent "tzone" attributes, but describes the difference in
      its return value (PR#17277).  This check can be disabled _via_
      the new argument check.tzone = FALSE; as suggested by Sebastian
      Meyer.

Here's pure R code for reproducing what you've seen :

x <- structure(1601623657, class = c("POSIXct", "POSIXt"))

Sys.unsetenv("TZ")
all.equal(x, ltx <- as.POSIXlt(x))  # TRUE
attr(ltx, "tzone")  # [1]  "" "CET"  "CEST"

Sys.setenv(TZ = "US/Eastern")
all.equal(x, ltx <- as.POSIXlt(x))
## "'tzone' attributes are inconsistent ('' and 'US/Eastern')"
all.equal(x, ltx, check.tzone = FALSE) # TRUE

Sys.unsetenv("TZ")
all.equal(x, ltx <- as.POSIXlt(x)) # TRUE



[Rd] timezone tests and R-devel
Martin Maechler