Skip to content

Commit

Permalink
fix: convert date to datetime in local mode to compare with datetime (q…
Browse files Browse the repository at this point in the history
  • Loading branch information
joein authored and skvark committed Apr 8, 2024
1 parent c174176 commit c26b0d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 6 additions & 3 deletions qdrant_client/local/payload_filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from datetime import datetime, timezone
from typing import Any, List, Optional
from datetime import date, datetime, timezone
from typing import Any, List, Optional, Union

import numpy as np

Expand Down Expand Up @@ -108,7 +108,10 @@ def check_range(condition: models.Range, value: Any) -> bool:


def check_datetime_range(condition: models.DatetimeRange, value: Any) -> bool:
def make_condition_tz_aware(dt: Optional[datetime]) -> Optional[datetime]:
def make_condition_tz_aware(dt: Optional[Union[datetime, date]]) -> Optional[datetime]:
if isinstance(dt, date):
dt = datetime.combine(dt, datetime.min.time())

if dt is None or dt.tzinfo is not None:
return dt

Expand Down
8 changes: 6 additions & 2 deletions tests/fixtures/filters.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
from datetime import datetime, timedelta, timezone
from datetime import date, datetime, timedelta, timezone
from typing import Union

from qdrant_client.http import models
from tests.fixtures.payload import geo_points, random_real_word, random_signed_int
Expand Down Expand Up @@ -198,11 +199,14 @@ def datetime_range_field_condition() -> models.FieldCondition:
start_datetime = datetime(2000, 1, 1)
end_datetime = datetime(2001, 1, 31)

def random_datetime() -> datetime:
def random_datetime() -> Union[datetime, date]:
dt = start_datetime + timedelta(
seconds=random.randint(0, int((end_datetime - start_datetime).total_seconds())),
microseconds=random.randint(0, 999999),
)
if random.random() > 0.8:
return dt.date()

return dt.replace(tzinfo=timezone(offset=timedelta(hours=random.randint(-12, 12))))

lt = random_datetime()
Expand Down

0 comments on commit c26b0d4

Please sign in to comment.