-
Notifications
You must be signed in to change notification settings - Fork 22
/
util.py
36 lines (25 loc) · 932 Bytes
/
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
import time
import os
import datetime
def timestamp_datetime(secs):
dt = time.strftime('%Y-%m-%dT%H:%M:%SZ', time.localtime(secs))
return dt
def datetime_timestamp(dt):
s = time.mktime(time.strptime(dt, '%Y-%m-%dT%H:%M:%SZ'))
return int(s)
def add_tz(dt):
return time.strftime('%Y-%m-%dT%H:%M:%SZ', time.strptime(dt, '%Y-%m-%d %H:%M:%S'))
def ensure_dir(dir_path):
if not os.path.exists(dir_path):
os.makedirs(dir_path)
def int_to_isoformat(_time):
days = _time // 86400
seconds = _time - days * 86400
hours = seconds // 3600
minutes = (seconds - 3600 * hours) // 60
seconds = seconds - 3600 * hours - minutes * 60
delta_time = datetime.timedelta(days=days, hours=hours, minutes=minutes, seconds=seconds)
cur_time = datetime.datetime(1970, 1, 1) + delta_time
cur_time = cur_time.isoformat()
cur_time += "Z" # mysterious time format
return cur_time