From 90fb51ad0d2511d627bf83ffaf8795d1ba1c757a Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 19 Nov 2019 16:28:24 -0600 Subject: [PATCH] Eliminate all partial matches Fixes #672 --- NEWS.md | 1 + R/round.r | 10 +- tests/testthat/setup-options.R | 6 + tests/testthat/test-daylight-savings.R | 10 +- tests/testthat/test-intervals.R | 8 +- tests/testthat/test-settors.R | 24 ++- tests/testthat/test-timezones.R | 2 +- tests/testthat/test-update.R | 253 ++++++++++++------------- 8 files changed, 159 insertions(+), 155 deletions(-) create mode 100644 tests/testthat/setup-options.R diff --git a/NEWS.md b/NEWS.md index b8d84ce5..4367c909 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/round.r b/R/round.r index 4b5fa915..53277136 100644 --- a/R/round.r +++ b/R/round.r @@ -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) } diff --git a/tests/testthat/setup-options.R b/tests/testthat/setup-options.R new file mode 100644 index 00000000..67675900 --- /dev/null +++ b/tests/testthat/setup-options.R @@ -0,0 +1,6 @@ +options( + warnPartialMatchArgs = TRUE, + warnPartialMatchAttr = TRUE, + warnPartialMatchDollar = TRUE +) + diff --git a/tests/testthat/test-daylight-savings.R b/tests/testthat/test-daylight-savings.R index dca27998..f4f11343 100644 --- a/tests/testthat/test-daylight-savings.R +++ b/tests/testthat/test-daylight-savings.R @@ -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), @@ -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)) }) diff --git a/tests/testthat/test-intervals.R b/tests/testthat/test-intervals.R index 9489683f..56dcebe4 100644 --- a/tests/testthat/test-intervals.R +++ b/tests/testthat/test-intervals.R @@ -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))) diff --git a/tests/testthat/test-settors.R b/tests/testthat/test-settors.R index 95321984..fa017a0f 100644 --- a/tests/testthat/test-settors.R +++ b/tests/testthat/test-settors.R @@ -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 @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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") diff --git a/tests/testthat/test-timezones.R b/tests/testthat/test-timezones.R index 5ab7d905..cf621727 100644 --- a/tests/testthat/test-timezones.R +++ b/tests/testthat/test-timezones.R @@ -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)) }) diff --git a/tests/testthat/test-update.R b/tests/testthat/test-update.R index 58a57eb1..d01ef4bc 100644 --- a/tests/testthat/test-update.R +++ b/tests/testthat/test-update.R @@ -3,12 +3,12 @@ context("Updating dates") test_that("update.Date returns a date object", { date <- as.Date("05/05/2010", "%m/%d/%Y") expect_that(update(date, days = 1), is_a("Date")) - expect_that(update(date, yday = 1), is_a("Date")) - expect_that(update(date, mday = 1), is_a("Date")) - expect_that(update(date, wday = 1), is_a("Date")) - expect_that(update(date, month = 1), is_a("Date")) - expect_that(update(date, year = 2001), is_a("Date")) - expect_that(update(date, tz = "UTC"), is_a("Date")) + expect_that(update(date, ydays = 1), is_a("Date")) + expect_that(update(date, mdays = 1), is_a("Date")) + expect_that(update(date, wdays = 1), is_a("Date")) + expect_that(update(date, months = 1), is_a("Date")) + expect_that(update(date, years = 2001), is_a("Date")) + expect_that(update(date, tzs = "UTC"), is_a("Date")) }) test_that("update.Date returns a posix object if time is manipulated", { @@ -24,12 +24,12 @@ test_that("update.POSIXlt returns a POSIXlt object", { expect_that(update(poslt, minutes = 1), is_a("POSIXlt")) expect_that(update(poslt, hours = 1), is_a("POSIXlt")) expect_that(update(poslt, days = 1), is_a("POSIXlt")) - expect_that(update(poslt, yday = 1), is_a("POSIXlt")) - expect_that(update(poslt, mday = 1), is_a("POSIXlt")) - expect_that(update(poslt, wday = 1), is_a("POSIXlt")) - expect_that(update(poslt, month = 1), is_a("POSIXlt")) - expect_that(update(poslt, year = 2001), is_a("POSIXlt")) - expect_that(update(poslt, tz = "UTC"), is_a("POSIXlt")) + expect_that(update(poslt, ydays = 1), is_a("POSIXlt")) + expect_that(update(poslt, mdays = 1), is_a("POSIXlt")) + expect_that(update(poslt, wdays = 1), is_a("POSIXlt")) + expect_that(update(poslt, months = 1), is_a("POSIXlt")) + expect_that(update(poslt, years = 2001), is_a("POSIXlt")) + expect_that(update(poslt, tzs = "UTC"), is_a("POSIXlt")) }) test_that("update.POSIXct returns a POSIXct object", { @@ -39,12 +39,12 @@ test_that("update.POSIXct returns a POSIXct object", { expect_that(update(posct, minutes = 1), is_a("POSIXct")) expect_that(update(posct, hours = 1), is_a("POSIXct")) expect_that(update(posct, days = 1), is_a("POSIXct")) - expect_that(update(posct, yday = 1), is_a("POSIXct")) - expect_that(update(posct, mday = 1), is_a("POSIXct")) - expect_that(update(posct, wday = 1), is_a("POSIXct")) - expect_that(update(posct, month = 1), is_a("POSIXct")) - expect_that(update(posct, year = 2001), is_a("POSIXct")) - expect_that(update(posct, tz = "UTC"), is_a("POSIXct")) + expect_that(update(posct, ydays = 1), is_a("POSIXct")) + expect_that(update(posct, mdays = 1), is_a("POSIXct")) + expect_that(update(posct, wdays = 1), is_a("POSIXct")) + expect_that(update(posct, months = 1), is_a("POSIXct")) + expect_that(update(posct, years = 2001), is_a("POSIXct")) + expect_that(update(posct, tzs = "UTC"), is_a("POSIXct")) }) test_that("update.Date performs simple operation as expected", { @@ -52,18 +52,18 @@ test_that("update.Date performs simple operation as expected", { expect_that(second(update(date, seconds = 1)), equals(1)) expect_that(minute(update(date, minutes = 1)), equals(1)) expect_that(hour(update(date, hours = 1)), equals(1)) - expect_that(mday(update(date, mday = 1)), equals(1)) - expect_that(wday(update(date, mday = 1)), equals(7)) - expect_that(yday(update(date, mday = 1)), equals(121)) - expect_that(yday(update(date, yday = 1)), equals(1)) - expect_that(mday(update(date, yday = 1)), equals(1)) - expect_that(wday(update(date, yday = 1)), equals(6)) - expect_that(wday(update(date, wday = 1)), equals(1)) - expect_that(yday(update(date, wday = 1)), equals(122)) - expect_that(mday(update(date, wday = 1)), equals(2)) + expect_that(mday(update(date, mdays = 1)), equals(1)) + expect_that(wday(update(date, mdays = 1)), equals(7)) + expect_that(yday(update(date, mdays = 1)), equals(121)) + expect_that(yday(update(date, ydays = 1)), equals(1)) + expect_that(mday(update(date, ydays = 1)), equals(1)) + expect_that(wday(update(date, ydays = 1)), equals(6)) + expect_that(wday(update(date, wdays = 1)), equals(1)) + expect_that(yday(update(date, wdays = 1)), equals(122)) + expect_that(mday(update(date, wdays = 1)), equals(2)) expect_that(month(update(date, months = 1)), equals(1)) expect_that(year(update(date, years = 2000)), equals(2000)) - expect_match(tz(update(date, tz = "UTC")), "UTC") + expect_match(tz(update(date, tzs = "UTC")), "UTC") }) test_that("update.POSIXt performs simple operation as expected", { @@ -72,101 +72,101 @@ test_that("update.POSIXt performs simple operation as expected", { expect_that(second(update(poslt, seconds = 1)), equals(1)) expect_that(minute(update(poslt, minutes = 1)), equals(1)) expect_that(hour(update(poslt, hours = 1)), equals(1)) - expect_that(mday(update(poslt, mday = 1)), equals(1)) - expect_that(wday(update(poslt, mday = 1)), equals(2)) - expect_that(yday(update(poslt, mday = 1)), equals(32)) - expect_that(yday(update(poslt, yday = 1)), equals(1)) - expect_that(mday(update(poslt, yday = 1)), equals(1)) - expect_that(wday(update(poslt, yday = 1)), equals(6)) - expect_that(wday(update(poslt, wday = 1)), equals(1)) - expect_that(yday(update(poslt, wday = 1)), equals(31)) - expect_that(mday(update(poslt, wday = 1)), equals(31)) + expect_that(mday(update(poslt, mdays = 1)), equals(1)) + expect_that(wday(update(poslt, mdays = 1)), equals(2)) + expect_that(yday(update(poslt, mdays = 1)), equals(32)) + expect_that(yday(update(poslt, ydays = 1)), equals(1)) + expect_that(mday(update(poslt, ydays = 1)), equals(1)) + expect_that(wday(update(poslt, ydays = 1)), equals(6)) + expect_that(wday(update(poslt, wdays = 1)), equals(1)) + expect_that(yday(update(poslt, wdays = 1)), equals(31)) + expect_that(mday(update(poslt, wdays = 1)), equals(31)) expect_that(month(update(poslt, months = 1)), equals(1)) expect_that(year(update(poslt, years = 2000)), equals(2000)) - expect_match(tz(update(poslt, tz = "UTC")), "UTC") + expect_match(tz(update(poslt, tzs = "UTC")), "UTC") expect_that(second(update(posct, seconds = 1)), equals(1)) expect_that(minute(update(posct, minutes = 1)), equals(1)) expect_that(hour(update(posct, hours = 1)), equals(1)) - expect_that(mday(update(posct, mday = 1)), equals(1)) - expect_that(wday(update(posct, mday = 1)), equals(2)) - expect_that(yday(update(posct, mday = 1)), equals(32)) - expect_that(yday(update(posct, yday = 1)), equals(1)) - expect_that(mday(update(posct, yday = 1)), equals(1)) - expect_that(wday(update(posct, yday = 1)), equals(6)) - expect_that(wday(update(posct, wday = 1)), equals(1)) - expect_that(yday(update(posct, wday = 1)), equals(31)) - expect_that(mday(update(posct, wday = 1)), equals(31)) + expect_that(mday(update(posct, mdays = 1)), equals(1)) + expect_that(wday(update(posct, mdays = 1)), equals(2)) + expect_that(yday(update(posct, mdays = 1)), equals(32)) + expect_that(yday(update(posct, ydays = 1)), equals(1)) + expect_that(mday(update(posct, ydays = 1)), equals(1)) + expect_that(wday(update(posct, ydays = 1)), equals(6)) + expect_that(wday(update(posct, wdays = 1)), equals(1)) + expect_that(yday(update(posct, wdays = 1)), equals(31)) + expect_that(mday(update(posct, wdays = 1)), equals(31)) expect_that(month(update(posct, months = 1)), equals(1)) expect_that(year(update(posct, years = 2000)), equals(2000)) - expect_match(tz(update(posct, tz = "UTC")), "UTC") + expect_match(tz(update(posct, tzs = "UTC")), "UTC") }) test_that("update.POSIXt works on wdays", { date <- ymd("2017-05-07") ## sunday ct <- as.POSIXct("2010-02-03 13:45:59", tz = "America/New_York", format = "%Y-%m-%d %H:%M:%S") ## Wednesday - expect_equal(wday(update(ct, wday = 1)), 1) - expect_equal(wday(update(ct, wday = 2)), 2) - expect_equal(wday(update(ct, wday = 5)), 5) - expect_equal(wday(update(ct, wday = 7)), 7) - expect_equal(wday(update(date, wday = 1)), 1) - expect_equal(wday(update(date, wday = 2)), 2) - expect_equal(wday(update(date, wday = 5)), 5) - expect_equal(wday(update(date, wday = 7)), 7) + expect_equal(wday(update(ct, wdays = 1)), 1) + expect_equal(wday(update(ct, wdays = 2)), 2) + expect_equal(wday(update(ct, wdays = 5)), 5) + expect_equal(wday(update(ct, wdays = 7)), 7) + expect_equal(wday(update(date, wdays = 1)), 1) + expect_equal(wday(update(date, wdays = 2)), 2) + expect_equal(wday(update(date, wdays = 5)), 5) + expect_equal(wday(update(date, wdays = 7)), 7) ws <- 1 - expect_equal(wday(update(ct, wday = 1, week_start = ws)), 2) - expect_equal(wday(update(ct, wday = 2, week_start = ws)), 3) - expect_equal(wday(update(ct, wday = 5, week_start = ws)), 6) - expect_equal(wday(update(ct, wday = 7, week_start = ws)), 1) - expect_equal(wday(update(date, wday = 1, week_start = ws)), 2) - expect_equal(wday(update(date, wday = 2, week_start = ws)), 3) - expect_equal(wday(update(date, wday = 5, week_start = ws)), 6) - expect_equal(wday(update(date, wday = 7, week_start = ws)), 1) + expect_equal(wday(update(ct, wdays = 1, week_start = ws)), 2) + expect_equal(wday(update(ct, wdays = 2, week_start = ws)), 3) + expect_equal(wday(update(ct, wdays = 5, week_start = ws)), 6) + expect_equal(wday(update(ct, wdays = 7, week_start = ws)), 1) + expect_equal(wday(update(date, wdays = 1, week_start = ws)), 2) + expect_equal(wday(update(date, wdays = 2, week_start = ws)), 3) + expect_equal(wday(update(date, wdays = 5, week_start = ws)), 6) + expect_equal(wday(update(date, wdays = 7, week_start = ws)), 1) ws <- 1 - expect_equal(wday(update(ct, wday = 1, week_start = ws), week_start = ws), 1) - expect_equal(wday(update(ct, wday = 2, week_start = ws), week_start = ws), 2) - expect_equal(wday(update(ct, wday = 5, week_start = ws), week_start = ws), 5) - expect_equal(wday(update(ct, wday = 7, week_start = ws), week_start = ws), 7) - expect_equal(wday(update(date, wday = 1, week_start = ws), week_start = ws), 1) - expect_equal(wday(update(date, wday = 2, week_start = ws), week_start = ws), 2) - expect_equal(wday(update(date, wday = 5, week_start = ws), week_start = ws), 5) - expect_equal(wday(update(date, wday = 7, week_start = ws), week_start = ws), 7) + expect_equal(wday(update(ct, wdays = 1, week_start = ws), week_start = ws), 1) + expect_equal(wday(update(ct, wdays = 2, week_start = ws), week_start = ws), 2) + expect_equal(wday(update(ct, wdays = 5, week_start = ws), week_start = ws), 5) + expect_equal(wday(update(ct, wdays = 7, week_start = ws), week_start = ws), 7) + expect_equal(wday(update(date, wdays = 1, week_start = ws), week_start = ws), 1) + expect_equal(wday(update(date, wdays = 2, week_start = ws), week_start = ws), 2) + expect_equal(wday(update(date, wdays = 5, week_start = ws), week_start = ws), 5) + expect_equal(wday(update(date, wdays = 7, week_start = ws), week_start = ws), 7) ws <- 3 - expect_equal(wday(update(ct, wday = 1, week_start = ws), week_start = ws), 1) - expect_equal(wday(update(ct, wday = 2, week_start = ws), week_start = ws), 2) - expect_equal(wday(update(ct, wday = 5, week_start = ws), week_start = ws), 5) - expect_equal(wday(update(ct, wday = 7, week_start = ws), week_start = ws), 7) - expect_equal(wday(update(date, wday = 1, week_start = ws), week_start = ws), 1) - expect_equal(wday(update(date, wday = 2, week_start = ws), week_start = ws), 2) - expect_equal(wday(update(date, wday = 5, week_start = ws), week_start = ws), 5) - expect_equal(wday(update(date, wday = 7, week_start = ws), week_start = ws), 7) + expect_equal(wday(update(ct, wdays = 1, week_start = ws), week_start = ws), 1) + expect_equal(wday(update(ct, wdays = 2, week_start = ws), week_start = ws), 2) + expect_equal(wday(update(ct, wdays = 5, week_start = ws), week_start = ws), 5) + expect_equal(wday(update(ct, wdays = 7, week_start = ws), week_start = ws), 7) + expect_equal(wday(update(date, wdays = 1, week_start = ws), week_start = ws), 1) + expect_equal(wday(update(date, wdays = 2, week_start = ws), week_start = ws), 2) + expect_equal(wday(update(date, wdays = 5, week_start = ws), week_start = ws), 5) + expect_equal(wday(update(date, wdays = 7, week_start = ws), week_start = ws), 7) }) test_that("updates on ydays works correctly with leap years", { - expect_equal(update(ymd("15-02-03", tz = "UTC"), year = 2000, yday = 1), + expect_equal(update(ymd("15-02-03", tz = "UTC"), years = 2000, ydays = 1), ymd("2000-01-01", tz = "UTC")) - expect_equal(update(ymd("15-02-03", tz = "UTC"), year = 2015, yday = 1), + expect_equal(update(ymd("15-02-03", tz = "UTC"), years = 2015, ydays = 1), ymd("2015-01-01", tz = "UTC")) - expect_equal(update(ymd("15-02-03", tz = "UTC"), year = 2016, yday = 10), + expect_equal(update(ymd("15-02-03", tz = "UTC"), years = 2016, ydays = 10), ymd("2016-01-10", tz = "UTC")) - expect_equal(update(ymd("15-02-03", tz = "America/New_York"), year = 2000, yday = 1), + expect_equal(update(ymd("15-02-03", tz = "America/New_York"), years = 2000, ydays = 1), ymd("2000-01-01", tz = "America/New_York")) - expect_equal(update(ymd("15-02-03", tz = "America/New_York"), year = 2015, yday = 1), + expect_equal(update(ymd("15-02-03", tz = "America/New_York"), years = 2015, ydays = 1), ymd("2015-01-01", tz = "America/New_York")) - expect_equal(update(ymd("15-02-03", tz = "America/New_York"), year = 2016, yday = 10), + expect_equal(update(ymd("15-02-03", tz = "America/New_York"), years = 2016, ydays = 10), ymd("2016-01-10", tz = "America/New_York")) - expect_equal(update(ymd(c("2016-02-29", "2016-03-01")), yday = 1), + expect_equal(update(ymd(c("2016-02-29", "2016-03-01")), ydays = 1), ymd(c("2016-01-01", "2016-01-01"))) - expect_equal(update(ymd(c("2016-02-29", "2016-03-01"), tz = "America/New_York"), yday = 1), + expect_equal(update(ymd(c("2016-02-29", "2016-03-01"), tz = "America/New_York"), ydays = 1), ymd(c("2016-01-01", "2016-01-01"), tz = "America/New_York")) - expect_equal(update(ymd_hms(c("2016-02-29 1:2:3", "2016-03-01 10:20:30")), yday = 1), + expect_equal(update(ymd_hms(c("2016-02-29 1:2:3", "2016-03-01 10:20:30")), ydays = 1), ymd_hms(c("2016-01-01 1:2:3", "2016-01-01 10:20:30"))) - expect_equal(update(ymd_hms(c("2016-02-29 1:2:3", "2016-03-01 10:20:30"), tz = "America/New_York"), yday = 1), + expect_equal(update(ymd_hms(c("2016-02-29 1:2:3", "2016-03-01 10:20:30"), tz = "America/New_York"), ydays = 1), ymd_hms(c("2016-01-01 1:2:3", "2016-01-01 10:20:30"), tz = "America/New_York")) }) @@ -182,15 +182,15 @@ test_that("update performs roll overs correctly for Date objects", { expect_that(mday(update(date, hours = 25)), equals(6)) expect_that(yday(update(date, hours = 25)), equals(126)) expect_that(wday(update(date, hours = 25)), equals(5)) - expect_that(mday(update(date, mday = 32)), equals(1)) - expect_that(month(update(date, mday = 32)), equals(6)) - expect_that(wday(update(date, wday = 31)), equals(3)) - expect_that(month(update(date, wday = 31)), equals(6)) - expect_that(yday(update(date, yday = 366)), equals(1)) - expect_that(month(update(date, yday = 366)), equals(1)) - expect_that(month(update(date, month = 13)), equals(1)) - expect_that(year(update(date, month = 13)), equals(2011)) - expect_match(tz(update(date, month = 13)), "UTC") + expect_that(mday(update(date, mdays = 32)), equals(1)) + expect_that(month(update(date, mdays = 32)), equals(6)) + expect_that(wday(update(date, wdays = 31)), equals(3)) + expect_that(month(update(date, wdays = 31)), equals(6)) + expect_that(yday(update(date, ydays = 366)), equals(1)) + expect_that(month(update(date, ydays = 366)), equals(1)) + expect_that(month(update(date, months = 13)), equals(1)) + expect_that(year(update(date, months = 13)), equals(2011)) + expect_match(tz(update(date, months = 13)), "UTC") }) test_that("update performs roll overs correctly for POSIXlt objects", { @@ -203,15 +203,15 @@ test_that("update performs roll overs correctly for POSIXlt objects", { expect_that(mday(update(poslt, hours = 25)), equals(6)) expect_that(yday(update(poslt, hours = 25)), equals(126)) expect_that(wday(update(poslt, hours = 25)), equals(5)) - expect_that(mday(update(poslt, mday = 32)), equals(1)) - expect_that(month(update(poslt, mday = 32)), equals(6)) - expect_that(wday(update(poslt, wday = 31)), equals(3)) - expect_that(month(update(poslt, wday = 31)), equals(6)) - expect_that(yday(update(poslt, yday = 366)), equals(1)) - expect_that(month(update(poslt, yday = 366)), equals(1)) - expect_that(month(update(poslt, month = 13)), equals(1)) - expect_that(year(update(poslt, month = 13)), equals(2011)) - expect_match(tz(update(poslt, month = 13)), "GMT") + expect_that(mday(update(poslt, mdays = 32)), equals(1)) + expect_that(month(update(poslt, mdays = 32)), equals(6)) + expect_that(wday(update(poslt, wdays = 31)), equals(3)) + expect_that(month(update(poslt, wdays = 31)), equals(6)) + expect_that(yday(update(poslt, ydays = 366)), equals(1)) + expect_that(month(update(poslt, ydays = 366)), equals(1)) + expect_that(month(update(poslt, months = 13)), equals(1)) + expect_that(year(update(poslt, months = 13)), equals(2011)) + expect_match(tz(update(poslt, months = 13)), "GMT") }) test_that("update performs roll overs correctly for POSIXct objects", { @@ -224,15 +224,15 @@ test_that("update performs roll overs correctly for POSIXct objects", { expect_that(mday(update(posct, hours = 25)), equals(6)) expect_that(yday(update(posct, hours = 25)), equals(126)) expect_that(wday(update(posct, hours = 25)), equals(5)) - expect_that(mday(update(posct, mday = 32)), equals(1)) - expect_that(month(update(posct, mday = 32)), equals(6)) - expect_that(wday(update(posct, wday = 31)), equals(3)) - expect_that(month(update(posct, wday = 31)), equals(6)) - expect_that(yday(update(posct, yday = 366)), equals(1)) - expect_that(month(update(posct, yday = 366)), equals(1)) - expect_that(month(update(posct, month = 13)), equals(1)) - expect_that(year(update(posct, month = 13)), equals(2011)) - expect_match(tz(update(posct, month = 13)), "GMT") + expect_that(mday(update(posct, mdays = 32)), equals(1)) + expect_that(month(update(posct, mdays = 32)), equals(6)) + expect_that(wday(update(posct, wdays = 31)), equals(3)) + expect_that(month(update(posct, wdays = 31)), equals(6)) + expect_that(yday(update(posct, ydays = 366)), equals(1)) + expect_that(month(update(posct, ydays = 366)), equals(1)) + expect_that(month(update(posct, months = 13)), equals(1)) + expect_that(year(update(posct, months = 13)), equals(2011)) + expect_match(tz(update(posct, months = 13)), "GMT") }) test_that("update performs consecutive roll overs correctly for @@ -250,8 +250,7 @@ test_that("update performs consecutive roll overs correctly for expect_that(year(date), equals(2011)) expect_match(tz(date), "UTC") date2 <- update(as.Date("11/01/2010", "%m/%d/%Y"), - seconds = 61, minutes = 61, hours = 25, days = 32, months - = 13) + seconds = 61, minutes = 61, hours = 25, days = 32, months = 13) expect_that(second(date2), equals(1)) expect_that(minute(date2), equals(2)) expect_that(hour(date2), equals(2)) @@ -326,23 +325,23 @@ test_that("update performs consecutive roll overs correctly for POSIXct objects" test_that("update returns NA for date-times in the 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") expect_true(is.na(update(poslt, seconds = 65))) expect_true(is.na(update(poslt, minutes = 65))) expect_true(is.na(update(poslt, hours = 2))) 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") - expect_true(is.na(update(poslt, mday = 14))) - expect_true(is.na(update(poslt, wday = 8))) - expect_true(is.na(update(poslt, yday = 73))) + poslt <- force_tz(poslt, tzone = "America/New_York") + 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 <- 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") expect_true(is.na(update(poslt, months = 3))) 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") expect_true(is.na(update(poslt, years = 2010))) poslt <- as.POSIXlt("2010-03-14 02:59:59", tz = "UTC", format = "%Y-%m-%d %H:%M:%S") - expect_true(is.na(update(poslt, tz = "America/New_York"))) + expect_true(is.na(update(poslt, tzs = "America/New_York"))) }) test_that("update handles vectors of dates", {