diff --git a/openeo/dates.py b/openeo/dates.py index 43d64a09f..7d48deb14 100644 --- a/openeo/dates.py +++ b/openeo/dates.py @@ -96,14 +96,17 @@ def _get_end_of_time_slot(date: str) -> Union[dt.date, str]: return date date_converted = _convert_abbreviated_date(date) - type_start_date = _type_of_date_string(date) - if type_start_date == _TypeOfDateString.YEAR: + granularity = _type_of_date_string(date) + if granularity == _TypeOfDateString.YEAR: return dt.date(date_converted.year + 1, 1, 1) - elif type_start_date == _TypeOfDateString.MONTH: + elif granularity == _TypeOfDateString.MONTH: if date_converted.month == 12: return dt.date(date_converted.year + 1, 1, 1) else: return dt.date(date_converted.year, date_converted.month + 1, 1) + elif granularity == _TypeOfDateString.DAY: + # TODO: also support day granularity in _convert_abbreviated_date so that we don't need ad-hoc parsing here + return dt.date(*(int(x) for x in _REGEX_DAY.match(date).group(1, 2, 3))) + dt.timedelta(days=1) else: # Don't convert: it is a day or datetime. return date @@ -154,6 +157,7 @@ def _convert_abbreviated_date( ) if type_of_date in [_TypeOfDateString.DATETIME, _TypeOfDateString.DAY]: + # TODO: also convert these to `date` or `datetime` for more internal consistency. return date if type_of_date == _TypeOfDateString.MONTH: diff --git a/tests/rest/datacube/test_datacube.py b/tests/rest/datacube/test_datacube.py index 2e9707525..124212269 100644 --- a/tests/rest/datacube/test_datacube.py +++ b/tests/rest/datacube/test_datacube.py @@ -182,7 +182,7 @@ def test_load_collection_filter_temporal(connection, api_version, extent, expect # Test that the simplest/shortest syntax works: temporal_extent="2016" ("2016", ["2016-01-01", "2017-01-01"]), ("2016-02", ["2016-02-01", "2016-03-01"]), - ("2016-02-03", ["2016-02-03", "2016-03-04"]), + ("2016-02-03", ["2016-02-03", "2016-02-04"]), # Test date abbreviations using tuples for the extent (["2016", None], ["2016-01-01", None]), (["2016-02", None], ["2016-02-01", None]), diff --git a/tests/test_dates.py b/tests/test_dates.py index 6565816f3..e6b8d0431 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -164,6 +164,8 @@ def test_extent_sequence_shorthand_month(self, extent, expected): ("2019", ("2019-01-01", "2020-01-01")), ("2019-03", ("2019-03-01", "2019-04-01")), ("2019-12", ("2019-12-01", "2020-01-01")), + ("2019-03-05", ("2019-03-05", "2019-03-06")), + ("2019-12-31", ("2019-12-31", "2020-01-01")), ], ) def test_extent_single_string_shorthand(self, extent, expected):