tests/testthat/test-contract.R

d <- as_messydate(c("2001-01-01", "2001-01", "2001",
                    "2001-01-01..2001-02-02", "{2001-10-01,2001-10-04}",
                    "{2001-01,2001-02-02}", "-2000-01-01",
                    "2001-XX-01"))
dd <- as_messydate(c("2001-01-01", "2001-01-01..2001-01-31",
                     "2001-01-01..2001-12-31",
                     "2001-01-01..2001-02-02", "{2001-10-01,2001-10-04}",
                     "{2001-01-01..2001-01-31,2001-02-02}",
                     "-2000-01-01",
                     "2001-XX-01"))
e <- expand(d)

test_that("contract works properly", {
  expect_equal(contract(e), d)
  expect_equal(contract(e, collapse = FALSE), dd)
  expect_equal(contract("{2001-01-01, 2001-01-02, 2001-01-03}"),
               as_messydate("2001-01-01..2001-01-03"))
})

Try the messydates package in your browser

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

messydates documentation built on Jan. 22, 2023, 1:36 a.m.