x <- year_month_day(2019, 1:3)
# Set the day
set_day(x, 12:14)
# Set to the "last" day of the month
set_day(x, "last")
# Set to an invalid day of the month
invalid <- set_day(x, 31)
invalid
# Then resolve the invalid day by choosing the next valid day
invalid_resolve(invalid, invalid = "next")
# Cannot set a component two levels more precise than where you currently are
try(set_hour(x, 5))
Run the code above in your browser using DataLab