Skip to content

Commit

Permalink
fixup! fixup! Issue #421/#68 drop "round up" feature for end_date for…
Browse files Browse the repository at this point in the history
… better consistency
  • Loading branch information
soxofaan committed Sep 18, 2023
1 parent 73590e3 commit 02067cb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 7 additions & 3 deletions openeo/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/rest/datacube/test_datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 02067cb

Please sign in to comment.