tests/testthat/test_elapsed.R

library(statar)
library(lubridate)
context("dates")

date <- mdy(c("04/03/1992", "01/04/1992", "03/15/1992"))  

test_that("class is maintained", {
datem <- as.monthly(date)
expect_equal(class(datem + 1), "monthly")
expect_equal(class(seq(datem[1], datem[2])), "monthly")
})

test_that("conversion works", {
	expect_equal(as.POSIXlt(as.monthly(date)), as.POSIXlt(floor_date(date, "month")))
	expect_equal(as.Date(as.monthly(date)), as.Date(floor_date(date, "month") ))
	})


test_that("rounding", {
	expect_equal(as.Date(as.monthly(mdy("02/28/1960"))), as.Date(mdy("02/01/1960")))
	expect_equal(as.Date(as.quarterly(mdy("02/28/1960"))),as.Date(mdy("01/01/1960")))
	})

Try the statar package in your browser

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

statar documentation built on Aug. 19, 2023, 5:09 p.m.