Skip to content
Prev 387905 / 398502 Next

Date Time, as.POSIXct used locale, strange plot behavior

On Fri, 30 Apr 2021, Tilmann Faul writes:
Timezone names in general are not portable (i.e. not
safe to use).  You may always specify a timezone name,
but it may be ignored:

    as.POSIXct("2021-04-21 00:00:00", tz = "PartyTime")
    ## "2021-04-21 PartyTime"

So just because your system prints "CEST", it does not
mean it has recognised it as a timezone. (To make it
even more complicated: your system may display a time
as "CEST", meaning a time in Central European Summer
Time, but still not accept "CEST" as _input_ for a
timezone name.)

'POSIXct' represents time as a number (seconds since
1970). To compare the results of different calls, it is
easier to compare those numbers.

    dput(as.POSIXct("2021-04-21 00:00:00", tz="CEST"))
    ## structure(1618963200, class = c("POSIXct", "POSIXt"), tzone = "CEST")
    dput(as.POSIXct("2021-04-21 00:00:00", tz="PartyTime"))
    ## structure(1618963200, class = c("POSIXct", "POSIXt"), tzone = "PartyTime")

    dput(as.POSIXct("2021-04-21 00:00:00", tz="Europe/Berlin"))
    ## structure(1618956000, class = c("POSIXct", "POSIXt"), tzone = "Europe/Berlin")
    dput(as.POSIXct("2021-04-21 00:00:00"))
    ## structure(1618956000, class = c("POSIXct", "POSIXt"), tzone = "")

So in your case, "CEST" is (most likely) not recognised
as a valid input for a timezone name, and hence it is
ignored, but still displayed.

HTH
    Enrico

  
    
Message-ID: <87y2d0t9lo.fsf@enricoschumann.net>
In-Reply-To: <2dff15c0-ed56-e80d-20df-15912e33220d@t-online.de> (Tilmann Faul's message of "Fri, 30 Apr 2021 09:50:50 +0200")