-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcVersion.py
64 lines (60 loc) · 2.08 KB
/
cVersion.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
58
59
60
61
62
63
import datetime, re;
### cVersion ###
grVersion = re.compile(r"^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2})$");
class cVersion(object):
@staticmethod
def foNew():
oNow = datetime.datetime.now(datetime.UTC);
return cVersion(oNow.year, oNow.month, oNow.day, oNow.hour, oNow.minute);
@staticmethod
def fo0FromString(s0Version):
if s0Version is None: return None;
oVersionMatch = grVersion.match(s0Version);
if oVersionMatch is None: return None;
return cVersion(*[int(s) for s in oVersionMatch.groups()]);
def __init__(oSelf, uYear, uMonth, uDay, uHour, uMinute):
assert uYear is not None, \
"uYear cannot be None";
assert uMonth is not None, \
"uMonth cannot be None";
assert uDay is not None, \
"uDay cannot be None";
assert uHour is not None, \
"uHour cannot be None";
assert uMinute is not None, \
"uMinute cannot be None";
oSelf.uYear = uYear;
oSelf.uMonth = uMonth;
oSelf.uDay = uDay;
oSelf.uHour = uHour;
oSelf.uMinute = uMinute;
@property
def __uComparableValue(oSelf):
return (
(
(
(
(
oSelf.uYear
) * 12 + oSelf.uMonth
) * 31 + oSelf.uDay
) * 24 + oSelf.uHour
) * 60 + oSelf.uMinute
);
def __eq__(oSelf, oVersion):
if oVersion.__class__ != cVersion: return NotImplemented;
return oSelf.__uComparableValue == oVersion.__uComparableValue;
def __ge__(oSelf, oVersion):
if oVersion.__class__ != cVersion: return NotImplemented;
return oSelf.__uComparableValue >= oVersion.__uComparableValue;
def __gt__(oSelf, oVersion):
if oVersion.__class__ != cVersion: return NotImplemented;
return oSelf.__uComparableValue > oVersion.__uComparableValue;
def __le__(oSelf, oVersion):
return not oSelf.__gt__(oVersion);
def __lt__(oSelf, oVersion):
return not oSelf.__ge__(oVersion);
def __ne__(oSelf, oVersion):
return not oSelf.__eq__(oVersion);
def __str__(oSelf):
return "%04d-%02d-%02d %02d:%02d" % (oSelf.uYear, oSelf.uMonth, oSelf.uDay, oSelf.uHour, oSelf.uMinute);