# date coercion
as_yearmonth(Sys.Date())
# POSIXt coercion
as_yearmonth(as.POSIXct("2019-03-04 01:01:01", tz = "America/New_York"))
# character coercion
as_yearmonth("2019-05-03")
# construction
yearmonth(year = 2000, month = 3)
# direct construction
d <- seq.Date(from = as.Date("1970-01-01"), by = "month", length.out = 10)
stopifnot(
identical(
as_yearmonth(d),
new_yearmonth(0:9)
)
)
Run the code above in your browser using DataLab