* Fix FalkoDB tests * Add support for graph memory using Kuzu * Fix lints * Fix queries * Add tests * Add comments * Add more test coverage * Add mocked tests * Format * Add mocked tests II * Refactor community queries * Add more mocked tests * Refactor tests to always cleanup * Add more mocked tests * Update kuzu * Refactor how filters are built * Add more mocked tests * Refactor and cleanup * Fix tests * Fix lints * Refactor tests * Disable neptune * Fix * Update kuzu version * Update kuzu to latest release * Fix filter * Fix query * Fix Neptune query * Fix bulk queries * Fix lints * Fix deletes * Comments and format * Add Kuzu to the README * Fix bulk queries * Test all fields of nodes and edges * Fix lints * Update search_utils.py --------- Co-authored-by: Preston Rasmussen <109292228+prasmussen15@users.noreply.github.com>
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
"""
|
|
Copyright 2024, Zep Software, Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
"""
|
|
|
|
from datetime import datetime, timezone
|
|
|
|
|
|
def utc_now() -> datetime:
|
|
"""Returns the current UTC datetime with timezone information."""
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
def ensure_utc(dt: datetime | None) -> datetime | None:
|
|
"""
|
|
Ensures a datetime is timezone-aware and in UTC.
|
|
If the datetime is naive (no timezone), assumes it's in UTC.
|
|
If the datetime has a different timezone, converts it to UTC.
|
|
Returns None if input is None.
|
|
"""
|
|
if dt is None:
|
|
return None
|
|
|
|
if dt.tzinfo is None:
|
|
# If datetime is naive, assume it's UTC
|
|
return dt.replace(tzinfo=timezone.utc)
|
|
elif dt.tzinfo != timezone.utc:
|
|
# If datetime has a different timezone, convert to UTC
|
|
return dt.astimezone(timezone.utc)
|
|
|
|
return dt
|
|
|
|
|
|
def convert_datetimes_to_strings(obj):
|
|
if isinstance(obj, dict):
|
|
return {k: convert_datetimes_to_strings(v) for k, v in obj.items()}
|
|
elif isinstance(obj, list):
|
|
return [convert_datetimes_to_strings(item) for item in obj]
|
|
elif isinstance(obj, tuple):
|
|
return tuple(convert_datetimes_to_strings(item) for item in obj)
|
|
elif isinstance(obj, datetime):
|
|
return obj.isoformat()
|
|
else:
|
|
return obj
|