Skip to content

Commit 6f74a12

Browse files
YuriZmytrakovYuri Zmytrakov
andauthored
fix: ensure isformat does not truncate 0Z (#535)
**Description:** This PR fixes `.0Z` milliseconds being truncated by `isformat`, causing items outside the expected datetime range to be returned. The apply_filter_datetime function was updated to preserve milliseconds when filtering, ensuring that only items exactly within the specified datetime range are included. Example `2023-01-09T13:39:39.0Z` returned item `2023-01-09T13:39:39.024Z` which is not within the specified range, but was returned because .0Z was truncated to 2023-01-09T13:39:39Z. After the fix, queries respect millisecond precision, and only items strictly within the specified range are returned. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [ ] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog --------- Co-authored-by: Yuri Zmytrakov <yzmytrakovNB@yzmytrakovNB.local>
1 parent ddee878 commit 6f74a12

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313

1414
### Fixed
1515

16+
- 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)
17+
1618
### Removed
1719

1820
## [v6.7.5] - 2025-11-25

stac_fastapi/core/stac_fastapi/core/datetime_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def normalize(dt):
3232
dt_utc = MIN_DATE_NANOS
3333
if dt_utc > MAX_DATE_NANOS:
3434
dt_utc = MAX_DATE_NANOS
35-
return dt_utc.isoformat(timespec="auto").replace("+00:00", "Z")
35+
dt_normalized = dt_utc.isoformat(timespec="auto").replace("+00:00", "Z")
36+
if "." not in dt_normalized:
37+
dt_normalized = dt_normalized.replace("Z", ".0Z")
38+
return dt_normalized
3639

3740
if not isinstance(date_str, str):
3841
return f"{MIN_DATE_NANOS.isoformat(timespec='auto').replace('+00:00','Z')}/{MAX_DATE_NANOS.isoformat(timespec='auto').replace('+00:00','Z')}"

0 commit comments

Comments
 (0)