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:
parent
45d5f9b262
commit
97709ae84e
1 changed files with 11 additions and 1 deletions
|
@ -1,14 +1,24 @@
|
||||||
import re
|
import re
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
class Timestamp:
|
class Timestamp:
|
||||||
"""Parsing the VILLASnode human-readable timestamp format"""
|
"""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.seconds = seconds
|
||||||
self.nanoseconds = nanoseconds
|
self.nanoseconds = nanoseconds
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
self.sequence = sequence
|
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
|
@classmethod
|
||||||
def parse(self, ts):
|
def parse(self, ts):
|
||||||
m = re.match('(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts)
|
m = re.match('(\d+)(?:\.(\d+))?([-+]\d+(?:\.\d+)?(?:e[+-]?\d+)?)?(?:\((\d+)\))?', ts)
|
||||||
|
|
Loading…
Add table
Reference in a new issue