From e6dfb226d3ffea4296002a8e97de0fb268dd6c82 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Fri, 4 Jun 2021 06:07:47 -0600 Subject: [PATCH 1/2] Improve the datetime regex Includes a test with a lot of funky datetimes. Closes #57 --- pystac_client/item_search.py | 3 ++- tests/test_item_search.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/pystac_client/item_search.py b/pystac_client/item_search.py index 694c9fe9..0cbba35d 100644 --- a/pystac_client/item_search.py +++ b/pystac_client/item_search.py @@ -18,7 +18,8 @@ from pystac_client.stac_io import get_pages, make_request, simple_stac_resolver DATETIME_REGEX = re.compile( - r"(?P\d{4})(-(?P\d{2})(-(?P\d{2})(?PT\d{2}:\d{2}:\d{2}\w*)?)?)?") + r"(?P\d{4})(\-(?P\d{2})(\-(?P\d{2})" + r"(?P(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]] diff --git a/tests/test_item_search.py b/tests/test_item_search.py index 059dd494..899e5d52 100644 --- a/tests/test_item_search.py +++ b/tests/test_item_search.py @@ -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()) From 707e8e22267ba35e51b35039e2d0876ff752fce3 Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Fri, 4 Jun 2021 06:10:28 -0600 Subject: [PATCH 2/2] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2cc088e2..6ff696e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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