Skip to content

Module stac_fastapi.types.rfc3339

rfc3339.

Variables

DateTimeType
RFC33339_PATTERN

Functions

datetime_to_str

def datetime_to_str(
    dt: datetime.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>.

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.

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.

parse_single_date

def parse_single_date(
    date_str: str
) -> datetime.datetime

Parse a single RFC3339 date string into a datetime object.

Parameters:

Name Type Description Default
date_str str A string representing the date in RFC3339 format. None

Returns:

Type Description
datetime A datetime object parsed from the date_str.

Raises:

Type Description
ValueError If the date_str is empty or contains the placeholder '..'.

rfc3339_str_to_datetime

def rfc3339_str_to_datetime(
    s: str
) -> datetime.datetime

Convert a string conforming to RFC 3339 to a :class:datetime.datetime.

Uses :meth:iso8601.parse_date under the hood.

Parameters:

Name Type Description Default
s str The string to convert to :class:datetime.datetime. None

Returns:

Type Description
str The datetime represented by the ISO8601 (RFC 3339) formatted string.

Raises:

Type Description
ValueError If the string is not a valid RFC 3339 string.

str_to_interval

def str_to_interval(
    interval: Optional[str]
) -> Union[datetime.datetime, Tuple[datetime.datetime, datetime.datetime], Tuple[datetime.datetime, NoneType], Tuple[NoneType, datetime.datetime], NoneType]

Extract a single datetime object or a tuple of datetime objects from an

interval string defined by the OGC API. The interval can either be a single datetime or a range with start and end datetime.

Args: interval (Optional[str]): The interval string to convert to datetime objects, or None if no datetime is specified.

Returns: Optional[DateTimeType]: A single datetime.datetime object, a tuple of datetime.datetime objects, or None if input is None.

Raises: HTTPException: If the string is not valid for various reasons such as being empty, having more than one slash, or if date formats are invalid.