diff --git a/CHANGELOG.md b/CHANGELOG.md index e66e2b97..2e161e4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed +- Fixed datetime filtering for .0Z milliseconds to preserve precision in apply_filter_datetime, ensuring only items exactly within the specified range are returned. [#535](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/535) + ### Removed ### Updated diff --git a/stac_fastapi/core/stac_fastapi/core/datetime_utils.py b/stac_fastapi/core/stac_fastapi/core/datetime_utils.py index 587f2d0b..38a37036 100644 --- a/stac_fastapi/core/stac_fastapi/core/datetime_utils.py +++ b/stac_fastapi/core/stac_fastapi/core/datetime_utils.py @@ -32,7 +32,10 @@ def normalize(dt): dt_utc = MIN_DATE_NANOS if dt_utc > MAX_DATE_NANOS: dt_utc = MAX_DATE_NANOS - return dt_utc.isoformat(timespec="auto").replace("+00:00", "Z") + dt_normalized = dt_utc.isoformat(timespec="auto").replace("+00:00", "Z") + if "." not in dt_normalized: + dt_normalized = dt_normalized.replace("Z", ".0Z") + return dt_normalized if not isinstance(date_str, str): return f"{MIN_DATE_NANOS.isoformat(timespec='auto').replace('+00:00','Z')}/{MAX_DATE_NANOS.isoformat(timespec='auto').replace('+00:00','Z')}"