Skip to content

Commit 29c7683

Browse files
Yuri ZmytrakovYuri Zmytrakov
authored andcommitted
fix format_datetime_range
1 parent ec928c0 commit 29c7683

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

stac_fastapi/core/stac_fastapi/core/datetime_utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,33 @@ 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+
print("dt_utc: ", dt_utc.isoformat(timespec="milliseconds").replace("+00:00", "Z"))
27+
28+
if dt_obj.microsecond > 0:
29+
return dt_utc.isoformat(timespec="milliseconds").replace("+00:00", "Z")
30+
else:
31+
return dt_utc.strftime("%Y-%m-%dT%H:%M:%SZ")
2632

2733
if not isinstance(date_str, str):
2834
return "../.."
35+
36+
if "/" in date_str and ".." in date_str:
37+
return date_str
38+
2939
if "/" not in date_str:
30-
return f"{normalize(date_str)}/{normalize(date_str)}"
40+
return normalize(date_str)
41+
3142
try:
3243
start, end = date_str.split("/", 1)
44+
return f"{normalize(start)}/{normalize(end)}"
3345
except Exception:
3446
return "../.."
35-
return f"{normalize(start)}/{normalize(end)}"
3647

3748

3849
# Borrowed from pystac - https://github.com/stac-utils/pystac/blob/f5e4cf4a29b62e9ef675d4a4dac7977b09f53c8f/pystac/utils.py#L370-L394

stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def run() -> None:
158158
"stac_fastapi.elasticsearch.app:app",
159159
host=settings.app_host,
160160
port=settings.app_port,
161-
log_level="info",
161+
log_level="debug",
162162
reload=settings.reload,
163163
)
164164
except ImportError:

stac_fastapi/opensearch/stac_fastapi/opensearch/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def run() -> None:
159159
"stac_fastapi.opensearch.app:app",
160160
host=settings.app_host,
161161
port=settings.app_port,
162-
log_level="info",
162+
log_level="debug",
163163
reload=settings.reload,
164164
)
165165
except ImportError:

0 commit comments

Comments
 (0)