-
Notifications
You must be signed in to change notification settings - Fork 0
/
journosDate.py
66 lines (57 loc) · 1.26 KB
/
journosDate.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
64
65
66
import datetime
def nextDate(date):
d=datetime.date(int(date.split('/')[2]), int(date.split('/')[0]), int(date.split('/')[1]))
n=d+datetime.timedelta(1)
return datetimeToDate(n)
def prevDate(date):
d=datetime.date(int(date.split('/')[2]), int(date.split('/')[0]), int(date.split('/')[1]))
n=d+datetime.timedelta(-1)
return datetimeToDate(n)
def today():
return datetimeToDate(datetime.date.today())
def datetimeToDate(dt):
ret = str(dt.month)+"/"+str(dt.day)+"/"+str(dt.year)
return formatDate(ret)
def formatDate(s):
try:
y=datetime.date.today().year
if len(s.split("/")) > 2:
y=int(s.split("/")[2])
m=int(s.split("/")[0])
d=int(s.split("/")[1])
ret=""
if m<10:
ret+="0"+str(m)
else:
ret+=str(m)
ret+="/"
if d<10:
ret+="0"+str(d)
else:
ret+=str(d)
ret+="/"
if y<100:
ret+="20"+str(y)
else:
ret+=str(y)
return ret
except:
return -1
def min(_date1, _date2):
date1=_date1.split("/")
date2=_date2.split("/")
if date1[2] < date2[2]:
return _date1
elif date1[2] > date2[2]:
return _date2
elif date1[0] < date2[0]:
return _date1
elif date1[0] > date2[0]:
return _date2
elif date1[1] < date2[1]:
return _date1
elif date1[1] > date2[1]:
return _date2
else:
# arbitrary - they are equal
return _date1