Module stac_fastapi.core.datetime_utils¶
Utility functions to handle datetime parsing.
Functions¶
datetime_to_str¶
def datetime_to_str(
dt: datetime.datetime,
timespec: str = 'auto'
) -> str
Convert a :class:datetime.datetime
instance to an ISO8601 string in the `RFC 3339, section 5.6.
datatracker.ietf.org/doc/html/rfc3339#section-5.6__ format required by
the :stac-spec:
STAC Spec
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dt | None | The datetime to convert. | None |
timespec | None | 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'. |
None |
Returns:
Type | Description |
---|---|
str | The ISO8601 (RFC 3339) formatted string representing the datetime. |
format_datetime_range¶
def format_datetime_range(
date_str: str
) -> str
Convert a datetime range string into a normalized UTC string for API requests using rfc3339_str_to_datetime.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
date_str | str | A string containing two datetime values separated by a '/'. | None |
Returns:
Type | Description |
---|---|
str | A string formatted as 'YYYY-MM-DDTHH:MM:SSZ/YYYY-MM-DDTHH:MM:SSZ', with '..' used if any element is None. |
now_in_utc¶
def now_in_utc(
) -> datetime.datetime
Return a datetime value of now with the UTC timezone applied.
now_to_rfc3339_str¶
def now_to_rfc3339_str(
) -> str
Return an RFC 3339 string representing now.