Fix more vars, and re-worked Timestamp problems
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import secrets
|
||||
import string
|
||||
|
||||
from google.cloud.firestore_v1 import GeoPoint
|
||||
from datetime import datetime
|
||||
from google.cloud.firestore_v1 import GeoPoint, DocumentReference
|
||||
|
||||
from shared.firebase import get_db
|
||||
from shared.exceptions import NotFoundError
|
||||
@@ -39,14 +40,15 @@ def _ensure_unique_serial(db) -> str:
|
||||
|
||||
|
||||
def _convert_firestore_value(val):
|
||||
"""Convert Firestore-specific types (Timestamp, GeoPoint) to strings."""
|
||||
if hasattr(val, "seconds") and hasattr(val, "nanos"):
|
||||
# Firestore Timestamp → ISO string
|
||||
from datetime import datetime, timezone
|
||||
dt = datetime.fromtimestamp(val.seconds + val.nanos / 1e9, tz=timezone.utc)
|
||||
return dt.strftime("%d %B %Y at %H:%M:%S UTC")
|
||||
"""Convert Firestore-specific types (Timestamp, GeoPoint, DocumentReference) to strings."""
|
||||
if isinstance(val, datetime):
|
||||
# Firestore DatetimeWithNanoseconds is a datetime subclass
|
||||
return val.strftime("%d %B %Y at %H:%M:%S UTC%z")
|
||||
if isinstance(val, GeoPoint):
|
||||
return f"{val.latitude}° N, {val.longitude}° E"
|
||||
if isinstance(val, DocumentReference):
|
||||
# Store the document path (e.g. "users/abc123")
|
||||
return val.path
|
||||
return val
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user