forked from Stepheny755/ClanStatsBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
73 lines (57 loc) · 1.66 KB
/
util.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
67
68
69
70
71
72
73
import numpy as np
import time,calendar
#Throw all the miscellaneous functions in here
class Util():
def __init__(self):
pass
def GTimeToSec(self,a):
t = time.strptime(a)
return calendar.timegm(t)
def SecToGTime(self,a):
t = time.gmtime(a)
return time.asctime(t)
def getGMTTime(self): #GMT == UTC
return int(calendar.timegm(time.gmtime()))
def getEarlier(self,a,b):
return a if a<b else b
def getLater(self,a,b):
return a if a>b else b
def ifPos(self,a):
if a > 0:
return "+"+str(a)
else:
return str(a)
def dToS(self,num):
return 24*60*60*num
def sToD(self,num):
return num/(60*60*24)
def countPreviousDays(self,days):
curtime = self.getGMTTime()
curtime -= self.dToS(days)
return self.SecToGTime(curtime)
def countWeekSec(self):
curtime = self.getGMTTime()
return curtime - self.dToS(7)
def countMonthSec(self):
curtime = self.getGMTTime()
return curtime - self.dToS(30)
def round3(self,input):
return float(format(input,'.3f'))
def round2(self,input):
return float(format(input,'.2f'))
if(__name__=='__main__'):
test = Util()
print(test.countWeekSec())
print(test.countMonthSec())
#print(test.sToD(134124))
#print(test.countPreviousDays(7))
#print(test.getLater(12322456,test.getGMTTime()))
#a = calendar.timegm(time.gmtime())
#print(a)
#b = test.SecToGTime(a)
#print(b)
# b is GMT/UTC, and c is localtime (PST)
#print()
#print(time.ctime(a))
#d = test.GTimeToSec(b)
#print(d)