Skip to content

Commit

Permalink
replace ciso8601 with pyiso8601 (#448)
Browse files Browse the repository at this point in the history
* replace ciso8601 with pyiso8601

* update changelog

* test types package in ci
  • Loading branch information
geospatial-jeff authored Aug 5, 2022
1 parent 4369424 commit 9f236be
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
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

0 comments on commit 9f236be

Please sign in to comment.