Errors and OS Differences with as.POSIXct and as.POSIXlt

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

Errors and OS Differences with as.POSIXct and as.POSIXlt

Bill Denney-2
Hello,



Dates created with as.POSIXct differ between Windows/Mac and Linux.
Specifically this time that is during a gap when the hour does not exist
due to daylight savings time:



as.POSIXct("2018-03-11 02:09:36", tz="America/New_York")



Gives on Windows:

[1] "2018-03-11 EST"

Gives on Linux (Ubuntu 20.04):

[1] "2018-03-11 01:09:36 EST"



Since the time does not exist, and I think that NA should be returned.



Another issue and difference is that with as.POSIXlt on Linux, the invalid
time is presented:



as.POSIXlt("2018-03-11 02:09", tz="America/New_York")



Gives on Windows:

[1] "2018-03-11 EST"

Gives on Linux:

[1] "2018-03-11 02:09:00 EDT"



(Note that the time provided on Linux does not exist due to daylight
savings time.)



I think that for any invalid time, the result should be the same as an
invalid date:  NA is returned.



What is the intended, appropriate time, and what is the best way to fix
this?



Thanks,



Bill

        [[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: Errors and OS Differences with as.POSIXct and as.POSIXlt

Jeff Newmiller
This is as described in the documentation, due to OS differences, e.g
 [1].

[1] https://stat.ethz.ch/R-manual/R-devel/library/base/html/strptime.html

On January 18, 2021 5:56:11 PM PST, Bill Denney <[hidden email]> wrote:

>Hello,
>
>
>
>Dates created with as.POSIXct differ between Windows/Mac and Linux.
>Specifically this time that is during a gap when the hour does not
>exist
>due to daylight savings time:
>
>
>
>as.POSIXct("2018-03-11 02:09:36", tz="America/New_York")
>
>
>
>Gives on Windows:
>
>[1] "2018-03-11 EST"
>
>Gives on Linux (Ubuntu 20.04):
>
>[1] "2018-03-11 01:09:36 EST"
>
>
>
>Since the time does not exist, and I think that NA should be returned.
>
>
>
>Another issue and difference is that with as.POSIXlt on Linux, the
>invalid
>time is presented:
>
>
>
>as.POSIXlt("2018-03-11 02:09", tz="America/New_York")
>
>
>
>Gives on Windows:
>
>[1] "2018-03-11 EST"
>
>Gives on Linux:
>
>[1] "2018-03-11 02:09:00 EDT"
>
>
>
>(Note that the time provided on Linux does not exist due to daylight
>savings time.)
>
>
>
>I think that for any invalid time, the result should be the same as an
>invalid date:  NA is returned.
>
>
>
>What is the intended, appropriate time, and what is the best way to fix
>this?
>
>
>
>Thanks,
>
>
>
>Bill
>
> [[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.
Reply | Threaded
Open this post in threaded view
|

Re: Errors and OS Differences with as.POSIXct and as.POSIXlt

Rui Barradas
In reply to this post by Bill Denney-2
Hello,

R 4.0.3 on Ubuntu 20.04, sessionInfo() below.

A fix is to use as.POSIXct instead:

rui@rui:~$ Rscript --vanilla -e 'as.POSIXlt("2018-03-11 02:09",
tz="America/New_York")'
#[1] "2018-03-11 02:09:00 EDT"
rui@rui:~$ Rscript --vanilla -e 'as.POSIXct("2018-03-11 02:09",
tz="America/New_York")'
#[1] "2018-03-11 01:09:00 EST"


rui@rui:~$ Rscript --vanilla -e 'sessionInfo()'
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.1 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0

locale:
  [1] LC_CTYPE=pt_PT.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=pt_PT.UTF-8        LC_COLLATE=pt_PT.UTF-8
  [5] LC_MONETARY=pt_PT.UTF-8    LC_MESSAGES=pt_PT.UTF-8
  [7] LC_PAPER=pt_PT.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=pt_PT.UTF-8 LC_IDENTIFICATION=C

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

loaded via a namespace (and not attached):
[1] compiler_4.0.3


Hope this helps,

Rui Barradas
Às 01:56 de 19/01/21, Bill Denney escreveu:

> Hello,
>
>
>
> Dates created with as.POSIXct differ between Windows/Mac and Linux.
> Specifically this time that is during a gap when the hour does not exist
> due to daylight savings time:
>
>
>
> as.POSIXct("2018-03-11 02:09:36", tz="America/New_York")
>
>
>
> Gives on Windows:
>
> [1] "2018-03-11 EST"
>
> Gives on Linux (Ubuntu 20.04):
>
> [1] "2018-03-11 01:09:36 EST"
>
>
>
> Since the time does not exist, and I think that NA should be returned.
>
>
>
> Another issue and difference is that with as.POSIXlt on Linux, the invalid
> time is presented:
>
>
>
> as.POSIXlt("2018-03-11 02:09", tz="America/New_York")
>
>
>
> Gives on Windows:
>
> [1] "2018-03-11 EST"
>
> Gives on Linux:
>
> [1] "2018-03-11 02:09:00 EDT"
>
>
>
> (Note that the time provided on Linux does not exist due to daylight
> savings time.)
>
>
>
> I think that for any invalid time, the result should be the same as an
> invalid date:  NA is returned.
>
>
>
> What is the intended, appropriate time, and what is the best way to fix
> this?
>
>
>
> Thanks,
>
>
>
> Bill
>
> [[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.
>

______________________________________________
[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: Errors and OS Differences with as.POSIXct and as.POSIXlt

Bill Denney-2
In reply to this post by Jeff Newmiller
There are many caveats about OS specificity on the strptime help page, but
most of them have to do with formatting and fewer with validation.  My
reading of the strptime page indicates that conversion with as.POSIXct()
will validate daylight savings times which the examples I gave indicate it
is not validating.

as.POSIXct on windows gives the expected value based on the help (the date
part is valid, so it exists, but the time part is invalid, so it does not
exist).  On Linux, it makes an inaccurate conversion (as shown in my
original message and in Rui's).

If the results from as.POSIXct do not guarantee valid time conversion, only
approximate conversion, then that should be made clearer in the help page.
If valid time conversion is intended as a guarantee from as.POSIXct and
as.POSIXlt, then this is a bug.

From strptime help:

Remember that in most time zones some times do not occur and some occur
twice because of transitions to/from ‘daylight saving’ (also known as
‘summer’) time. strptime does not validate such times (it does not assume a
specific time zone), but conversion by as.POSIXct
<https://stat.ethz.ch/R-manual/R-devel/library/base/help/as.POSIXct.html> will
do so.

On Tue, Jan 19, 2021, 3:57 AM Jeff Newmiller <[hidden email]>
wrote:

> This is as described in the documentation, due to OS differences, e.g
>  [1].
>
> [1] https://stat.ethz.ch/R-manual/R-devel/library/base/html/strptime.html
>
> On January 18, 2021 5:56:11 PM PST, Bill Denney <
> [hidden email]> wrote:
> >Hello,
> >
> >
> >
> >Dates created with as.POSIXct differ between Windows/Mac and Linux.
> >Specifically this time that is during a gap when the hour does not
> >exist
> >due to daylight savings time:
> >
> >
> >
> >as.POSIXct("2018-03-11 02:09:36", tz="America/New_York")
> >
> >
> >
> >Gives on Windows:
> >
> >[1] "2018-03-11 EST"
> >
> >Gives on Linux (Ubuntu 20.04):
> >
> >[1] "2018-03-11 01:09:36 EST"
> >
> >
> >
> >Since the time does not exist, and I think that NA should be returned.
> >
> >
> >
> >Another issue and difference is that with as.POSIXlt on Linux, the
> >invalid
> >time is presented:
> >
> >
> >
> >as.POSIXlt("2018-03-11 02:09", tz="America/New_York")
> >
> >
> >
> >Gives on Windows:
> >
> >[1] "2018-03-11 EST"
> >
> >Gives on Linux:
> >
> >[1] "2018-03-11 02:09:00 EDT"
> >
> >
> >
> >(Note that the time provided on Linux does not exist due to daylight
> >savings time.)
> >
> >
> >
> >I think that for any invalid time, the result should be the same as an
> >invalid date:  NA is returned.
> >
> >
> >
> >What is the intended, appropriate time, and what is the best way to fix
> >this?
> >
> >
> >
> >Thanks,
> >
> >
> >
> >Bill
> >
> >       [[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.
>

        [[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.