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 1
1
# Changelog
2
2
3
- [ Unreleased] - TBD
3
+ ## [ Unreleased] - TBD
4
4
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
6
11
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 ) )
9
13
10
14
## [ 3.0.0a0] - 2024-05-06
11
15
Original file line number Diff line number Diff line change 18
18
"pytest-asyncio" ,
19
19
"pre-commit" ,
20
20
"requests" ,
21
- "pystac[validation]==1.*" ,
22
21
],
23
22
"benchmark" : [
24
23
"pytest-benchmark" ,
Original file line number Diff line number Diff line change 10
10
"attrs>=23.2.0" ,
11
11
"pydantic-settings>=2" ,
12
12
"stac_pydantic>=3" ,
13
- "pystac==1.*" ,
14
13
"iso8601>=1.0.2,<2.2.0" ,
15
14
]
16
15
Original file line number Diff line number Diff line change 6
6
7
7
import iso8601
8
8
from fastapi import HTTPException
9
- from pystac .utils import datetime_to_str
10
9
11
10
RFC33339_PATTERN = (
12
11
r"^(\d\d\d\d)\-(\d\d)\-(\d\d)(T|t)(\d\d):(\d\d):(\d\d)([.]\d+)?"
21
20
]
22
21
23
22
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
+
24
51
def rfc3339_str_to_datetime (s : str ) -> datetime :
25
52
"""Convert a string conforming to RFC 3339 to a :class:`datetime.datetime`.
26
53
You can’t perform that action at this time.
0 commit comments