Protection against accidental change of time zone

In R, I have a bunch of datetime values ​​that I measure in GMT. I continue to encounter accidents when some function loses the time zone by my values ​​or even loses the class name. Even with such basic functions as c()and unlist():

> dput(x)
structure(1317830532, class = c("POSIXct", "POSIXt"), tzone = "GMT")
> dput(c(x))
structure(1317830532, class = c("POSIXct", "POSIXt"))
> dput(list(x))
list(structure(1317830532, class = c("POSIXct", "POSIXt"), tzone = "GMT"))
> dput(unlist(list(x)))
1317830532

I feel like I have the hair width from the real moment of Mars Climate Orbiter , if that happens when I least expect it. Does anyone have strategies to ensure that their dates "stay in place"?

+5
source share
3 answers

GMT R, ? - "" , - .

+3

?c, ?DateTimeClasses ?unlist:

?DateTimeClasses:

c "POSIXlt" , "POSIXct" "tzone" ( ). *

?c:

c , . *


, , , c unlist. :

x <- structure(1317830532, class = c("POSIXct", "POSIXt"), 
                 tzone = "GMT")
y <- structure(1317830532+3600, class = c("POSIXct", "POSIXt"), 
                 tzone = "PST8PDT")
x
[1] "2011-10-05 16:02:12 GMT"

y
[1] "2011-10-05 10:02:12 PDT"

strftime(c(x, y), format="%Y/%m/%d %H:%M:%S", tz="GMT")
[1] "2011/10/05 16:02:12" "2011/10/05 17:02:12"

strftime(c(x, y), format="%Y/%m/%d %H:%M:%S", tz="PST8PDT")
[1] "2011/10/05 09:02:12" "2011/10/05 10:02:12"

strftime(unlist(y), format="%Y/%m/%d %H:%M:%S", tz="PST8PDT")
[1] "2011/10/05 10:02:12"

Rover , R .

+5

, , , , . " "; lint, . , , , :

  • . -, , , , , , , -, , . , , .
  • . , (, ), script GNU find grep - (, grep R), , . , (, # 1).
  • . , . Runit testthat, , . , , , , .
  • . , , . , , . , , , , (, , , ).
  • , TZ Indiana-be-damned. - , , . TZ (UTC), - . , DST, UTC.

# 1-4 , , , , Mars Orbiter. , . ( , .:))

+2
source

All Articles