Bug 14358 - format(posix, "... %Z") gives wrong timezone
format(posix, "... %Z") gives wrong timezone
Product: R
Classification: Unclassified
Component: Misc
R 2.11.1
ix86 (32-bit) Mac OS X v10.6
: P3 normal
Assigned To: R-core
Depends on:
  Show dependency treegraph
Reported: 2010-08-13 13:21 UTC by Dan Kelley
Modified: 2010-09-18 12:48 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Dan Kelley 2010-08-13 13:21:22 UTC
The %Z component of the format for a POSIXct item is yielding the local timezone, not the timezone of the item.  (However, %z correctly reports the offset)

> july.first <- as.POSIXct("2010-07-01", tz="UTC")

> july.first
[1] "2010-07-01 UTC"

> format(july.first, "%Y-%m-%d %H:%M:%S %Z")
[1] "2010-07-01 00:00:00 AST"

> format(july.first, "%Y-%m-%d %H:%M:%S %z")
[1] "2010-07-01 00:00:00 -0400"

> attr(july.first, "tzone")
[1] "UTC"

> sessionInfo()
R version 2.11.1 (2010-05-31) 

[1] en_CA.UTF-8/en_CA.UTF-8/C/C/en_CA.UTF-8/en_CA.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] oce_0.1-81

loaded via a namespace (and not attached):
[1] tools_2.11.1
Comment 1 Brian Ripley 2010-08-17 14:30:42 UTC
Well, 'wrong' only if you expect it to make use of the "tzone" attribute,
which was not the intention (and this long predates such attributes).

Note too that the offset in UTC is by definition +0000, so you seem to
have expected the name but not the offset to be in the marked timezone.

Where possible 2.12.0 will make use of the "tzone" attribute, but it
isn't always possible -- to find the offset we need the name of the timezone
in the Olson database.
Comment 2 Dan Kelley 2010-09-18 12:48:40 UTC
I realize that my message was unclear.  I just tried this with

    R version 2.12.0 alpha (2010-09-17 r52943)

and got as follows.  This behaviour is more in line with what users might expect.

    > july.first <- as.POSIXct("2010-07-01", tz="UTC")

    > july.first
    [1] "2010-07-01 UTC"

    > format(july.first, "%Y-%m-%d %H:%M:%S %Z")
    [1] "2010-07-01 00:00:00 UTC"

    > format(july.first, "%Y-%m-%d %H:%M:%S %z")
    [1] "2010-07-01 00:00:00 +0000"