fix: mark capture_time and other timestamps as UTC-aware#87
Open
birkholz-cubert wants to merge 1 commit into
Open
fix: mark capture_time and other timestamps as UTC-aware#87birkholz-cubert wants to merge 1 commit into
birkholz-cubert wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the issue reported in cubert-hyperspectral/cuvis.pyil#29 (the issue was filed against
cuvis.pyil, but the cause lives here incuvis.python).measurement.capture_timereturned a UTC time as a naivedatetime(notzinfo). Consumers could not tell the value was UTC and might interpret it as local time, corrupting timezone-aware processing.Root cause
base_datetimewas a naivedatetime.datetime(1970, 1, 1). The SDK derives timestamps by adding a millisecond offset (milliseconds since the Unix epoch, i.e. UTC) to it, and adding atimedeltato a naive datetime stays naive.Fix
Make the epoch base explicitly UTC-aware in both definitions:
Fixing at the source corrects all four derived fields consistently with one change each:
capture_time,factory_calibration(Measurement.py),GPSData.timeandSensorInfo.readout_time(cuvis_aux.py). The UTC instant is unchanged - only the+00:00label is added.Tests
test_measurement_capture_timenow also assertstzinfo is not Noneand a zero UTC offset.test_measurement_capture_time_valueasserts the exact expected value of the bundledtest_mesu.cu3sfixture (2023-11-24 11:13:05.356000+00:00).All 11 tests in
tests/test_measurement.pypass.Compatibility note
This is a behavioral change: comparing
capture_timeagainst a naive datetime (e.g.datetime.datetime.now()) now raisesTypeError: can't compare offset-naive and offset-aware datetimes. This is the correct behavior, but downstream code relying on naive comparisons will need to attach a tzinfo.