Summary:
For certain well formed inputs, cut.POSIXt will give an error.
Example:
cut(as.POSIXct("2009-11-01 04:00:00",
tz="America/Los_Angeles"), "1 day")
Example output:
Error in seq.int(0, to - from, by) : 'to' must be finite
Patch to fix error:
This patch is for src/library/base/R/datetime.R
Index: datetime.R
==================================================================--- datetime.R
(revision 51110)
+++ datetime.R (working copy)
@@ -729,7 +729,7 @@
incr <- 1
if(valid > 1L) { start$sec <- 0L; incr <- 59.99 }
if(valid > 2L) { start$min <- 0L; incr <- 3600 - 1 }
- if(valid > 3L) { start$hour <- 0L; incr <- 86400 - 1 }
+ if(valid > 3L) { start$hour <- 0L; start$isdst <- -1L; incr <-
86400 - 1 }
if(valid == 5L) { # weeks
start$mday <- start$mday - start$wday
if(start.on.monday)
Discussion/description:
The bug is triggered when the (earliest) date/time given to cut.POSIXt
falls on the day transitioning from daylight savings time to standard
time, but at a time after the switchover. In the US, November 1, 2009 was
such a day.
In cut.POSIXt(), the elements of a POSIXlt representation of the starting
date/time are directly manipulated to set it to the start of the day
(since a day sized spacing was requested). This puts it before the daylight
savings time to standard time switchover. When as.POSIXct is later called
on this object, it returns NA which causes the returned error when the NA
is passed as an argument to seq.int().
The motivation for the patch is the trunc.POSIXt function in the same
file. It correctly handles this case:
trunc(as.POSIXct("2009-11-01 04:00:00",
tz="America/Los_Angeles"), "day")
# [1] "2009-11-01 America/Los_Angeles"
as.POSIXct(trunc(as.POSIXct("2009-11-01 04:00:00",
tz="America/Los_Angeles"), "day"))
# [1] "2009-11-01 PDT"
In that function, when truncating to days, the isdst element of the POSIXlt
is set to -1L. That is the modification to cut.POSIXt() that I made.
--
Brian Diggs, Ph.D.
Senior Research Associate, Department of Surgery, Oregon Health & Science
University
--please do not edit the information below--
Version:
platform = i386-pc-mingw32
arch = i386
os = mingw32
system = i386, mingw32
status =
major = 2
minor = 10.1
year = 2009
month = 12
day = 14
svn rev = 50720
language = R
version.string = R version 2.10.1 (2009-12-14)
Windows XP (build 2600) Service Pack 3
Locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
Search Path:
.GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils,
package:datasets, package:methods, Autoloads, package:base
I do not know why my bug report got so oddly encoded, I've reproduced it;
hopefully it won't get mangled again.
Summary:
For certain well formed inputs, cut.POSIXt will give an error.
Example:
cut(as.POSIXct("2009-11-01 04:00:00",
tz="America/Los_Angeles"), "1 day")
Example output:
Error in seq.int(0, to - from, by) : 'to' must be finite
Patch to fix error:
This patch is for src/library/base/R/datetime.R
Index: datetime.R
==================================================================--- datetime.R
(revision 51110)
+++ datetime.R (working copy)
@@ -729,7 +729,7 @@
incr <- 1
if(valid > 1L) { start$sec <- 0L; incr <- 59.99 }
if(valid > 2L) { start$min <- 0L; incr <- 3600 - 1 }
- if(valid > 3L) { start$hour <- 0L; incr <- 86400 - 1 }
+ if(valid > 3L) { start$hour <- 0L; start$isdst <- -1L; incr <-
86400 - 1 }
if(valid == 5L) { # weeks
start$mday <- start$mday - start$wday
if(start.on.monday)
Discussion:
The bug is triggered when the (earliest) date/time given to cut.POSIXt
falls on the day transitioning from daylight savings time to standard
time, but at a time after the switchover. In the US, November 1, 2009 was
such a day.
In cut.POSIXt(), the elements of a POSIXlt representation of the date/time
are directly manipulated to set it to the start of the day (since a day
sized spacing was requested). This puts it before the daylight savings
time to standard time switchover. When as.POSIXct is later called on this
object, it returns NA which causes the returned error when the NA is passed
as an argument to seq.int().
The motivation for the patch is the trunc.POSIXt function in the same
file. It correctly handles this case:
trunc(as.POSIXct("2009-11-01 04:00:00",
tz="America/Los_Angeles"), "day")
# [1] "2009-11-01 America/Los_Angeles"
as.POSIXct(trunc(as.POSIXct("2009-11-01 04:00:00",
tz="America/Los_Angeles"), "day"))
# [1] "2009-11-01 PDT"
In that function, when truncating to days, the isdst element of the POSIXlt
is set to -1L. That is the modification to cut.POSIXt() that I made.
--please do not edit the information below--
Version:
platform = i386-pc-mingw32
arch = i386
os = mingw32
system = i386, mingw32
status =
major = 2
minor = 10.1
year = 2009
month = 12
day = 14
svn rev = 50720
language = R
version.string = R version 2.10.1 (2009-12-14)
Windows XP (build 2600) Service Pack 3
Locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United
States.1252;LC_MONETARY=English_United
States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
Search Path:
.GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils,
package:datasets, package:methods, Autoloads, package:base
On 2/8/2010 11:30 AM, diggsb@ohsu.edu wrote:>
U3VtbWFyeToNCg0KRm9yIGNlcnRhaW4gd2VsbCBmb3JtZWQgaW5wdXRzLCBjdXQuUE9TSVh0IHdp
>
bGwgZ2l2ZSBhbiBlcnJvci4NCg0KRXhhbXBsZToNCg0KY3V0KGFzLlBPU0lYY3QoIjIwMDktMTEt
>
MDEgMDQ6MDA6MDAiLCB0ej0iQW1lcmljYS9Mb3NfQW5nZWxlcyIpLCAiMSBkYXkiKQ0KDQpFeGFt
>
cGxlIG91dHB1dDoNCg0KRXJyb3IgaW4gc2VxLmludCgwLCB0byAtIGZyb20sIGJ5KSA6ICd0bycg
>
bXVzdCBiZSBmaW5pdGUNCg0KUGF0Y2ggdG8gZml4IGVycm9yOg0KDQpUaGlzIHBhdGNoIGlzIGZv
>
ciBzcmMvbGlicmFyeS9iYXNlL1IvZGF0ZXRpbWUuUg0KDQpJbmRleDogZGF0ZXRpbWUuUg0KPT09
>
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
>
PT09PT09PQ0KLS0tIGRhdGV0aW1lLlIJKHJldmlzaW9uIDUxMTEwKQ0KKysrIGRhdGV0aW1lLlIJ
>
KHdvcmtpbmcgY29weSkNCkBAIC03MjksNyArNzI5LDcgQEANCiAJaW5jciA8LSAxDQogCWlmKHZh
>
bGlkID4gMUwpIHsgc3RhcnQkc2VjIDwtIDBMOyBpbmNyIDwtI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