Skip to content

replace ciso8601 with pyiso8601 #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 5, 2022
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
8 changes: 7 additions & 1 deletion .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,13 @@ jobs:
cd stac_fastapi/api && pipenv run pytest -svvv
env:
ENVIRONMENT: testing


- name: Run test suite
run: |
cd stac_fastapi/types && pipenv run pytest -svvv
env:
ENVIRONMENT: testing

- name: Run test suite
run: |
cd stac_fastapi/sqlalchemy && pipenv run pytest -svvv
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Removed

### Fixed
* `ciso8601` fails to build in some environments, instead use `pyiso8601` to parse datetimes.

## [2.4.0]

Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/types/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"pydantic[dotenv]",
"stac_pydantic==2.0.*",
"pystac==1.*",
"ciso8601~=2.2.0",
"iso8601~=1.0.2",
]

extra_reqs = {
Expand Down
19 changes: 15 additions & 4 deletions stac_fastapi/types/stac_fastapi/types/rfc3339.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""rfc3339."""

import re
from datetime import datetime, timezone
from typing import Optional, Tuple

import ciso8601
import iso8601
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+)?(Z|([-+])(\d\d):(\d\d))$"


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

Uses :meth:`ciso8601.parse_rfc3339` under the hood.
Uses :meth:`iso8601.parse_date` under the hood.

Args:
s (str) : The string to convert to :class:`datetime.datetime`.
Expand All @@ -21,7 +23,16 @@ def rfc3339_str_to_datetime(s: str) -> datetime:
Raises:
ValueError: If the string is not a valid RFC 3339 string.
"""
return ciso8601.parse_rfc3339(s)
# Uppercase the string
s = s.upper()

# Match against RFC3339 regex.
result = re.match(RFC33339_PATTERN, s)
if not result:
raise ValueError("Invalid RFC3339 datetime.")

# Parse with pyiso8601
return iso8601.parse_date(s)


def str_to_interval(
Expand Down