Skip to content

Commit

Permalink
[Fix #219] In interval use UTC when tzone is missing.
Browse files Browse the repository at this point in the history
   Complies with the value returned by `tz`.
  • Loading branch information
vspinu committed Dec 14, 2014
1 parent 72738d1 commit d128299
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/intervals.r
Expand Up @@ -235,7 +235,7 @@ setMethod("$<-", signature(x = "Interval"), function(x, name, value) {
#' # 2009-01-01 UTC--2009-02-01 UTC
new_interval <- interval <- function(start, end, tzone = attr(start, "tzone")){
if (is.null(tzone)) {
if (is.null(attr(end, "tzone"))) tzone <- ""
if (is.null(attr(end, "tzone"))) tzone <- "UTC"
else tzone <- attr(end, "tzone")
}

Expand Down
5 changes: 5 additions & 0 deletions inst/tests/test-intervals.R
Expand Up @@ -111,6 +111,11 @@ test_that("format.Interval correctly displays intervals of length 0", {
expect_output(int[FALSE], "Interval\\(0)")
})

test_that("interval handles correctly time zones of Date objects", {
expect_equal(interval(as.Date('2011-01-01'), as.Date('2013-01-01')),
new_interval(ymd('2011-01-01'), ymd('2013-01-01')))
})

test_that("summary.Interval creates useful summary", {
int <- interval(ymd(20090201), ymd(20090101))
text <- c(3, "2009-01-01", "2009-02-01", "UTC", 1)
Expand Down

0 comments on commit d128299

Please sign in to comment.