-
Notifications
You must be signed in to change notification settings - Fork 0
/
Appointment.py
57 lines (46 loc) · 1.7 KB
/
Appointment.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import datetime
import functools
from builtins import property
@functools.total_ordering
class Appointment:
def __init__(self, start, end, title, details):
self._start = start
self._end = end
self._title = title
self._details = details
start = property(lambda o: o._start)
end = property(lambda o: o._end)
def __sub__(self, other):
return self.start - other.start
def __eq__(self, other):
return (self.start, self.end) == (other.start, other.end)
def __lt__(self, other):
if isinstance(other, datetime.datetime):
return self.start < other
return self.start < other.start
def __gt__(self, other):
if isinstance(other, datetime.datetime):
return self.start > other
return self.start > other.start
def clashes_with(self, other):
if self.start < other.start < self.end:
return True
if self.start < other.end < self.end:
return True
return False
def __str__(self):
strt = self.start.strftime('%d/%m/%Y %H:%m:%S')
end = self.end.strftime('%d/%m/%Y %H:%m:%S')
return strt + ' -- ' + end + ' : ' + self._title
def main():
strt = datetime.datetime(2017, 10, 28, 10, 30, 12)
end = datetime.datetime(2017, 10, 28, 11, 30, 12)
a = Appointment(strt, end, 'Appnt1', 'an example of an appointment')
strt = datetime.datetime(2017, 10, 28, 11, 30, 12)
end = datetime.datetime(2017, 10, 28, 12, 30, 12)
b = Appointment(strt, end, 'Appnt2', 'another example of an appointment')
print(a.clashes_with(b), a < b)
print(b-a)
print(sorted([a,b],reverse=True)[0])
if __name__ == "__main__":
main()