tests/testthat/test-convert_sequence.R

test_that("seq.mdate works for a straightforward CE sequence", {
  expect_equal(seq(as_messydate("2012-01-01"), as_messydate("2012-01-05")),
               seq(as.Date("2012-01-01"), as.Date("2012-01-05"), by = "days"))
})

test_that("seq.mdate uses the min/max of a range when 'to' is missing", {
  expect_equal(seq(as_messydate("2012-01-01..2012-01-05")),
               seq(as.Date("2012-01-01"), as.Date("2012-01-05"), by = "days"))
})

test_that("seq.mdate works within a single BCE year", {
  expect_equal(seq(as_messydate("-0010-01-01"), as_messydate("-0010-01-05")),
               c("-0010-01-01", "-0010-01-02", "-0010-01-03", "-0010-01-04",
                 "-0010-01-05"))
})

test_that("seq.mdate works across multiple BCE years", {
  r <- seq(as_messydate("-0012-12-28"), as_messydate("-0010-01-03"))
  expect_length(r, 372)
  expect_equal(r[1:3], c("-0012-12-28", "-0012-12-29", "-0012-12-30"))
  expect_equal(tail(r, 3), c("-0010-01-01", "-0010-01-02", "-0010-01-03"))
})

test_that("seq.mdate works across a BCE gap spanning several whole middle years", {
  r <- seq(as_messydate("-0006-01-01"), as_messydate("-0001-01-05"))
  expect_length(r, 1831)
  expect_equal(r[1:3], c("-0006-01-01", "-0006-01-02", "-0006-01-03"))
  expect_equal(tail(r, 3), c("-0001-01-03", "-0001-01-04", "-0001-01-05"))
})

test_that("seq.mdate crosses the BCE/CE boundary without a year zero", {
  r <- seq(as_messydate("-0001-12-28"), as_messydate("0001-01-05"))
  expect_equal(r, c("-0001-12-28", "-0001-12-29", "-0001-12-30", "-0001-12-31",
                     "0001-01-01", "0001-01-02", "0001-01-03", "0001-01-04",
                     "0001-01-05"))
})

test_that("seq.mdate accepts a non-day 'by'", {
  expect_equal(seq(as_messydate("2012-01-01"), as_messydate("2012-03-01"), by = "month"),
               seq(as.Date("2012-01-01"), as.Date("2012-03-01"), by = "month"))
})

test_that("seq.mdate supports sub-day sequences via a time-of-day 'by'", {
  expect_equal(
    seq(as_messydate("2019-03-01T09:00"), as_messydate("2019-03-01T12:00"),
        by = "hour"),
    c("2019-03-01 09:00:00", "2019-03-01 10:00:00",
      "2019-03-01 11:00:00", "2019-03-01 12:00:00"))
})

test_that("seq.mdate uses POSIXct once either endpoint carries a time, even with a day-based by", {
  r <- seq(as_messydate("2019-03-01T00:00:00"), as_messydate("2019-03-03T00:00:00"),
           by = "day")
  expect_equal(r, c("2019-03-01 00:00:00", "2019-03-02 00:00:00",
                     "2019-03-03 00:00:00"))
})

Try the messydates package in your browser

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

messydates documentation built on July 17, 2026, 1:07 a.m.