|
13 | 13 | DoubleAnalogWaveform, |
14 | 14 | WaveformAttributeValue, |
15 | 15 | ) |
16 | | -from nitypes.bintime import DateTime, TimeDelta |
| 16 | +from nitypes.bintime import DateTime, TimeValueTuple |
17 | 17 | from nitypes.scalar import Scalar |
18 | 18 | from nitypes.waveform import AnalogWaveform, ExtendedPropertyDictionary, NoneScaleMode, Timing |
19 | 19 | from typing_extensions import TypeAlias |
@@ -53,8 +53,7 @@ def to_protobuf_message( |
53 | 53 | else: |
54 | 54 | precision_timestamp = PrecisionTimestamp(seconds=0, fractional_seconds=0) |
55 | 55 |
|
56 | | - # TODO: Replace with .has_sample_interval once available. |
57 | | - if python_value.timing._sample_interval is not None: |
| 56 | + if python_value.timing.has_sample_interval: |
58 | 57 | time_interval = python_value.timing.sample_interval.total_seconds() |
59 | 58 | else: |
60 | 59 | time_interval = 0 |
@@ -137,18 +136,13 @@ def protobuf_message(self) -> Type[PrecisionTimestamp]: |
137 | 136 |
|
138 | 137 | def to_protobuf_message(self, python_value: DateTime) -> PrecisionTimestamp: |
139 | 138 | """Convert the Python DateTime to a protobuf PrecisionTimestamp.""" |
140 | | - time_delta: TimeDelta = DateTime._to_offset(python_value._to_datetime_datetime()) |
141 | | - # TODO: Replace with Datetime.to_tuple once available |
142 | | - ticks = TimeDelta._to_ticks(time_delta.total_seconds()) |
143 | | - seconds = ticks >> 64 |
144 | | - frac_seconds = ticks & ((1 << 64) - 1) |
145 | | - return self.protobuf_message(seconds=seconds, fractional_seconds=frac_seconds) |
| 139 | + seconds, fractional_seconds = python_value.to_tuple() |
| 140 | + return self.protobuf_message(seconds=seconds, fractional_seconds=fractional_seconds) |
146 | 141 |
|
147 | 142 | def to_python_value(self, protobuf_value: PrecisionTimestamp) -> DateTime: |
148 | 143 | """Convert the protobuf PrecisionTimestamp to a Python DateTime.""" |
149 | | - ticks = (protobuf_value.seconds << 64) | protobuf_value.fractional_seconds |
150 | | - # TODO: Replace with Datetime.from_tuple() once available |
151 | | - return DateTime.from_ticks(ticks) |
| 144 | + time_value_tuple = TimeValueTuple(protobuf_value.seconds, protobuf_value.fractional_seconds) |
| 145 | + return DateTime.from_tuple(time_value_tuple) |
152 | 146 |
|
153 | 147 |
|
154 | 148 | class ScalarConverter(Converter[Scalar[_AnyScalarType], scalar_pb2.ScalarData]): |
|
0 commit comments