Skip to content

Commit

Permalink
[Fix #605] Fix ceiling of days at DST transition
Browse files Browse the repository at this point in the history
  • Loading branch information
vspinu committed Jan 29, 2018
1 parent 7c04abd commit c061796
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/round.r
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ ceiling_date <- function(x, unit = "seconds", change_on_boundary = NULL, week_st
}
update(x, seconds = csec, simple = T)

} else if (unit %in% c("minute", "hour", "day")) {
} else if (unit %in% c("minute", "hour")) {

## cannot use this for minute/hour for Date class; local tz interferes with
## the computation
Expand Down Expand Up @@ -280,6 +280,7 @@ ceiling_date <- function(x, unit = "seconds", change_on_boundary = NULL, week_st
new <- switch(unit,
minute = update(new, minute = ceil_multi_unit(minute(new), n), second = 0, simple = T),
hour = update(new, hour = ceil_multi_unit(hour(new), n), minute = 0, second = 0, simple = T),
day = update(new, day = ceil_multi_unit1(day(new), n), hour = 0, minute = 0, second = 0),
week = update(new, wday = 8, hour = 0, minute = 0, second = 0, week_start = week_start),
month = update(new, months = new_month, mdays = 1, hours = 0, minutes = 0, seconds = 0),
year = update(new, year = ceil_multi_unit(year(new), n), month = 1, mday = 1, hour = 0, minute = 0, second = 0))
Expand Down
3 changes: 3 additions & 0 deletions tests/testthat/test-round.R
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ test_that("rounding works across DST", {
expect_equal(floor_date(tt, "month"), as.POSIXct("2016-03-01", tz = "Europe/Helsinki"))
tt <- ymd_hms("2016-03-27 05:00:00", tz = "Europe/Helsinki");
expect_equal(floor_date(tt, "day"), as.POSIXct("2016-03-27", tz = "Europe/Helsinki"))
## https://github.com/tidyverse/lubridate/issues/605
x <- ymd_hms("2017-11-05 23:59:03", tz = 'America/New_York')
expect_equal(ceiling_date(x, "day"), as.POSIXct("2017-11-06", tz = "America/New_York"))
})

test_that("Ceiling for partials (Date) rounds up on boundary", {
Expand Down

0 comments on commit c061796

Please sign in to comment.