-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
43 lines (33 loc) · 1.06 KB
/
utils.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
from datetime import datetime, date
class Date:
def __init__(self, d=None, format='%Y-%m-%d', mindate=date(1900, 1, 1)):
d = d if d else mindate
if isinstance(d, str):
if d == 'now' or d == 'today':
d = date.today()
else:
d = datetime.strptime(d, format).date()
elif isinstance(d, datetime):
d = d.date()
elif isinstance(d, Date):
d = d.date
elif isinstance(d, date):
pass
else:
raise ValueError()
self.date = d
def format(self, fmts='%Y-%m-%d'):
return datetime.strftime(self.date, fmts)
def __gt__(self, other):
return self.date > other.date
def __ge__(self, other):
return self.date >= other.date
def __lt__(self, other):
return self.date < other.date
def __le__(self, other):
return self.date <= other.date
def __eq__(self, other):
return self.date == other.date
def __repr__(self):
return self.format()
__str__ = __repr__