Skip to content

Allow hightime_datetime_to_protobuf to accept non utc timezones - #395

Open
mjohanse-emr wants to merge 4 commits into
mainfrom
users/mjohanse/hightime_utc
Open

mjohanse-emr wants to merge 4 commits into
mainfrom
users/mjohanse/hightime_utc

Conversation

@mjohanse-emr

@mjohanse-emr mjohanse-emr commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

What does this Pull Request accomplish?

Adds a conversion to datetime.timezone.utc in hightime_datetime_to_protobuf to allow clients to pass non-utc timestamps to test result and step create methods.

A new helper method _hightime_datetime_to_utc has been added to handle pre-1970 values which are not supported by astimezone.

Why should this Pull Request be merged?

Fixes

What testing has been done?

  • Updated/added conversion unit tests to cover various datetime timezone scenarios.

Signed-off-by: Michael Johansen <michael.johansen@emerson.com>
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

  120 files  ± 0    120 suites  ±0   3m 14s ⏱️ -16s
  453 tests + 9    441 ✅ + 9   12 💤 ±0  0 ❌ ±0 
4 530 runs  +90  4 376 ✅ +90  154 💤 ±0  0 ❌ ±0 

Results for commit 34fc396. ± Comparison against base commit c1334a6.

♻️ This comment has been updated with latest results.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Naïve datetimes are host-dependent, and the test does not exercise a non-UTC timezone.

2 open findings
What changed in this PR

Normalizes hightime.datetime values to UTC before protobuf conversion.

Changes:

  • Adds UTC normalization before conversion.
  • Updates conversion unit coverage.
File Description
precision_timestamp_conversion.py Adds UTC normalization.
test_precision_timestamp_conversion.py Updates timestamp conversion test.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/ni.protobuf.types/tests/unit/test_precision_timestamp_conversion.py Outdated

def test___hightime_datetime___convert___valid_precision_timestamp() -> None:
ht_datetime = ht.datetime(year=2020, month=1, day=1, hour=5, minute=26, tzinfo=dt.timezone.utc)
ht_datetime = ht.datetime(year=2020, month=1, day=1, hour=5, minute=26)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing a single naive timestamp is inadequate. Please test:

  • Dates before 1904
  • Dates between 1904 and 1970
  • Dates after 1970
  • Fixed-offset timezones
  • Real timezones like ZoneInfo("America/Chicago"). Add a Windows-only test dependency for this: tzdata = { version = "*", markers = "sys_platform == 'win32'" }
  • The local timezone returned from the tzlocal package.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Daylight saving time

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The NI-BTF epoch (NI-DAQmx uses this as a sentinel value to denote unset timestamps)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should now be adequate testing. For the NI-BTF epoch, the test specifies the epoch as UTC, so it skips the actual conversion. If there's another way I should specify the epoch, please let me know. Perhaps adding a timezone offset and the corresponding hour value when creating the datetime?

…datetimes. Add more unit testing.

Signed-off-by: Michael Johansen <michael.johansen@emerson.com>
Signed-off-by: Michael Johansen <michael.johansen@emerson.com>
Signed-off-by: Michael Johansen <michael.johansen@emerson.com>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you fixing this in ni.protobuf.types?

nitypes is where the conversion between bintime and hightime lives.

nidatastore is the API that needs this functionality.

Are waveform timestamps the reason you want to do this in a lower-level component rather than nidatastore?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based the location of my fix on @csjall 's comment here:
ni/datastore-python#116 (comment)

The main reason I didn't make the change in nidatastore was to reduce code duplication. Waveform timestamps weren't a major factor in this decision.

I didn't consider making the change in nitypes. If that is the better place to make this change, I can abandon this PR.

@mjohanse-emr
mjohanse-emr requested a review from bkeryan October 8, 2026 16:26

This branch has not been deployed

No deployments
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.

3 participants