tests/testthat/test-wday.R

test_that("wday for Dates", {
  expect_identical(dtt_wday(as.Date("2020-03-05")), "Thursday")
  expect_identical(dtt_wday(as.Date("2020-03-05")[-1]), character(0))
  expect_identical(dtt_wday(NA_Date_), NA_character_)
  expect_identical(
    dtt_wday(as.Date("2020-03-05") + 0:6),
    c(
      "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday",
      "Wednesday"
    )
  )
  expect_identical(
    dtt_wday(as.Date("2020-03-05") + 0:6, abbr = TRUE),
    c("Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed")
  )
})

test_that("wday for POSIXct", {
  expect_identical(dtt_wday(as.POSIXct("2020-03-05")), "Thursday")
  expect_identical(dtt_wday(as.POSIXct("2020-03-05")[-1]), character(0))
  expect_identical(dtt_wday(NA_POSIXct_), NA_character_)
  expect_identical(
    dtt_wday(as.POSIXct("2020-03-05") + 0:6 * 86400),
    c(
      "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday",
      "Wednesday"
    )
  )
  expect_identical(
    dtt_wday(as.POSIXct("2020-03-05") + 0:6 * 86400, abbr = TRUE),
    c("Thu", "Fri", "Sat", "Sun", "Mon", "Tue", "Wed")
  )
})

Try the dttr2 package in your browser

Any scripts or data that you put into this service are public.

dttr2 documentation built on Sept. 19, 2021, 9:06 a.m.