Skip to content

Commit

Permalink
Merge pull request #960 from weaviate/last_update_nano
Browse files Browse the repository at this point in the history
Support last_update_time in nanoseconds
  • Loading branch information
dirkkul authored Mar 15, 2024
2 parents fa0f4cd + e56302e commit 0f3ce2c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions weaviate/collections/queries/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ def __init__(
validate_arguments=self._validate_arguments,
)

def __retrieve_timestamp(
self,
timestamp: int,
) -> datetime.datetime:
# Handle the case in which last_update_time_unix is in nanoseconds or milliseconds, issue #958
if len(str(timestamp)) <= 13:
return datetime.datetime.fromtimestamp(timestamp / 1000, tz=datetime.timezone.utc)
else:
return datetime.datetime.fromtimestamp(timestamp / 1e9, tz=datetime.timezone.utc)

def __extract_metadata_for_object(
self,
add_props: "search_get_pb2.MetadataResult",
Expand All @@ -102,16 +112,12 @@ def __extract_metadata_for_object(
distance=add_props.distance if add_props.distance_present else None,
certainty=add_props.certainty if add_props.certainty_present else None,
creation_time=(
datetime.datetime.fromtimestamp(
add_props.creation_time_unix / 1000, tz=datetime.timezone.utc
)
self.__retrieve_timestamp(add_props.creation_time_unix)
if add_props.creation_time_unix_present
else None
),
last_update_time=(
datetime.datetime.fromtimestamp(
add_props.last_update_time_unix / 1000, tz=datetime.timezone.utc
)
self.__retrieve_timestamp(add_props.last_update_time_unix)
if add_props.last_update_time_unix_present
else None
),
Expand Down

0 comments on commit 0f3ce2c

Please sign in to comment.