Skip to content

Unexpected Behaviour on Poorly Formed Date #358

@szwiep

Description

@szwiep

When you pass a str date to search without leading zeros on the months (e.g '2020-7/2020-8'), the current DATETIME_REGEX only matches the years and ignores the months, since the months are incorrectly formatted. This causes the final datetime to consist only of the years (e.g 2020-2020).

>>> api = Client.open("https://planetarycomputer.microsoft.com/api/stac/v1")
>>> bad_date_str = '2020-7/2020-8'
>>> aoi = box(35.434076765062386, 7.548766587474588, 35.57903679114287, 7.799796217489619)
>>> search = api.search(collections=['sentinel-2-l2a'], intersects=aoi, datetime=bad_date_str)
>>> items = search.get_all_items()
>>> len(items)
143
>>> good_date_str = '2020-07/2020-08'
>>> search = api.search(collections=['sentinel-2-l2a'], intersects=aoi, datetime=bad_date_str)
>>> items = search.get_all_items()
>>> len(items)
24

I would expect that this sort of poorly formatted string would raise an error instead of ignoring the portion of the string unmatched by the regex expression (in our case, the months with no leading zero).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions