# Calendar Days From Date Input
input days = 19;
input date = 20210912;
def yymmdd = date;
def year = Round(date / 10000, 0);
def Month = AbsValue(year - Round(date / 100, 0) / 100) * 100;
def Day = GetDayOfMonth(date);
def daysinmonth = if Month == 2
then 28
else if Month == 4 or Month == 6 or Month == 9 or Month == 11
then 30
else 31;
def newdays = if Month then (Day + days) else newdays[1];
def month_ = if Between(newdays, 1, daysinmonth)
then Month
else if Between(newdays, 1, daysinmonth * 2)
then Month + 1
else if Between(newdays, 1, daysinmonth * 3)
then Month + 2
else if Between(newdays, 1, daysinmonth * 4)
then Month + 3
else month_[1];
def newmonth = if month_ <= 13
then month_
else if month_ <= 25
then month_ - 12
else if month_ > 25
then month_ - 24
else newmonth[1];
def daysinmonth_ = if month_ == 2
then 28
else if month_ == 4 or month_ == 6 or month_ == 9 or month_ == 11
then 30
else 31;
def newyear = if month_ < 13
then year
else if month_ < 24
then year + 1
else if month_ > 24
then year + 2
else newyear[1];
def newday = if (newdays - daysinmonth) == 1
then 1
else if (newdays - daysinmonth) <= 0
then newdays
else if (newdays - daysinmonth * 2) <= 0
then newdays - (daysinmonth * 1)
else if (newdays - daysinmonth * 3) <= 0
then newdays - (daysinmonth * 2)
else if (newdays - daysinmonth * 4) <= 0
then newdays - (daysinmonth * 3)
else newday[1];
AddLabel(1, "Date Input: " + Month + "/" + Day + "/" + AsPrice(year), Color.YELLOW);
AddLabel(1, "Calendar Days Added: " + days, Color.WHITE);
AddLabel(1, "New Calendar Date: " + (if daysinmonth_ == 2 and newday[1] == 29
then 31 else newmonth) + "/"
+ newday + "/"
+ AsPrice(newyear), Color.YELLOW);
input debug = no;
AddLabel(debug, " " + month_ + " " + newdays + " " + daysinmonth + " " + newyear, Color.WHITE);