You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Create result requires that I provide UTC time #110
Trying to call create_test_result with the following code will throw an error that the start and end times have to be in utc. The python API should allow me to provide local time and internally convert to utc.
The datastore-python code calls to the hightime_datetime_to_protobuf helper conversion function to get the PrecisionTimestamp needed to send over the wire to the server.
The hightime_datetime_to_protobuf method in ni-apis-pythoncalls to convert_datetime.
The convert_datetime method in nitypes-pythoncalls to construct a nitypes.bintime.DateTime representing the Hightime.
nitypes.bintime.DateTimeonly supports UTC. Consequently, the call in the constructor to _to_offset throws an error about the timezone needing to be UTC.
Given that nitypes.bintime.DateTime is only intended to support UTC, then I suppose that leaves three main options for where to make a change:
The N places in datastore-python where we are calling hightime_datetime_to_protobuf (converting to a UTC Hightime each time before calling this method)
Within hightime_datetime_to_protobuf in ni-apis-python
Within the convert_datetime logic in nitypes-python
A naive object does not contain enough information to unambiguously locate itself relative to other date/time objects. Whether a naive object represents Coordinated Universal Time (UTC), local time, or time in some other time zone is purely up to the program, just like it is up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand and to work with, at the cost of ignoring some aspects of reality.
Converting naive datetimes to UTC requires making a choice about whether they are in UTC or local time. Once the API has shipped, it's difficult to revisit this decision. It also makes the API easier to misuse: if your code disagrees about what timezone naive datetimes are in, the conversion introduces a time offset.
Activity
hunter-ni commentedon Feb 23, 2026
Some initial notes from assessment:
datastore-pythoncode calls to thehightime_datetime_to_protobufhelper conversion function to get thePrecisionTimestampneeded to send over the wire to the server.hightime_datetime_to_protobufmethod inni-apis-pythoncalls toconvert_datetime.convert_datetimemethod innitypes-pythoncalls to construct anitypes.bintime.DateTimerepresenting theHightime.nitypes.bintime.DateTimeonly supports UTC. Consequently, the call in the constructor to _to_offset throws an error about the timezone needing to be UTC.Given that
nitypes.bintime.DateTimeis only intended to support UTC, then I suppose that leaves three main options for where to make a change:datastore-pythonwhere we are callinghightime_datetime_to_protobuf(converting to a UTCHightimeeach time before calling this method)hightime_datetime_to_protobufinni-apis-pythonconvert_datetimelogic innitypes-pythonCC @csjall
[-]Create result requires that I provide uct time[/-][+]Create result requires that I provide UTC time[/+]bkeryan commentedon Oct 8, 2026
datetime.now()returns a naive datetime, which is ambiguous: https://docs.python.org/3/library/datetime.htmlConverting naive datetimes to UTC requires making a choice about whether they are in UTC or local time. Once the API has shipped, it's difficult to revisit this decision. It also makes the API easier to misuse: if your code disagrees about what timezone naive datetimes are in, the conversion introduces a time offset.
Also note that the
protobufpackage'sFromDatetimemethod has a comment saying it treats naive datetimes as UTC, which is the opposite of what your sample code is expecting: https://github.com/protocolbuffers/protobuf/blob/6c177b61dfd225c06840d13ffd789ba6210dc2cb/python/google/protobuf/internal/well_known_types.py#L271Please consider not accepting naive datetimes and throwing an exception instead.