Skip to content
Merged
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
12 changes: 8 additions & 4 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# Changelog

[Unreleased] - TBD
## [Unreleased] - TBD

## Changed
### Changed

* switch from `fastapi` to `fastapi-slim` to avoid installing unwanted dependencies. ([#687](https://github.com/stac-utils/stac-fastapi/pull/687))
* replace Enum with `Literal` for `FilterLang`. ([#686](https://github.com/stac-utils/stac-fastapi/pull/686))

### Removed

* switch from `fastapi` to `fastapi-slim` to avoid installing unwanted dependencies
* replace Enum with `Literal` for `FilterLang`
* Pystac as it was just used for a datetime to string function. ([#690](https://github.com/stac-utils/stac-fastapi/pull/690))

## [3.0.0a0] - 2024-05-06

Expand Down
1 change: 0 additions & 1 deletion stac_fastapi/api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"pytest-asyncio",
"pre-commit",
"requests",
"pystac[validation]==1.*",
],
"benchmark": [
"pytest-benchmark",
Expand Down
1 change: 0 additions & 1 deletion stac_fastapi/types/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"attrs>=23.2.0",
"pydantic-settings>=2",
"stac_pydantic>=3",
"pystac==1.*",
"iso8601>=1.0.2,<2.2.0",
]

Expand Down
29 changes: 28 additions & 1 deletion stac_fastapi/types/stac_fastapi/types/rfc3339.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import iso8601
from fastapi import HTTPException
from pystac.utils import datetime_to_str

RFC33339_PATTERN = (
r"^(\d\d\d\d)\-(\d\d)\-(\d\d)(T|t)(\d\d):(\d\d):(\d\d)([.]\d+)?"
Expand All @@ -21,6 +20,34 @@
]


# Borrowed from pystac - https://github.com/stac-utils/pystac/blob/f5e4cf4a29b62e9ef675d4a4dac7977b09f53c8f/pystac/utils.py#L370-L394
def datetime_to_str(dt: datetime, timespec: str = "auto") -> str:
"""Converts a :class:`datetime.datetime` instance to an ISO8601 string in the
`RFC 3339, section 5.6
<https://datatracker.ietf.org/doc/html/rfc3339#section-5.6>`__ format required by
the :stac-spec:`STAC Spec <master/item-spec/common-metadata.md#date-and-time>`.

Args:
dt : The datetime to convert.
timespec: An optional argument that specifies the number of additional
terms of the time to include. Valid options are 'auto', 'hours',
'minutes', 'seconds', 'milliseconds' and 'microseconds'. The default value
is 'auto'.

Returns:
str: The ISO8601 (RFC 3339) formatted string representing the datetime.
"""
if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc)

timestamp = dt.isoformat(timespec=timespec)
zulu = "+00:00"
if timestamp.endswith(zulu):
timestamp = f"{timestamp[: -len(zulu)]}Z"

return timestamp


def rfc3339_str_to_datetime(s: str) -> datetime:
"""Convert a string conforming to RFC 3339 to a :class:`datetime.datetime`.

Expand Down