-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtempo.py
39 lines (26 loc) · 876 Bytes
/
tempo.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
# tempo -- time and date module
import debugtools as dbg
import datetime
import time
# in (UTC)
Epoch = datetime.datetime(year=1970, month = 1, day=1)
# takes Unix timestamp as input and returns a timedate object
# does not take timezones into consideration
def fromUnixToDateTime(unx):
delta = datetime.timedelta(seconds=unx)
return Epoch + delta
# return the current Unix timestamp
def getCurrentTimestamp():
return int(time.time())
# returns a string representing time (hour and minues)
def timeToStr(t):
return " {:02d}:{:02d}".format(t.hour, t.minute)
# returns a string representing date and time with precision of one minute
def dateTimeToStr(d):
return d.date().isoformat() + " {:02d}:{:02d}".format(d.hour, d.minute)
if __name__ == "__main__":
timestamp = time.time()
dt = fromUnixToDateTime(timestamp)
print(dt)
t = dt.time()
print(type(t), t)