Skip to content

Instantly share code, notes, and snippets.

@duaneleem
Created March 30, 2018 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duaneleem/2382ef52055f1e6e68ec5a2407f3dbc2 to your computer and use it in GitHub Desktop.
Save duaneleem/2382ef52055f1e6e68ec5a2407f3dbc2 to your computer and use it in GitHub Desktop.
Adds a year to the current year.
/**
* @param {string} currentDate - The current date.
* @returns {string} Returns the new expiration date.
*/
private addYear = (currentDate: string): string => {
// Add a day to the current date.
let objDate = new Date(currentDate);
objDate.setDate(objDate.getDate() + 1);
// Format the month.
let numMonth = objDate.getMonth() + 1;
let strMonth = numMonth.toString();
if (numMonth < 10) { strMonth = "0" + numMonth; }
// Format the day.
let numDay = objDate.getDate();
let strDay = numDay.toString();
if (numDay < 10) { strDay = "0" + numDay; }
// Add a year to the current date.
let newExpiration =
(objDate.getFullYear() + 1).toString() + "-" +
strMonth + "-" +
strDay
; // strInvoiceNum
return newExpiration;
} // addYear(currentDate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment