Description : This is calender project I have made using python. It contains a calender class which has many property that returns value based on if year is lear year, what is the first day of the month, etc. When program is first launched it ask user about year and month of calender they want to display, after getting these input from user, they are presented with accurate calender.
- In order to make this software more expandable in future and easy to manage I have decided to create a class first called Calender in file called custom_calender.py
- Then in constructor I have created few variables such as list of month names, list of week names and also a list which shows how many days each month have (for simplicity I have used 28 for febuary but have created new function which return 29 if it detects a leap year).
- I made a function later which returns first day of the year when year is provided. It is common knowledge that if for example today is January 1st 2019 which is on Tuesday, then on same date next year January 1st 2020 it will be Wednesday. It means it jumps a day on same exact date in next year and jumps 2 day if there is a leap year.
def findFirstDayOfYear(self):
start = 1900
curr_day = 0
for i in range(start, self.year+1):
if self.isLeapYear(i-1):
curr_day += 2
else:
curr_day += 1
return self.dayChecker(curr_day)
def isLeapYear(self, year):
if year % 4 == 0 and not year % 100 == 0:
return True
elif year % 4 == 0 and year % 100 == 0 and year % 400 == 0:
return True
elif year % 4 == 0 and year % 100 == 0:
return False
else:
return False
Made a function which prints a month based on user input after all calculations are done.
def printCalenderMonth(self):
i = 1
step = 0
while i <= self.returnMonthDay(self.month-1, self.year):
# print(self.findStartDayOfMonth(self.month))
if step > self.findStartDayOfMonth(self.month):
if i < 10:
print(" {}".format(i), end=" ")
else:
print(" {}".format(i), end=" ")
if step % 7 == 0:
print("\n")
i += 1
else:
print(" ", end=" ")
if step % 7 == 0:
print("\n")
step += 1