Skip to content

Commit e06f8c0

Browse files
committed
change format datetime function
1 parent a93608d commit e06f8c0

File tree

1 file changed

+7
-10
lines changed
  • stac_fastapi/core/stac_fastapi/core

1 file changed

+7
-10
lines changed

stac_fastapi/core/stac_fastapi/core/core.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -426,23 +426,20 @@ def _return_date(
426426

427427
return result
428428

429-
def _format_datetime_range(self, date_tuple: DateTimeType) -> str:
429+
def _format_datetime_range(self, date_tuple: str) -> str:
430430
"""
431-
Convert a tuple of datetime objects or None into a formatted string for API requests.
431+
Convert a datetime range into a formatted string.
432432
433433
Args:
434-
date_tuple (tuple): A tuple containing two elements, each can be a datetime object or None.
434+
date_tuple (str): A string containing two datetime values separated by a '/'.
435435
436436
Returns:
437437
str: A string formatted as 'YYYY-MM-DDTHH:MM:SS.sssZ/YYYY-MM-DDTHH:MM:SS.sssZ', with '..' used if any element is None.
438438
"""
439-
440-
def format_datetime(dt):
441-
"""Format a single datetime object to the ISO8601 extended format with 'Z'."""
442-
return dt.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z" if dt else ".."
443-
444-
start, end = date_tuple
445-
return f"{format_datetime(start)}/{format_datetime(end)}"
439+
start, end = date_tuple.split("/")
440+
start = start.replace("+01:00", "Z") if start else ".."
441+
end = end.replace("+01:00", "Z") if end else ".."
442+
return f"{start}/{end}"
446443

447444
async def get_search(
448445
self,

0 commit comments

Comments
 (0)