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 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: