Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Changed

- Changed datetime format to `strict_date_optional_time_nanos` for microsecond precision and updated normalization to replace infinite ("..") or overflow datetimes with the maximum supported Elasticsearch date 2262-04-11T23:47:16.854775Z.

### Fixed

[v6.5.1] - 2025-09-30
Expand Down
17 changes: 13 additions & 4 deletions stac_fastapi/core/stac_fastapi/core/datetime_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,26 @@ def format_datetime_range(date_str: str) -> str:
date_str (str): A string containing two datetime values separated by a '/'.

Returns:
str: A string formatted as 'YYYY-MM-DDTHH:MM:SSZ/YYYY-MM-DDTHH:MM:SSZ', with '..' used if any element is None.
str: A string formatted as 'YYYY-MM-DDTHH:MM:SS.ssssssZ/YYYY-MM-DDTHH:MM:SS.ssssssZ'.
Each datetime is converted to UTC and preserves microsecond precision.
If a value is infinite '..', it is replaced with the maximum supported
UTC datetime ('2262-04-11T23:47:16.854775Z').
"""

def normalize(dt):
"""Normalize datetime string and preserve millisecond precision."""
"""Normalize datetime string and preserve microsecond precision."""
dt = dt.strip()

max_es_date = datetime(2262, 4, 11, 23, 47, 16, 854775, tzinfo=timezone.utc)
if not dt or dt == "..":
return ".."
return max_es_date.isoformat(timespec="microseconds").replace("+00:00", "Z")

dt_obj = rfc3339_str_to_datetime(dt)
if dt_obj > max_es_date:
dt_obj = max_es_date

dt_utc = dt_obj.astimezone(timezone.utc)
return dt_utc.isoformat(timespec="milliseconds").replace("+00:00", "Z")
return dt_utc.isoformat(timespec="microseconds").replace("+00:00", "Z")

if not isinstance(date_str, str):
return "../.."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ class Geometry(Protocol): # noqa
"type": "object",
"properties": {
# Common https://github.com/radiantearth/stac-spec/blob/master/item-spec/common-metadata.md
"datetime": {"type": "date"},
"datetime": {
"type": "date",
"format": "strict_date_optional_time_nanos",
},
"start_datetime": {"type": "date"},
"end_datetime": {"type": "date"},
"created": {"type": "date"},
Expand Down