I have a function called date_has_passed
where it takes in both a Date-type value and a boolean value as its two arguments. Based on the given date, it calculates the difference between that date and today's date to determine whether or not if that given date has already occurred this year.
#7.
date_has_passed <- function(date, ignore_year) {
today <- Sys.Date()
difference <- today - date
if (difference < 0) {
true_or_false <- FALSE
} else if (difference > 0) {
true_or_false <- TRUE
} else {
true_or_false <- "It is the same day as the given date"
}
true_or_false
}
#8.
date_has_passed(as.Date("2020-01-23"), TRUE) #date has not occurred test case
date_has_passed(as.Date("2021-01-19"), TRUE) #ignore_year test case
Right now I want to add in an ignore_year argument where if the argument is passed a boolean value of TRUE, then the function will return whether the date has passed this year, regardless of the year passed for the argument date
EX: if the argument date is "2021-01-19" and the passed boolean value is TRUE, then the function should return TRUE in that the date has been passed despite it being a year away from the current date.