Skip to content

Commit

Permalink
enum_value as a class attribute, bytes as a property
Browse files Browse the repository at this point in the history
  • Loading branch information
jimkring committed Jan 24, 2024
1 parent d990f91 commit 00b3be3
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nptdms/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ class TdmsTimestamp(object):
:ivar ~.seconds: Seconds since the epoch as a signed integer
:ivar ~.second_fractions: A positive number of 2^-64 fractions of a second
"""
enum_value = 0x44

def __init__(self, seconds, second_fractions):
self.seconds = seconds
self.second_fractions = second_fractions
self.enum_value = 0x44
self.bytes = _struct_pack('<Qq', second_fractions, seconds)

def __repr__(self):
return "TdmsTimestamp({0}, {1})".format(self.seconds, self.second_fractions)
Expand Down Expand Up @@ -53,6 +52,10 @@ def as_datetime(self):
microseconds = (self.second_fractions / fractions_per_us)
return datetime(1904, 1, 1, 0, 0, 0) + timedelta(seconds=self.seconds) + timedelta(microseconds=microseconds)

@property
def bytes(self):
return _struct_pack('<Qq', self.second_fractions, self.seconds)


class TimestampArray(np.ndarray):
""" A numpy array of TDMS timestamps
Expand Down

0 comments on commit 00b3be3

Please sign in to comment.