Skip to content

Instantly share code, notes, and snippets.

@abmathewks
Created December 16, 2021 03:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abmathewks/09548ce6221ae05d9bc34dcff6c3dd0b to your computer and use it in GitHub Desktop.
Save abmathewks/09548ce6221ae05d9bc34dcff6c3dd0b to your computer and use it in GitHub Desktop.
AddMonths <- function(DATE_VAL,
ADD_N = NULL,
DEBUG = TRUE){
if(DEBUG) message("AddMonths: Function initialized \n")
if(!lubridate::is.Date(DATE_VAL)){
stop("AddMonths: DATE_VAL is not a date format \n")
}
if(is.null(ADD_N)){
stop("AddMonths: Argument ADD_N is missing \n")
}
FUNCTION_OUTPUT <- list()
FUNCTION_OUTPUT[["ORIGINAL_DATE"]] <- DATE_VAL
FUNCTION_OUTPUT[["ADD_N"]] <- ADD_N
new_date <- seq(DATE_VAL, by = paste(ADD_N, "months"), length = 2)[2]
if(DEBUG) message("AddMonths: Collecting final output \n")
FUNCTION_OUTPUT[["NEW_DATE"]] <- new_date
if(!is.null(new_date) || !is.na(new_date)){
if(DEBUG) message("AddMonths: Function run completed \n")
return(FUNCTION_OUTPUT)
} else {
stop("AddMonths: Dates not created \n")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment