Skip to content

Commit 77d77d4

Browse files
YuriZmytrakovYuri Zmytrakov
andauthored
Ensure Normalize func preserves milliseconds precision (#423)
**Description:** Fixes an issue in the OS STAC `/search` endpoint where datetime filters overwrite milliseconds. The queries return products outside the specified range because the filter was rounding datetimes to full seconds. This change ensures that milliseconds are preserved, so datetime filtering returns correct results. **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 <[email protected]>
1 parent 8974c38 commit 77d77d4

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2222

2323
- 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)
2424
- 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)
25+
- Updated the `format_datetime_range` function to support milliseconds. [#423](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/423)
2526

2627
### Changed
2728

stac_fastapi/core/stac_fastapi/core/datetime_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,20 @@ def format_datetime_range(date_str: str) -> str:
1717
"""
1818

1919
def normalize(dt):
20+
"""Normalize datetime string and preserve millisecond precision."""
2021
dt = dt.strip()
2122
if not dt or dt == "..":
2223
return ".."
2324
dt_obj = rfc3339_str_to_datetime(dt)
2425
dt_utc = dt_obj.astimezone(timezone.utc)
25-
return dt_utc.strftime("%Y-%m-%dT%H:%M:%SZ")
26+
return dt_utc.isoformat(timespec="milliseconds").replace("+00:00", "Z")
2627

2728
if not isinstance(date_str, str):
2829
return "../.."
30+
2931
if "/" not in date_str:
3032
return f"{normalize(date_str)}/{normalize(date_str)}"
33+
3134
try:
3235
start, end = date_str.split("/", 1)
3336
except Exception:

0 commit comments

Comments
 (0)