Repository navigation
Create result requires that I provide UTC time #110
Description
Activity
Some initial notes from assessment:
- The
datastore-pythoncode calls to thehightime_datetime_to_protobufhelper conversion function to get thePrecisionTimestampneeded to send over the wire to the server. - The
hightime_datetime_to_protobufmethod inni-apis-pythoncalls toconvert_datetime. - The
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:- The N places in
datastore-pythonwhere we are callinghightime_datetime_to_protobuf(converting to a UTCHightimeeach time before calling this method) - Within
hightime_datetime_to_protobufinni-apis-python - Within the
convert_datetimelogic innitypes-python
CC @csjall
Reacted by Johann Scholtz- The
- changed the title
[-]Create result requires that I provide uct time[/-][+]Create result requires that I provide UTC time[/+]on Jul 10, 2026 datetime.now()returns a naive datetime, which is ambiguous: https://docs.python.org/3/library/datetime.htmlA 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.
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.
Trying to call
create_test_resultwith 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.AB#3746793