1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-30 00:00:11 +01:00

python: create timestamps using datetime.utcnow()

This commit is contained in:
Steffen Vogel 2020-06-07 18:13:29 +01:00 committed by Steffen Vogel
parent 45d5f9b262
commit 97709ae84e

View file

@ -1,14 +1,24 @@
import re
from datetime import datetime
class Timestamp:
"""Parsing the VILLASnode human-readable timestamp format"""
def __init__(self, seconds = 0, nanoseconds = None, offset = None, sequence = None):
def __init__(self, seconds=None, nanoseconds=None, offset=None, sequence=None):
self.seconds = seconds
self.nanoseconds = nanoseconds
self.offset = offset
self.sequence = sequence
@classmethod
def now(self, offset=None, sequence=None):
n = datetime.utcnow()
secs = int(n.timestamp())
nsecs = 1000 * n.microsecond
return Timestamp(seconds=secs, nanoseconds=nsecs, offset=offset, sequence=sequence)
@classmethod
def parse(self, ts):
m = re.match('(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts)