Determine dates 30 and 31 days from now

 

var today = new Date();

$context.result.postMessage($context.result.LEVEL_INFO, "Today = "+today);

var currentMonth = today.getMonth() + 1;
currentMonth = currentMonth.toString();
//Prepend leading '0' if the Month is a single digit Month.
if(1 == currentMonth.length)
{
  currentMonth = "0"+currentMonth;
}
var currentDay = today.getDate();
currentDay = currentDay.toString();
if(1 == currentDay.length)
{
  currentDay = "0"+currentDay;
}
var currentYear = today.getFullYear();
var nextYear = currentYear + 1;
currentYear = currentYear.toString();
nextYear = nextYear.toString();
var current2DigitYear = currentYear.toString().substring(2);

//Calculate today in Milliseconds.
//We will take today in Milliseconds, and add the other two Millisecond calculations 
// to come up with the two future dates of 30 and 31 days.
var todayInMillis = Date.parse(today.toString());

//Calculate 30 days worth of time in Milliseconds.
var thirtyDaysInMillis = 1000 * 60 * 60 * 24 * 30;

//Calculate 31 days worth of time in Milliseconds.
var thirtyOneDaysInMillis = 1000 * 60 * 60 * 24 * 31;

//Calculate the Millisecond value of 30 days in the future.
var thirtyDaysInTheFutureInMillis = today.getTime() + thirtyDaysInMillis;

//Calculate the Millisecond value of 31 days in the future.
var thirtyOneDaysInTheFutureInMillis = today.getTime() + thirtyOneDaysInMillis;

//Create Date object for the 30 days in the future.  We need this so we can then 
// set this object with the calculated Millisecond value for 30 days in the future.
var thirtyDaysInTheFuture = new Date();
thirtyDaysInTheFuture.setTime(thirtyDaysInTheFutureInMillis);

// Create Date object for the 31 days in the future.  We need this so we can 
// then set this object with the calculated Millisecond value for 31 days in the future.
var thirtyOneDaysInTheFuture = new Date();
thirtyOneDaysInTheFuture.setTime(thirtyOneDaysInTheFutureInMillis);

//Calculate the date parts needed for the 30 days in the future date.
//We need to add 1 to the Month because JavaScript starts the month with 0 instead of 1.
var currentMonthPlus30Days = thirtyDaysInTheFuture.getMonth() + 1;
currentMonthPlus30Days = currentMonthPlus30Days.toString();
var currentDayPlus30Days = thirtyDaysInTheFuture.getDate();
currentDayPlus30Days = currentDayPlus30Days.toString();
var currentFullYearPlus30Days = thirtyDaysInTheFuture.getFullYear();
var current2DigitYearPlus30Days = currentFullYearPlus30Days.toString().substring(2);

//Calculate the date parts needed for the 31 days in the future date.
var currentMonthPlus31Days = thirtyOneDaysInTheFuture.getMonth() + 1;
currentMonthPlus31Days = currentMonthPlus31Days.toString();
var currentDayPlus31Days = thirtyOneDaysInTheFuture.getDate();
currentDayPlus31Days = currentDayPlus31Days.toString();
var currentFullYearPlus31Days = thirtyOneDaysInTheFuture.getFullYear();
var current2DigitYearPlus31Days = currentFullYearPlus31Days.toString().substring(2);

$prop.set("MessageClip", "currentMonth", currentMonth);
$prop.set("MessageClip", "currentDay", currentDay);
$prop.set("MessageClip", "currentYear", currentYear);
$prop.set("MessageClip", "nextYear", nextYear);
$prop.set("MessageClip", "current2DigitYear", current2DigitYear);

$prop.set("MessageClip", "currentMonthPlus30Days", currentMonthPlus30Days);
$prop.set("MessageClip", "currentDayPlus30Days", currentDayPlus30Days);
$prop.set("MessageClip", "current2DigitYearPlus30Days", current2DigitYearPlus30Days);

$prop.set("MessageClip", "currentMonthPlus31Days", currentMonthPlus31Days);
$prop.set("MessageClip", "currentDayPlus31Days", currentDayPlus31Days);
$prop.set("MessageClip", "current2DigitYearPlus31Days", current2DigitYearPlus31Days);