File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
stac_fastapi/core/stac_fastapi/core Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -17,22 +17,32 @@ 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+
27+ if dt_obj .microsecond > 0 :
28+ return dt_utc .isoformat (timespec = "milliseconds" ).replace ("+00:00" , "Z" )
29+ else :
30+ return dt_utc .strftime ("%Y-%m-%dT%H:%M:%SZ" )
2631
2732 if not isinstance (date_str , str ):
2833 return "../.."
34+
35+ if "/" in date_str and ".." in date_str :
36+ return date_str
37+
2938 if "/" not in date_str :
30- return f"{ normalize (date_str )} /{ normalize (date_str )} "
39+ return normalize (date_str )
40+
3141 try :
3242 start , end = date_str .split ("/" , 1 )
43+ return f"{ normalize (start )} /{ normalize (end )} "
3344 except Exception :
3445 return "../.."
35- return f"{ normalize (start )} /{ normalize (end )} "
3646
3747
3848# Borrowed from pystac - https://github.com/stac-utils/pystac/blob/f5e4cf4a29b62e9ef675d4a4dac7977b09f53c8f/pystac/utils.py#L370-L394
You can’t perform that action at this time.
0 commit comments