From 6c0c60a58bd7f4731044693347338e144526221f Mon Sep 17 00:00:00 2001 From: Yuri Zmytrakov Date: Mon, 1 Sep 2025 15:17:18 +0200 Subject: [PATCH 1/2] fix: Ensure Normalize func preserves milliseconds precision Normalize function for datetime strings did not preserve milliseconds, causing the `/search` endpoint return incorrect results. This change ensures that milliseconds are retained when normalized. --- stac_fastapi/core/stac_fastapi/core/datetime_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/stac_fastapi/core/stac_fastapi/core/datetime_utils.py b/stac_fastapi/core/stac_fastapi/core/datetime_utils.py index 87911ac51..d5f992de8 100644 --- a/stac_fastapi/core/stac_fastapi/core/datetime_utils.py +++ b/stac_fastapi/core/stac_fastapi/core/datetime_utils.py @@ -17,17 +17,20 @@ def format_datetime_range(date_str: str) -> str: """ def normalize(dt): + """Normalize datetime string and preserve millisecond precision.""" dt = dt.strip() if not dt or dt == "..": return ".." dt_obj = rfc3339_str_to_datetime(dt) dt_utc = dt_obj.astimezone(timezone.utc) - return dt_utc.strftime("%Y-%m-%dT%H:%M:%SZ") + return dt_utc.isoformat(timespec="milliseconds").replace("+00:00", "Z") if not isinstance(date_str, str): return "../.." + if "/" not in date_str: return f"{normalize(date_str)}/{normalize(date_str)}" + try: start, end = date_str.split("/", 1) except Exception: From cf256e994566d968bd292d648896ab00e3fb76bb Mon Sep 17 00:00:00 2001 From: Yuri Zmytrakov Date: Wed, 10 Sep 2025 11:02:19 +0200 Subject: [PATCH 2/2] docs: updating changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d9fd130..ae7511646 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Added `id` field as secondary sort to sort config to ensure unique pagination tokens. [#421](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/421) - Added default environment variable `STAC_ITEM_LIMIT` to SFEOS for result limiting of returned items and STAC collections [#419](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/419) +- Updated the `format_datetime_range` function to support milliseconds. [#423](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/423) ### Changed