Hi list, I'd like to submit the following problem that seems a bug but it is so strange that it could be my mind ... so I would like to sort a list of date time items like in this script: df = data.frame(DateTime = c( '2016-12-21 10:34:54', '2016-12-21 11:04:54', '2016-12-21 11:34:54', '2016-03-27 02:05:50', '2016-03-27 02:35:50', '2016-12-21 12:04:54', '2016-12-21 12:34:54' )) df$DateTime = as.POSIXlt(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S')) ord = order(as.numeric(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S'))) df.ord = df[ord,1] df.ord I have the following results: "2016-12-21 10:34:54 CET" "2016-12-21 11:04:54 CET" "2016-12-21 11:34:54 CET" "2016-12-21 12:04:54 CET" "2016-12-21 12:34:54 CET" "2016-03-27 02:05:50" "2016-03-27 02:35:50" the last two terms should be before (note that CET is missing). if I change "2016-03-27 02:05:50" and "2016-03-27 02:35:50" to something like "2016-03-27 01:05:50" and "2016-03-27 01:35:50" it seems to work. It seems to have problem with 02 hours. Any ideas? I'm using R-3.1.2 on Win Thank you rob
order list of date (bug?)
6 messages · rob vech, William Dunlap, Jeff Newmiller
1 day later
When did the switch between 'summer time'/'winter time' (or 'daylight savings'/'standard') happen in CET last year? (Did 2:35 exist on March 27, 2016?) At the R level, what is as.numeric(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S')) with your time zone settings? Bill Dunlap TIBCO Software wdunlap tibco.com
On Thu, Jan 19, 2017 at 11:18 AM, rob vech <rob.vech87 at gmail.com> wrote:
Hi list,
I'd like to submit the following problem that seems a bug but it is so
strange that it could be my mind ... so
I would like to sort a list of date time items like in this script:
df = data.frame(DateTime = c(
'2016-12-21 10:34:54',
'2016-12-21 11:04:54',
'2016-12-21 11:34:54',
'2016-03-27 02:05:50',
'2016-03-27 02:35:50',
'2016-12-21 12:04:54',
'2016-12-21 12:34:54'
))
df$DateTime = as.POSIXlt(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S'))
ord = order(as.numeric(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S')))
df.ord = df[ord,1]
df.ord
I have the following results:
"2016-12-21 10:34:54 CET"
"2016-12-21 11:04:54 CET"
"2016-12-21 11:34:54 CET"
"2016-12-21 12:04:54 CET"
"2016-12-21 12:34:54 CET"
"2016-03-27 02:05:50"
"2016-03-27 02:35:50"
the last two terms should be before (note that CET is missing).
if I change "2016-03-27 02:05:50" and "2016-03-27 02:35:50" to something
like "2016-03-27 01:05:50" and "2016-03-27 01:35:50"
it seems to work. It seems to have problem with 02 hours. Any ideas?
I'm using R-3.1.2 on Win
Thank you
rob
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
It does look like "2016-03-27 02:35:00 CET" is a non-existent time since the time sprang from 02:00-epsilon to 0:300 on that date. The POSIXlt entry for it is a missing value (per is.na()) and order() puts missing values at the end, hence your problem. It seems like a bug that POSIXlt entries with such invalid time print oddly instead printing an NA. is.na() says that they are missing/invalid values.
txt <- sprintf("2016-03-27 %02d:30:00", 1:4)
txt
[1] "2016-03-27 01:30:00" "2016-03-27 02:30:00" "2016-03-27 03:30:00" "2016-03-27 04:30:00"
tim <- strptime(txt, format="%Y-%m-%d %H:%M:%S", tz="CET") tim
[1] "2016-03-27 01:30:00 CET" "2016-03-27 02:30:00" "2016-03-27 03:30:00 CEST" "2016-03-27 04:30:00 CEST"
is.na(tim)
[1] FALSE TRUE FALSE FALSE
diff(tim)
Time differences in hours [1] NA NA 1
tim[3]-tim[1]
Time difference of 1 hours
as.numeric(tim)
[1] 1459038600 NA 1459042200 1459045800 Bill Dunlap TIBCO Software wdunlap tibco.com
On Fri, Jan 20, 2017 at 9:10 PM, William Dunlap <wdunlap at tibco.com> wrote:
When did the switch between 'summer time'/'winter time' (or 'daylight savings'/'standard') happen in CET last year? (Did 2:35 exist on March 27, 2016?) At the R level, what is as.numeric(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S')) with your time zone settings? Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jan 19, 2017 at 11:18 AM, rob vech <rob.vech87 at gmail.com> wrote:
Hi list,
I'd like to submit the following problem that seems a bug but it is so
strange that it could be my mind ... so
I would like to sort a list of date time items like in this script:
df = data.frame(DateTime = c(
'2016-12-21 10:34:54',
'2016-12-21 11:04:54',
'2016-12-21 11:34:54',
'2016-03-27 02:05:50',
'2016-03-27 02:35:50',
'2016-12-21 12:04:54',
'2016-12-21 12:34:54'
))
df$DateTime = as.POSIXlt(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S'))
ord = order(as.numeric(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S')))
df.ord = df[ord,1]
df.ord
I have the following results:
"2016-12-21 10:34:54 CET"
"2016-12-21 11:04:54 CET"
"2016-12-21 11:34:54 CET"
"2016-12-21 12:04:54 CET"
"2016-12-21 12:34:54 CET"
"2016-03-27 02:05:50"
"2016-03-27 02:35:50"
the last two terms should be before (note that CET is missing).
if I change "2016-03-27 02:05:50" and "2016-03-27 02:35:50" to something
like "2016-03-27 01:05:50" and "2016-03-27 01:35:50"
it seems to work. It seems to have problem with 02 hours. Any ideas?
I'm using R-3.1.2 on Win
Thank you
rob
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org 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.
5 days later
Hi William,
asking to the r-devel list I resolved the problem! It depends from the
timezone (tz param) that I didn't specified and so R automatically uses
my local time and considers also the daylight saving time (that comes at
2:00 at my position).
As my dates are in solar time, I specified the time zone as "GMT" and it
works!
Here a simple example:
df = data.frame(DateTime = c(
'2016-12-21 10:34:54',
'2016-12-21 11:04:54',
'2016-12-21 11:34:54',
'2016-03-27 02:05:50',
'2016-03-27 02:35:50',
'2016-12-21 12:04:54',
'2016-12-21 12:34:54'
))
df$DateTime = as.POSIXlt(strptime(df$DateTime,
format='%Y-%m-%d %H:%M:%S',
tz='GMT'))
ord = order(as.numeric(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S',
tz='GMT')))
df.ord = df[ord,1]
df.ord
The R bug I mentioned was not that
as.POSIXlt("2016-03-27 02:30", format="%Y-%m-%d %H:%M", tz="CET")
returned an NA. That seems reasonable since there was no such time.
The bug is that the POSIXlt object prints in an odd format (leaving
off the time zone/daylight/standard time string) instead of printing
an NA. This made it hard for you to see the problem.
Using tz="GMT" or "UTC" will give 'solar' time England.
tz="Etc/GMT-1" will give 'solar' time in central Europe.
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Thu, Jan 26, 2017 at 10:46 AM, rob vech <rob.vech87 at gmail.com> wrote:
Hi William,
asking to the r-devel list I resolved the problem! It depends from the
timezone (tz param) that I didn't specified and so R automatically uses my
local time and considers also the daylight saving time (that comes at 2:00
at my position).
As my dates are in solar time, I specified the time zone as "GMT" and it
works!
Here a simple example:
df = data.frame(DateTime = c(
'2016-12-21 10:34:54',
'2016-12-21 11:04:54',
'2016-12-21 11:34:54',
'2016-03-27 02:05:50',
'2016-03-27 02:35:50',
'2016-12-21 12:04:54',
'2016-12-21 12:34:54'
))
df$DateTime = as.POSIXlt(strptime(df$DateTime,
format='%Y-%m-%d %H:%M:%S',
tz='GMT'))
ord = order(as.numeric(strptime(df$DateTime, format='%Y-%m-%d %H:%M:%S',
tz='GMT')))
df.ord = df[ord,1]
df.ord
The Etc timezones are nice and simple, but I am grateful for the other ones since they help make handling local time conventions used by other people tolerable. In the TL;DR department, Local Standard Time is accessible using Olson "Etc/GMT.*" time zone strings, but that is not the same thing as "solar" time, for which noon occurs when the sun is highest in the sky. As the earth follows an elliptical orbit it speeds up and slows down throughout the year so solar noon shifts back and forth relative to local standard time.
Sent from my phone. Please excuse my brevity.
On January 26, 2017 11:22:47 AM PST, William Dunlap via R-help <r-help at r-project.org> wrote:
>The R bug I mentioned was not that
> as.POSIXlt("2016-03-27 02:30", format="%Y-%m-%d %H:%M", tz="CET")
>returned an NA. That seems reasonable since there was no such time.
>
>The bug is that the POSIXlt object prints in an odd format (leaving
>off the time zone/daylight/standard time string) instead of printing
>an NA. This made it hard for you to see the problem.
>
>Using tz="GMT" or "UTC" will give 'solar' time England.
>tz="Etc/GMT-1" will give 'solar' time in central Europe.
>
>Bill Dunlap
>TIBCO Software
>wdunlap tibco.com
>
>
>On Thu, Jan 26, 2017 at 10:46 AM, rob vech <rob.vech87 at gmail.com>
>wrote:
>> Hi William,
>> asking to the r-devel list I resolved the problem! It depends from
>the
>> timezone (tz param) that I didn't specified and so R automatically
>uses my
>> local time and considers also the daylight saving time (that comes at
>2:00
>> at my position).
>> As my dates are in solar time, I specified the time zone as "GMT" and
>it
>> works!
>> Here a simple example:
>>
>> df = data.frame(DateTime = c(
>> '2016-12-21 10:34:54',
>> '2016-12-21 11:04:54',
>> '2016-12-21 11:34:54',
>> '2016-03-27 02:05:50',
>> '2016-03-27 02:35:50',
>> '2016-12-21 12:04:54',
>> '2016-12-21 12:34:54'
>> ))
>>
>>
>> df$DateTime = as.POSIXlt(strptime(df$DateTime,
>> format='%Y-%m-%d %H:%M:%S',
>> tz='GMT'))
>>
>> ord = order(as.numeric(strptime(df$DateTime, format='%Y-%m-%d
>%H:%M:%S',
>> tz='GMT')))
>>
>> df.ord = df[ord,1]
>> df.ord
>>
>
>______________________________________________
>R-help at r-project.org 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.