forked from SolidRun/SolidSense-MQTT
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mqtt_time.py
53 lines (34 loc) · 987 Bytes
/
mqtt_time.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
#-------------------------------------------------------------------------------
# Name: MQTTTimestamp
# Purpose:
#
# Author: Laurent Carré
#
# Created: 30/03/2020
# Copyright: (c) Laurent Carré Sterwen Technologies 2020
# Licence: <your licence>
#-------------------------------------------------------------------------------
import time
import datetime
class MQTT_Timestamp:
ts_format='iso'
def __init__(self):
pass
@staticmethod
def setFormat(ts_format):
MQTT_Timestamp.ts_format=ts_format
@staticmethod
def now():
return MQTT_Timestamp.format_ts(datetime.datetime.now())
@staticmethod
def fromEpoch(epoch):
t=datetime.datetime.fromtimestamp(epoch)
return MQTT_Timestamp.format_ts(t)
@staticmethod
def format_ts(ts):
if MQTT_Timestamp.ts_format == 'iso' :
return ts.isoformat(' ')
def main():
pass
if __name__ == '__main__':
main()