-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmdate.py
52 lines (41 loc) · 1.21 KB
/
mdate.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
from datetime import datetime,date
months={"jan":1,"feb":2,"mar":3,"apr":4,"may":5,"jun":6,"jul":7,"aug":8,"sep":9,"oct":10,"nov":11,"dec":12}
def convertdate(inputdate):
m=months.keys()
d=inputdate.lower()
for i in m:
if i in d:
#print(True)
fdate=d.replace(i,str(months[i]))
fdate=fdate.replace(" ","/")
return fdate
#convertdate("10 Jan 2024")
def getdate(epoch):
stringepoch=str(epoch)
if len(stringepoch)>10:
for i in range(len(stringepoch)-10):
epoch=epoch//10
return datetime.fromtimestamp(epoch)
def convertepoch(string):
epoch=datetime.strptime(str(string),"%d/%m/%Y")
convertedepoch=datetime.timestamp(epoch)
#print(convertedepoch)
return convertedepoch
def today():
todaytime=datetime.strptime(str(date.today()),"%Y-%m-%d")
todayepoch=datetime.timestamp(todaytime)
return todayepoch
def tillmaturity(mdate,tdate):
#print(mdate)
#print(tdate)
if(int(tdate)>int(mdate)):
return "Matured/Cancelled"
else:
epoch=int(mdate)-int(tdate)
return epoch
def daystillmaturity(seconds):
try:
days=int(seconds)/86400
return days
except:
return 0