Skip to content

Commit

Permalink
Merge pull request #488 from cderv/patch-ceiling_date
Browse files Browse the repository at this point in the history
ceiling_date handles missing value propely
  • Loading branch information
vspinu authored Oct 27, 2016
2 parents 45acc41 + 1f87be8 commit fce28cd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Version 1.6.0.9000
* [#466](https://github.com/hadley/lubridate/pull/466) Fix wrong formats within ymd_h family of functions.
* [#472](https://github.com/hadley/lubridate/pull/472) Printing method for duration doesn't throw format error on fractional seconds.
* [#475](https://github.com/hadley/lubridate/pull/475) character<> comparisons is no longer slow.
* [#486](https://github.com/hadley/lubridate/issues/486) ceiling_date handles `NA` properly.


Version 1.6.0
=============
Expand Down
2 changes: 1 addition & 1 deletion R/round.r
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ ceiling_date <- function(x, unit = "seconds", change_on_boundary = NULL) {
trunc_multi_unit(new, unit, n) + delta
} else{
new1 <- trunc_multi_unit(new, unit, n)
not_same <- new1 != new
not_same <- which(new1 != new)
new1[not_same] <- new1[not_same] + delta
new1
}
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-round.R
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,22 @@ test_that("round_date and ceiling_date skip day time gap", {

expect_equal(round_date(x, "hour"), y)
})

test_that("ceiling_date, round_date and floor_date behave correctly with NA", {
## (bug #486)
x <- ymd_hms("2009-08-03 12:01:59.23", tz = "UTC") + (0:1)*days()
x[2] <- NA
expect_equal(ceiling_date(x, unit = "day"),
c(ymd("2009-08-04", tz = "UTC"), NA))
expect_equal(ceiling_date(x, unit = "seconds"),
c(ymd_hms("2009-08-03 12:02:00", tz = "UTC"), NA))
expect_equal(ceiling_date(x, unit = "months"),
c(ymd("2009-09-01", tz = "UTC"), NA))
expect_equal(floor_date(x, unit = "day"),
c(ymd("2009-08-03", tz = "UTC"), NA))
expect_equal(floor_date(x, unit = "months"),
c(ymd("2009-08-01", tz = "UTC"), NA))
expect_equal(round_date(x, unit = "minute"),
c(ymd_hms("2009-08-03 12:02:00", tz = "UTC"), NA))
})

0 comments on commit fce28cd

Please sign in to comment.