Skip to content

fix: return UTC-aware datetimes for all SDK timestamps - #87

Merged
birkholz-cubert merged 4 commits into
developfrom
feature/update_datetime_to_utc_aware
Aug 19, 2026
Merged

fix: return UTC-aware datetimes for all SDK timestamps#87
birkholz-cubert merged 4 commits into
developfrom
feature/update_datetime_to_utc_aware

Conversation

@birkholz-cubert

Copy link
Copy Markdown
Collaborator

Summary

Fixes the issue reported in cubert-hyperspectral/cuvis.pyil#29 (the issue was filed against cuvis.pyil, but the cause lives here in cuvis.python).

measurement.capture_time returned a UTC time as a naive datetime (no tzinfo). Consumers could not tell the value was UTC and might interpret it as local time, corrupting timezone-aware processing.

Root cause

base_datetime was a naive datetime.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 a timedelta to a naive datetime stays naive.

Fix

Make the epoch base explicitly UTC-aware in both definitions:

base_datetime = datetime.datetime(1970, 1, 1, tzinfo=datetime.timezone.utc)

Fixing at the source corrects all four derived fields consistently with one change each: capture_time, factory_calibration (Measurement.py), GPSData.time and SensorInfo.readout_time (cuvis_aux.py). The UTC instant is unchanged - only the +00:00 label is added.

Tests

  • test_measurement_capture_time now also asserts tzinfo is not None and a zero UTC offset.
  • New test_measurement_capture_time_value asserts the exact expected value of the bundled test_mesu.cu3s fixture (2023-11-24 11:13:05.356000+00:00).

All 11 tests in tests/test_measurement.py pass.

Compatibility note

This is a behavioral change: comparing capture_time against a naive datetime (e.g. datetime.datetime.now()) now raises TypeError: 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.

@birkholz-cubert
birkholz-cubert force-pushed the feature/update_datetime_to_utc_aware branch 3 times, most recently from 8f3c009 to a7d0a51 Compare August 19, 2026 13:16
@birkholz-cubert
birkholz-cubert force-pushed the feature/update_datetime_to_utc_aware branch from a7d0a51 to 64de44d Compare August 19, 2026 13:51
@birkholz-cubert
birkholz-cubert changed the base branch from main to develop August 19, 2026 13:52
@birkholz-cubert birkholz-cubert changed the title fix: mark capture_time and other timestamps as UTC-aware fix: return UTC-aware datetimes for all SDK timestamps Aug 19, 2026
@birkholz-cubert
birkholz-cubert merged commit 3ad16e9 into develop Aug 19, 2026
4 checks passed
@birkholz-cubert
birkholz-cubert deleted the feature/update_datetime_to_utc_aware branch August 19, 2026 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant