Unable to return gmtoff from as.POSIXlt without converting date string to as.POSIXct first

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Unable to return gmtoff from as.POSIXlt without converting date string to as.POSIXct first

Sam Albers
Is it possible for someone to explain what is going on here? I would expect
that `as.POSIXlt` would be able to accept `datestring` and return all the
elements without having to convert it using `as.POSIXct` first. Do
`as.POSIXlt` and `as.POSIXct` do different things with the `tz` arg?

datestring <- "2017-01-01 12:00:00"
foo <- as.POSIXlt(datestring, tz = "America/Moncton")
foo
[1] "2017-01-01 12:00:00 AST"
foo$gmtoff
[1] NA

bar <- as.POSIXlt(as.POSIXct(datestring, tz = "America/Moncton"))
bar
[1] "2017-01-01 12:00:00 AST"
bar$gmtoff
[1] -14400

Thanks in advance,

Sam

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Unable to return gmtoff from as.POSIXlt without converting date string to as.POSIXct first

Jeff Newmiller
Read

?DateTimeClasses

regarding gmtoff. In short, it is implementation-dependent.

On June 28, 2018 10:58:13 AM PDT, Sam Albers <[hidden email]> wrote:

>Is it possible for someone to explain what is going on here? I would
>expect
>that `as.POSIXlt` would be able to accept `datestring` and return all
>the
>elements without having to convert it using `as.POSIXct` first. Do
>`as.POSIXlt` and `as.POSIXct` do different things with the `tz` arg?
>
>datestring <- "2017-01-01 12:00:00"
>foo <- as.POSIXlt(datestring, tz = "America/Moncton")
>foo
>[1] "2017-01-01 12:00:00 AST"
>foo$gmtoff
>[1] NA
>
>bar <- as.POSIXlt(as.POSIXct(datestring, tz = "America/Moncton"))
>bar
>[1] "2017-01-01 12:00:00 AST"
>bar$gmtoff
>[1] -14400
>
>Thanks in advance,
>
>Sam
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>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.

--
Sent from my phone. Please excuse my brevity.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.