Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions stac_fastapi/core/stac_fastapi/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,13 @@ async def get_search(
"q": q,
}

print("datetime:", datetime)

if datetime:
base_args["datetime"] = format_datetime_range(date_str=datetime)

print("get_search: base_args[datetime]", base_args["datetime"])

if intersects:
base_args["intersects"] = orjson.loads(unquote_plus(intersects))

Expand Down Expand Up @@ -499,6 +503,8 @@ async def post_search(

search = self.database.make_search()

# print("search_request: ", search_request)

if search_request.ids:
search = self.database.apply_ids_filter(
search=search, item_ids=search_request.ids
Expand Down
38 changes: 38 additions & 0 deletions stac_fastapi/core/stac_fastapi/core/datetime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,44 @@ def normalize(dt):
return f"{normalize(start)}/{normalize(end)}"


# def format_datetime_range(date_str: str) -> str:
# """
# Convert a datetime range string while preserving millisecond precision.
# """
# if not isinstance(date_str, str):
# return "../.."

# # If it's already a range with "..", return as-is to preserve precision
# if "/" in date_str and ".." in date_str:
# return date_str # <-- PRESERVE original format like "../2025-07-16T00:24:19.000Z"

# # Only apply normalization for closed ranges without ".."
# if "/" not in date_str:
# # Single datetime - normalize with precision
# return normalize(date_str)

# # For closed ranges (start/end without ".."), normalize both parts
# try:
# start, end = date_str.split("/", 1)
# return f"{normalize(start)}/{normalize(end)}"
# except Exception:
# return "../.."


# def normalize(dt):
# dt = dt.strip()
# if not dt or dt == "..":
# return ".."
# dt_obj = rfc3339_str_to_datetime(dt)
# dt_utc = dt_obj.astimezone(timezone.utc)

# # PRESERVE MILLISECONDS
# if dt_obj.microsecond > 0:
# return dt_utc.isoformat(timespec='milliseconds').replace('+00:00', 'Z')
# else:
# return dt_utc.strftime("%Y-%m-%dT%H:%M:%SZ")


# Borrowed from pystac - https://github.com/stac-utils/pystac/blob/f5e4cf4a29b62e9ef675d4a4dac7977b09f53c8f/pystac/utils.py#L370-L394
def datetime_to_str(dt: datetime, timespec: str = "auto") -> str:
"""Convert a :class:`datetime.datetime` instance to an ISO8601 string in the `RFC 3339, section 5.6.
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/opensearch/stac_fastapi/opensearch/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def run() -> None:
"stac_fastapi.opensearch.app:app",
host=settings.app_host,
port=settings.app_port,
log_level="info",
log_level="debug",
reload=settings.reload,
)
except ImportError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ async def execute_search(
"""
search_body: Dict[str, Any] = {}
query = search.query.to_dict() if search.query else None

# print("query: ", query)
index_param = await self.async_index_selector.select_indexes(
collection_ids, datetime_search
)
Expand Down
Loading