tests/testthat/test-am-pm.R

test_that("am and pm correctly identify time of day", {
  x <- as.POSIXct(c("2009-08-03 13:01:59", "2008-08-03 10:01:59"), tz = "UTC")
  expect_equal(am(x), c(FALSE, TRUE))
  expect_equal(pm(x), c(TRUE, FALSE))
})

test_that("am and pm handle various classes of date-time object", {
  x <- as.POSIXct(c("2009-08-03 13:01:59", "2008-08-03 10:01:59"), tz = "UTC")
  expect_equal(am(x), c(FALSE, TRUE))
  expect_equal(am(as.POSIXlt(x)), c(FALSE, TRUE))
  expect_equal(am(as.Date(x)), c(TRUE, TRUE))
})

Try the lubridate package in your browser

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

lubridate documentation built on Sept. 27, 2023, 5:07 p.m.