-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_unit.py
More file actions
57 lines (46 loc) · 1.11 KB
/
time_unit.py
File metadata and controls
57 lines (46 loc) · 1.11 KB
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
from enum import Enum
from datetime import datetime
class TimeUnit(Enum):
MILLISECOND = 1
SECOND = 2
MINUTE = 3
HOUR = 4
DAY = 5
class TimeUtil:
@staticmethod
def to_millis(time, unit):
if unit == TimeUnit.SECOND:
return time * 1000
elif unit == TimeUnit.MINUTE:
return time * 1000 * 60
elif unit == TimeUnit.HOUR:
return time * 1000 * 60 * 60
elif unit == TimeUnit.DAY:
return time * 1000 * 60 * 60 * 24
@staticmethod
def from_millis(millis):
pass
@staticmethod
def to_datetime(input):
datetime_obj = datetime.strptime(input, '%d-%m-%Y %H:%M:%S')
return datetime_obj
@staticmethod
def sqlite_to_datetime(input):
datetime_obj = datetime.strptime(input, '%Y-%m-%d %H:%M:%S')
return datetime_obj
@staticmethod
def now():
return datetime.now()
@staticmethod
def sanitize_time_input(input):
result = ' '.join(input.split('T'))
result += ':00'
return result
@staticmethod
def datetime_to_string(date):
return date.strftime("%Y-%m-%dT%H:%M")
@staticmethod
def desanitize_time_input(sanitized):
result = sanitized[0:-3]
result = 'T'.join(result.split(' '))
return result