Skip to content

Commit

Permalink
Eliminate all partial matches
Browse files Browse the repository at this point in the history
Fixes #672
  • Loading branch information
hadley committed Nov 19, 2019
1 parent a3fbaad commit 90fb51a
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 155 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Version 1.7.4.9000

### NEW FEATURES

* [#672](https://github.com/tidyverse/lubridate/issues/672) Eliminate all partial argument matches
* [#695](https://github.com/tidyverse/lubridate/issues/695) Durations can now be compared with numeric vectors.
* [#681](https://github.com/tidyverse/lubridate/issues/681) New constants `NA_Date_` and `NA_POSIXct_` which parallel built-in primitive constants.
* [#681](https://github.com/tidyverse/lubridate/issues/681) New constructors `Date()` and `POSIXct()` which parallel built-in primitive constructors.
Expand Down
10 changes: 5 additions & 5 deletions R/round.r
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,12 @@ 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),
minute = update(new, minutes = ceil_multi_unit(minute(new), n), seconds = 0, simple = T),
hour = update(new, hours = ceil_multi_unit(hour(new), n), minutes = 0, seconds = 0, simple = T),
day = update(new, days = ceil_multi_unit1(day(new), n), hours = 0, minutes = 0, seconds = 0),
week = update(new, wdays = 8, hours = 0, minutes = 0, seconds = 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))
year = update(new, years = ceil_multi_unit(year(new), n), months = 1, mdays = 1, hours = 0, minutes = 0, seconds = 0))

reclass_date_maybe(new, x, unit)
}
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/setup-options.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
options(
warnPartialMatchArgs = TRUE,
warnPartialMatchAttr = TRUE,
warnPartialMatchDollar = TRUE
)

10 changes: 5 additions & 5 deletions tests/testthat/test-daylight-savings.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ test_that("update returns NA for date-times in the spring dst gap", {
year = 110L, wday = 6L, yday = 71L, isdst = 0L),
.Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"),
class = c("POSIXlt", "POSIXt"), tzone = c("America/New_York", "EST", "EDT"))
expect_true(is.na(update(poslt, mday = 14)))
expect_true(is.na(update(poslt, wday = 8)))
expect_true(is.na(update(poslt, yday = 73)))
expect_true(is.na(update(poslt, mdays = 14)))
expect_true(is.na(update(poslt, wdays = 8)))
expect_true(is.na(update(poslt, ydays = 73)))

poslt <- structure(list(sec = 59, min = 59L, hour = 2L, mday = 14L, mon = 1L,
year = 110L, wday = 0L, yday = 44L, isdst = 0L),
Expand All @@ -134,8 +134,8 @@ test_that("update returns NA for date-times in the spring dst gap", {
year = 110L, wday = 0L, yday = 72L, isdst = 0L),
.Names = c("sec", "min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"),
class = c("POSIXlt", "POSIXt"), tzone = "UTC")
expect_true(is.na(update(poslt, tz = "America/New_York")))
expect_equal(update(c(xu, poslt), tz = "America/New_York"), c(x2, NA))
expect_true(is.na(update(poslt, tzs = "America/New_York")))
expect_equal(update(c(xu, poslt), tzs = "America/New_York"), c(x2, NA))

})

Expand Down
8 changes: 4 additions & 4 deletions tests/testthat/test-intervals.R
Original file line number Diff line number Diff line change
Expand Up @@ -390,21 +390,21 @@ test_that("intersect.Interval works as expected", {
nint3 <- interval(time32, time31)

expect_equal(intersect(int1, int2), interval(time21, time2))
expect_equal(intersect(int1, int3), interval(NA, NA, tz = "UTC"))
expect_equal(intersect(int1, int3), interval(NA, NA, tzone = "UTC"))
expect_equal(intersect(int1, c(int2, int3)), interval(c(time21, NA), c(time2, NA)))
expect_equal(intersect(c(int1, int3), int2), interval(c(time21, NA), c(time2, NA)))
expect_equal(intersect(c(int1, int3), c(int2, int2)), interval(c(time21, NA), c(time2, NA)))

expect_equal(intersect(nint1, nint2), interval(time2, time21))
expect_equal(intersect(nint1, nint3), interval(NA, NA, tz = "UTC"))
expect_equal(intersect(nint1, nint3), interval(NA, NA, tzone = "UTC"))
expect_equal(intersect(nint1, c(nint2, nint3)), interval(c(time2, NA), c(time21, NA)))
expect_equal(intersect(c(nint1, nint3), nint2), interval(c(time2, NA), c(time21, NA)))
expect_equal(intersect(c(nint1, nint3), c(nint2, nint2)), interval(c(time2, NA), c(time21, NA)))

expect_equal(intersect(int1, nint2), interval(time21, time2))
expect_equal(intersect(nint1, nint2), interval(time2, time21))
expect_equal(intersect(int1, nint3), interval(NA, NA, tz = "UTC"))
expect_equal(intersect(nint1, int3), interval(NA, NA, tz = "UTC"))
expect_equal(intersect(int1, nint3), interval(NA, NA, tzone = "UTC"))
expect_equal(intersect(nint1, int3), interval(NA, NA, tzone = "UTC"))
expect_equal(intersect(int1, c(nint2, int3)), interval(c(time21, NA), c(time2, NA)))
expect_equal(intersect(nint1, c(int2, int3)), interval(c(time2, NA), c(time21, NA)))
expect_equal(intersect(c(int1, nint3), nint2), interval(c(time21, NA), c(time2, NA)))
Expand Down
24 changes: 11 additions & 13 deletions tests/testthat/test-settors.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ test_that("seconds settor does not change time zone", {

test_that("seconds settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2010-03-14 01:59:59", tz = "UTC", format = "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posxct <- as.POSIXct(poslt)

second(poslt) <- 69
Expand Down Expand Up @@ -206,7 +206,7 @@ test_that("minutes settor does not change time zone", {
test_that("minutes settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2010-03-14 01:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

minute(poslt) <- 70
Expand Down Expand Up @@ -300,8 +300,7 @@ test_that("hours settor rolls over as expected", {
})

test_that("hours settor does not change time zone", {
poslt <- as.POSIXlt("2010-02-14 01:59:59", tz = "GMT", format
= "%Y-%m-%d %H:%M:%S")
poslt <- as.POSIXlt("2010-02-14 01:59:59", tz = "GMT", format = "%Y-%m-%d %H:%M:%S")
posct <- as.POSIXct(poslt)
date <- as.Date(poslt)

Expand All @@ -324,9 +323,8 @@ test_that("hours settor does not change time zone", {


test_that("hours settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2010-03-14 01:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- as.POSIXlt("2010-03-14 01:59:59", tz = "UTC", format = "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

hour(poslt) <- 2
Expand Down Expand Up @@ -456,7 +454,7 @@ test_that("mdays settor does not change time zone", {
test_that("mdays settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2010-03-13 02:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

mday(poslt) <- 14
Expand Down Expand Up @@ -585,7 +583,7 @@ test_that("ydays settor does not change time zone", {
test_that("ydays settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2010-03-13 02:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

yday(poslt) <- 73
Expand Down Expand Up @@ -715,7 +713,7 @@ test_that("wdays settor does not change time zone", {
test_that("wdays settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2010-03-13 02:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

wday(poslt) <- 8
Expand Down Expand Up @@ -835,7 +833,7 @@ test_that("months settor does not change time zone", {
test_that("months settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2010-02-14 02:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

month(poslt) <- 3
Expand Down Expand Up @@ -905,7 +903,7 @@ test_that("years settor does not change time zone", {
test_that("years settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2009-03-14 02:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

year(poslt) <- 2010
Expand Down Expand Up @@ -965,7 +963,7 @@ test_that("dates settor does not change time zone", {
test_that("dates settor returns NA for spring dst gap", {
poslt <- as.POSIXlt("2009-03-14 02:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt <- force_tz(poslt, tz = "America/New_York")
poslt <- force_tz(poslt, tzone = "America/New_York")
posct <- as.POSIXct(poslt)

date(poslt) <- as.Date("2010-03-14")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-timezones.R
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test_that("force_tz handles data.frames", {
test_that("force_tz doesn't return NA just because new time zone uses DST", {
poslt <- as.POSIXlt("2009-03-14 02:59:59", tz = "UTC", format
= "%Y-%m-%d %H:%M:%S")
poslt2 <- force_tz(poslt, tz = "America/New_York")
poslt2 <- force_tz(poslt, tzone = "America/New_York")

expect_true(!is.na(poslt2))
})
Expand Down
Loading

0 comments on commit 90fb51a

Please sign in to comment.