# Year precision vector
x <- year_week_day(2019:2023)
# Promote to week precision by setting the week
# (Note that some weeks have 52 weeks, and others have 53)
x <- set_week(x, "last")
x
# Set to an invalid week
invalid <- set_week(x, 53)
invalid
# Here are the invalid ones (they only have 52 weeks)
invalid[invalid_detect(invalid)]
# Resolve the invalid dates by choosing the previous/next valid moment
invalid_resolve(invalid, invalid = "previous")
invalid_resolve(invalid, invalid = "next")
Run the code above in your browser using DataLab