# date coercion
as_month(Sys.Date(), n = 2)
# character coercion
as_month("2019-05-03", n = 4)
# POSIXt coercion
as_month(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"), n = 2)
# direct construction
d <- seq.Date(from = as.Date("1970-03-01"), by = "2 month", length.out = 10)
stopifnot(
identical(
as_month(d, n = 2),
new_month(1:10, 2)
)
)
Run the code above in your browser using DataLab