CHeers
Joris
On Thu, May 18, 2017 at 1:45 PM, Joris Meys <jorismeys at gmail.com> wrote:
This has to do with your own timezone. If I run that code on my computer, both formats are correct. If I do this after
Sys.setenv(TZ = "UTC")
Then:
cbind(format(dlt), format(dct))
[,1] [,2]
[1,] "2016-12-06 21:45:41" "2016-12-06 20:45:41"
[2,] "2016-12-06 21:45:42" "2016-12-06 20:45:42"
The reason for that, is that dlt has a timezone set, but dct doesn't. To be correct, it only takes the first value "", which indicates "Use the default timezone of the locale".
[1] ""
The thing is, in POSIXlt the timezone attribute is stored together with the actual values for hour, minute etc. in list format. Changing the timezone doesn't change those values, but it will change the time itself:
Sys.unsetenv("TZ")
dlt2 <- dlt
attr(dlt2,"tzone") <- "UTC"
dlt2
[1] "2016-12-06 21:45:41 UTC" "2016-12-06 21:45:42 UTC"
[3] "2016-12-06 21:45:43 UTC" "2016-12-06 21:45:44 UTC"
in POSIXct the value doesn't change either, just the attribute. But this value is the number of seconds since the origin. So the time itself doesn't change, but you'll see a different hour.
[1] "2016-12-06 21:45:41 CET" "2016-12-06 21:45:42 CET"
...
attr(dct,"tzone") <- "UTC"
dct
[1] "2016-12-06 20:45:41 UTC" "2016-12-06 20:45:42 UTC"
[3] "2016-12-06 20:45:43 UTC" "2016-12-06 20:45:44 UTC"
So what you see, is simply the result of your timezone settings on your computer.
Cheers
Joris
On Thu, May 18, 2017 at 1:19 PM, peter dalgaard <pdalgd at gmail.com> wrote:
On 18 May 2017, at 11:00 , Patrick Connolly <p_connolly at slingshot.co.nz> wrote:
On Wed, 17-May-2017 at 01:21PM +0200, Peter Dalgaard wrote:
|>
|> Anyways, you might want to
|>
|> a) move the discussion to R-devel
|> b) include your platform (hardware, OS) and time zone info
System: Host: MTA-V1-427894 Kernel: 3.19.0-32-generic x86_64 (64 bit gcc: 4.8.2)
Desktop: KDE Plasma 4.14.2 (Qt 4.8.6) Distro: Linux Mint 17.3 Rosa
|> c) run the offending code lines "by hand" and show us the values of format(dlt) and format(dct) so we can see what the problem is, something like
|>
|> dlt <- structure(
|> list(sec = 52, min = 59L, hour = 18L, mday = 6L, mon = 11L, year = 116L,
|> wday = 2L, yday = 340L, isdst = 0L, zone = "CET", gmtoff = 3600L),
|> class = c("POSIXlt", "POSIXt"), tzone = c("", "CET", "CEST"))
|> dlt$sec <- 10000 + 1:10
|> dct <- as.POSIXct(dlt)
|> cbind(format(dlt), format(dct))
cbind(format(dlt), format(dct))
[,1] [,2]
[1,] "2016-12-06 21:45:41" "2016-12-06 22:45:41"
[2,] "2016-12-06 21:45:42" "2016-12-06 22:45:42"
[3,] "2016-12-06 21:45:43" "2016-12-06 22:45:43"
[4,] "2016-12-06 21:45:44" "2016-12-06 22:45:44"
[5,] "2016-12-06 21:45:45" "2016-12-06 22:45:45"
[6,] "2016-12-06 21:45:46" "2016-12-06 22:45:46"
[7,] "2016-12-06 21:45:47" "2016-12-06 22:45:47"
[8,] "2016-12-06 21:45:48" "2016-12-06 22:45:48"
[9,] "2016-12-06 21:45:49" "2016-12-06 22:45:49"
[10,] "2016-12-06 21:45:50" "2016-12-06 22:45:50"
So exactly 1 hour out of whack. Is there a Daylight Saving Times issue, perchance?
-pd
--
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
___ Patrick Connolly
{~._.~} Great minds discuss ideas
_( Y )_ Average minds discuss events
(:_~*~_:) Small minds discuss people
(_)-(_) ..... Eleanor Roosevelt
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
--
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com