xts icon indicating copy to clipboard operation
xts copied to clipboard

Incorrect endpoints when on="hours" and timezone is not a round hour offset from UTC

Open joshuaulrich opened this issue 9 years ago • 1 comments

If the index timezone happens to be one that is not a round hour offset from UTC, endpoints does not work correctly (because its calculations are based on UTC).

For example, Asia/Kolkata is UTC+0530, so endpoints aligns on half-hours.

R> require(xts)
R> x <- .xts(1:12, seq(0, by=600, length.out=12), tzone="Asia/Kolkata")
R> x[endpoints(x, "hours")]
                    [,1]
1970-01-01 06:20:00    6
1970-01-01 07:20:00   12

joshuaulrich avatar Oct 20 '15 19:10 joshuaulrich

A potential work-around: compare the 1-hour endpoints with the 30-minute endpoints.

R> hourEndpointsTZ30 <- function(x, k = 1) {
+   h <- endpoints(x, "hours", k)
+   m <- endpoints(x, "minutes", 30)
+   c(0, setdiff(m, h), last(m))
+ }
R> x[hourEndpointsTZ30(x)]
                    [,1]
1970-01-01 05:50:00    3
1970-01-01 06:50:00    9
1970-01-01 07:20:00   12

joshuaulrich avatar Feb 12 '17 16:02 joshuaulrich