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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

- Running `stac-client` with no arguments no longer raises a confusing exception [#52](https://github.com/stac-utils/pystac-client/pull/52)
- `Client.get_collections_list` [#44](https://github.com/stac-utils/pystac-client/issues/44)
- The regular expression used for datetime parsing [#59](https://github.com/stac-utils/pystac-client/pull/59)

## [v0.1.1] - 2021-04-16

Expand Down
3 changes: 2 additions & 1 deletion pystac_client/item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from pystac_client.stac_io import get_pages, make_request, simple_stac_resolver

DATETIME_REGEX = re.compile(
r"(?P<year>\d{4})(-(?P<month>\d{2})(-(?P<day>\d{2})(?P<remainder>T\d{2}:\d{2}:\d{2}\w*)?)?)?")
r"(?P<year>\d{4})(\-(?P<month>\d{2})(\-(?P<day>\d{2})"
r"(?P<remainder>(T|t)\d{2}:\d{2}:\d{2}(\.\d+)?(Z|([-+])(\d{2}):(\d{2})))?)?)?")

DatetimeOrTimestamp = Optional[Union[datetime_, str]]
Datetime = Union[Tuple[str], Tuple[str, str]]
Expand Down
28 changes: 28 additions & 0 deletions tests/test_item_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,34 @@ def test_mixed_simple_date_strings(self):
search = ItemSearch(url=ASTRAEA_URL, datetime="2019/2020-06-10")
assert search.request.json['datetime'] == "2019-01-01T00:00:00Z/2020-06-10T23:59:59Z"

def test_many_datetimes(self):
datetimes = [
"1985-04-12T23:20:50.52Z"
"1996-12-19T16:39:57-08:00"
"1990-12-31T23:59:60Z"
"1990-12-31T15:59:60-08:00"
"1937-01-01T12:00:27.87+01:00"
"1985-04-12T23:20:50.52Z"
"1937-01-01T12:00:27.8710+01:00"
"1937-01-01T12:00:27.8+01:00"
"1937-01-01T12:00:27.8Z"
"1985-04-12t23:20:50.5202020z"
"2020-07-23T00:00:00Z"
"2020-07-23T00:00:00.0Z"
"2020-07-23T00:00:00.01Z"
"2020-07-23T00:00:00.012Z"
"2020-07-23T00:00:00.0123Z"
"2020-07-23T00:00:00.01234Z"
"2020-07-23T00:00:00.012345Z"
"2020-07-23T00:00:00.000Z"
"2020-07-23T00:00:00.000+03:00"
"2020-07-23T00:00:00+03:00"
"2020-07-23T00:00:00.000+03:00"
"2020-07-23T00:00:00.000z"
]
for date_time in datetimes:
ItemSearch(url=ASTRAEA_URL, datetime=date_time)

def test_three_datetimes(self):
start = datetime(2020, 2, 1, 0, 0, 0, tzinfo=tzutc())
middle = datetime(2020, 2, 2, 0, 0, 0, tzinfo=tzutc())
Expand Down