Skip to content

Commit 5e66824

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
fix: ensure min, max dates have correct format
1 parent 375bb8d commit 5e66824

File tree

1 file changed

+6
-6
lines changed
  • stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database

1 file changed

+6
-6
lines changed

stac_fastapi/sfeos_helpers/stac_fastapi/sfeos_helpers/database/datetime.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ def return_date(
5353
if "/" in interval:
5454
parts = interval.split("/")
5555
result["gte"] = (
56-
parts[0] if parts[0] != ".." else MIN_DATE_NANOS.isoformat() + "Z"
56+
parts[0] if parts[0] != ".." else MIN_DATE_NANOS.isoformat()
5757
)
5858
result["lte"] = (
5959
parts[1]
6060
if len(parts) > 1 and parts[1] != ".."
61-
else MAX_DATE_NANOS.isoformat() + "Z"
61+
else MAX_DATE_NANOS.isoformat()
6262
)
6363
else:
6464
converted_time = interval if interval != ".." else None
@@ -90,7 +90,7 @@ def return_date(
9090
start_utc = MIN_DATE_NANOS
9191
elif start_utc > MAX_DATE_NANOS:
9292
start_utc = MAX_DATE_NANOS
93-
result["gte"] = start_utc.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
93+
result["gte"] = start_utc.isoformat().replace("+00:00", "Z")
9494
if end:
9595
end_utc = (
9696
end.astimezone(timezone.utc)
@@ -101,7 +101,7 @@ def return_date(
101101
end_utc = MIN_DATE_NANOS
102102
elif end_utc > MAX_DATE_NANOS:
103103
end_utc = MAX_DATE_NANOS
104-
result["lte"] = end_utc.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
104+
result["lte"] = end_utc.isoformat().replace("+00:00", "Z")
105105

106106
return result
107107

@@ -131,9 +131,9 @@ def return_date(
131131
start, end = interval
132132
# Ensure datetimes are converted to UTC and formatted with 'Z'
133133
if start:
134-
result["gte"] = start.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
134+
result["gte"] = start_utc.isoformat().replace("+00:00", "Z")
135135
if end:
136-
result["lte"] = end.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
136+
result["lte"] = end_utc.isoformat().replace("+00:00", "Z")
137137

138138
return result
139139

0 commit comments

Comments
 (0)