Re: [R] DateTime Math in R - POSIXct

From: Jeff Newmiller <jdnewmil_at_dcn.davis.ca.us>
Date: Mon, 30 May 2011 23:42:43 -0700

MDT is not a valid timezone specification... it is falling back on your default timezone in your "working" case.

  1. learn what valid timezone specifications are on your operating system. I suspect you are using Windows (hint: we should not have to guess), so look for the timezone directory in your R installation directory. I would guess that you want "America/Denver". Note that MST and MST7MDT are also possibilities , but they are generally deprecated as being too imprecise in the global context (who is to say "MDT" doesn't mean "Mongolian Daylight Time").
  2. I strongly recommend using the "default" timezone or overriding it with Sys.setenv(TZ= your timezone spec) rather than using the tz arguments. The frustration factor is much lower.
  3. if you properly import all of your time values into POSIXct, their internal representations will always be referenced to UTC (GMT). It is only on input and output (such as printing to the console) or conversion to POSIXlt that the timezone is considered.
    Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil_at_dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
    Sent from my phone. Please excuse my brevity.

Galen Moore <galen.a.moore_at_gmail.com> wrote:

Thank you, David.

I am not subtracting the seconds to convert POSIXct's GMT to MDT, and don't understand why I should need to.

Any hints, however, as to why
dateP <- as.POSIXct(tstamp, origin="1970-01-01", tzone="MDT") returns a date in the correct tz in my first instance below, yet

dateP2 <- as.POSIXct(dateN, origin="1970-01-01", tzone="MDT") decides to revert to GMT in my second instance below?

Thanks,

Galen

-----Original Message-----
From: David Winsemius [mailto:dwinsemius_at_comcast.net] Sent: Monday, May 30, 2011 20:31
To: galen.a.moore_at_gmail.com
Cc: r-help_at_r-project.org
Subject: Re: [R] DateTime Math in R - POSIXct

On May 30, 2011, at 10:20 PM, Galen Moore wrote:

> Greetings -
>
>
>
> I'm battling POSIXct, as per the code below. My input is actually an
> XL file, but the weird results below correctly model what I am seeing
> in my program.

>
>
>
> Before I punt and use lubridate or timeDate, could anyone please help
> me understand why POSIXct forces my variable back to GMT?

>
>
>
> I suspect that I'm not properly coding the tzone value, but it does
> not throw an error as-is.
>
>
>
>
>
>> tstamp <- "2011-05-22 11:45:00 MDT"
>
>> mode(tstamp)
>
> [1] "character"
>
>>
>
>> dateP <- as.POSIXct(tstamp, origin="1970-01-01", tzone="MDT")
>
>> mode(dateP)
>
> [1] "numeric"
>
>> dateP
>
> [1] "2011-05-22 11:45:00 MDT"
>
>>
>
>> dateN <- as.numeric(dateP)
>
>> dateN
>
> [1] 1306086300
>

So now the internal representation is referenced to GMT

>>
>
>> dateP2 <- as.POSIXct(dateN, origin="1970-01-01", tzone="MDT")
>
>> dateP2

And you are telling the function to add as many hours offset as needed for the difference between GMT and MD T.....

--
David.

>
> [1] "2011-05-22 18:45:00 MDT"
>
David Winsemius, MD West Hartford, CT _____________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] ______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Received on Tue 31 May 2011 - 07:32:19 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 31 May 2011 - 13:30:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive