-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate_class.py
More file actions
43 lines (40 loc) · 1.34 KB
/
Date_class.py
File metadata and controls
43 lines (40 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Date:
'''class to represent a date'''
def __init__(self,month,day,year):
'''Date(month,day,year) -> Date'''
self.month = month
self.day = day
self.year = year
def __str__(self):
'''str(Date) -> str
returns date in readable format'''
# list of strings for the months
months = ['','Jan','Feb','Mar','Apr','May','Jun','Jul',
'Aug','Sep','Oct','Nov','Dec']
output = months[self.month] + ' ' # month
output += str(self.day) + ', ' # day
output += str(self.year)
return output
def go_to_next_day(self):
'''Date.go_to_next_day()
advances the date to the next day'''
# list with the days in the month
daysInMonth = [0,31,28,31,30,31,30,31,31,30,31,30,31]
# check for leap year
isLeapYear = self.year%4
if isLeapYear == 0:
daysInMonth[2] += 1
if self.day == daysInMonth[self.month]:
if month == 12:
self.month = 1
self.day = 1
self.year += 1
return __str__(self)
else:
self.month += 1
self.day = 1
self.year = year
return __str__(self)
else:
self.day += 1
return __str__(self)