-
-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathmydate.py
More file actions
34 lines (27 loc) · 917 Bytes
/
Copy pathmydate.py
File metadata and controls
34 lines (27 loc) · 917 Bytes
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
def other_method(val):
print(f"other_method: {val}")
class Date(object):
def __init__(self, Year, Month, Day):
self.year = Year
self.month = Month
self.day = Day
def __str__(self):
return 'Date({}, {}, {})'.format(self.year, self.month, self.day)
@classmethod
def from_str(class_object, date_str):
'''Call as
d = Date.from_str('2013-12-30')
'''
print(f"from_str: {class_object}")
year, month, day = map(int, date_str.split('-'))
other_method(43)
if class_object.is_valid_date(year, month, day):
return class_object(year, month, day)
else:
raise Exception("Invalid date")
@staticmethod
def is_valid_date(year, month, day):
if 0 <= year <= 3000 and 1 <= month <= 12 and 1 <= day <= 31:
return True
else:
return False