Published 2024-04-16

Add Days in Calender

Add days in calender by Amit kumar Giri

Amit Kumar Giri
                                
                                    Add Days In Calender
==================

def isLeapYear(year):
    return year % 4 == 0 and ( year % 100 != 0 or year % 400 == 0)

def getNumberOfDays (month, isLeapYear):
    months = {
        1: 31,  # January
        2: 29 if isLeapYear else 28,  # February
        3: 31,  # March
        4: 30,  # April
        5: 31,  # May
        6: 30,  # June
        7: 31,  # July
        8: 31,  # August
        9: 30,  # September
        10: 31,  # October
        11: 30,  # November
        12: 31   # December
    }
    return months[month]

user_date = "2024-04-16"
days = 10000

year, month, day = map (int, user_date.split("-"))

print("Input Date: " + str(day) + "-" + str(month) + "-"  + str(year))

actualYear = year
actualMonth = month
actualDay = day

remainingDays = days

if (isLeapYear(actualYear)):
    dyear = 366
else:
    dyear = 365

while (remainingDays > dyear):
    isCurrentLeapYear = isLeapYear(actualYear)

    if (isCurrentLeapYear):
        dyear = 366
    else:
        dyear = 365

    if remainingDays > dyear:
        remainingDays = remainingDays - dyear
        actualYear = actualYear + 1

daysInMonth = getNumberOfDays(month, isLeapYear(actualYear))

while (remainingDays > daysInMonth):
    remainingDays = remainingDays - daysInMonth
    actualMonth = actualMonth + 1
    if (actualMonth > 12):
        actualMonth = actualMonth - 12
        actualYear = actualYear + 1
    daysInMonth = getNumberOfDays(actualMonth, isLeapYear(actualYear))

actualDay = actualDay + remainingDays
if (actualDay > daysInMonth):
    actualDay = actualDay - daysInMonth
    actualMonth = actualMonth + 1
    if (actualMonth > 12):
        actualMonth = actualMonth - 12
        actualYear = actualYear + 1

print("Next date is: " + str(actualYear) + "-" + str(actualMonth) + "-" + str(actualDay))