Created
December 16, 2021 03:22
-
-
Save abmathewks/09548ce6221ae05d9bc34dcff6c3dd0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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