File tree Expand file tree Collapse file tree 4 files changed +36
-7
lines changed Expand file tree Collapse file tree 4 files changed +36
-7
lines changed Original file line number Diff line number Diff line change 11# Changelog
22
3- [ Unreleased] - TBD
3+ ## [ Unreleased] - TBD
44
5- ## Changed
5+ ### Changed
6+
7+ * switch from ` fastapi ` to ` fastapi-slim ` to avoid installing unwanted dependencies. ([ #687 ] ( https://github.com/stac-utils/stac-fastapi/pull/687 ) )
8+ * replace Enum with ` Literal ` for ` FilterLang ` . ([ #686 ] ( https://github.com/stac-utils/stac-fastapi/pull/686 ) )
9+
10+ ### Removed
611
7- * switch from ` fastapi ` to ` fastapi-slim ` to avoid installing unwanted dependencies
8- * replace Enum with ` Literal ` for ` FilterLang `
12+ * Pystac as it was just used for a datetime to string function. ([ #690 ] ( https://github.com/stac-utils/stac-fastapi/pull/690 ) )
913
1014## [ 3.0.0a0] - 2024-05-06
1115
Original file line number Diff line number Diff line change 1818 "pytest-asyncio" ,
1919 "pre-commit" ,
2020 "requests" ,
21- "pystac[validation]==1.*" ,
2221 ],
2322 "benchmark" : [
2423 "pytest-benchmark" ,
Original file line number Diff line number Diff line change 1010 "attrs>=23.2.0" ,
1111 "pydantic-settings>=2" ,
1212 "stac_pydantic>=3" ,
13- "pystac==1.*" ,
1413 "iso8601>=1.0.2,<2.2.0" ,
1514]
1615
Original file line number Diff line number Diff line change 66
77import iso8601
88from fastapi import HTTPException
9- from pystac .utils import datetime_to_str
109
1110RFC33339_PATTERN = (
1211 r"^(\d\d\d\d)\-(\d\d)\-(\d\d)(T|t)(\d\d):(\d\d):(\d\d)([.]\d+)?"
2120]
2221
2322
23+ # Borrowed from pystac - https://github.com/stac-utils/pystac/blob/f5e4cf4a29b62e9ef675d4a4dac7977b09f53c8f/pystac/utils.py#L370-L394
24+ def datetime_to_str (dt : datetime , timespec : str = "auto" ) -> str :
25+ """Converts a :class:`datetime.datetime` instance to an ISO8601 string in the
26+ `RFC 3339, section 5.6
27+ <https://datatracker.ietf.org/doc/html/rfc3339#section-5.6>`__ format required by
28+ the :stac-spec:`STAC Spec <master/item-spec/common-metadata.md#date-and-time>`.
29+
30+ Args:
31+ dt : The datetime to convert.
32+ timespec: An optional argument that specifies the number of additional
33+ terms of the time to include. Valid options are 'auto', 'hours',
34+ 'minutes', 'seconds', 'milliseconds' and 'microseconds'. The default value
35+ is 'auto'.
36+
37+ Returns:
38+ str: The ISO8601 (RFC 3339) formatted string representing the datetime.
39+ """
40+ if dt .tzinfo is None :
41+ dt = dt .replace (tzinfo = timezone .utc )
42+
43+ timestamp = dt .isoformat (timespec = timespec )
44+ zulu = "+00:00"
45+ if timestamp .endswith (zulu ):
46+ timestamp = f"{ timestamp [: - len (zulu )]} Z"
47+
48+ return timestamp
49+
50+
2451def rfc3339_str_to_datetime (s : str ) -> datetime :
2552 """Convert a string conforming to RFC 3339 to a :class:`datetime.datetime`.
2653
You can’t perform that action at this time.
0 commit comments