Skip to content

Commit

Permalink
Allow None to be used as format_query_date() input
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jun 26, 2018
1 parent f974c2e commit e421a54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
24 changes: 22 additions & 2 deletions sentinelsat/sentinel.py
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,29 @@ def ensure_2d(geometry):


def format_query_date(in_date):
"""Format a date, datetime or a YYYYMMDD string input as YYYY-MM-DDThh:mm:ssZ
or validate a string input as suitable for the full text search interface and return it.
"""
Format a date, datetime or a YYYYMMDD string input as YYYY-MM-DDThh:mm:ssZ
or validate a date string as suitable for the full text search interface and return it.
`None` will be converted to '\*', meaning an unlimited date bound in date ranges.
Parameters
----------
in_date : str or datetime or date or None
Date to be formatted
Returns
-------
str
Formatted string
Raises
------
ValueError
If the input date type is incorrect or passed date string is invalid
"""
if in_date is None:
return '*'
if isinstance(in_date, (datetime, date)):
return in_date.strftime('%Y-%m-%dT%H:%M:%SZ')
elif not isinstance(in_date, string_types):
Expand Down
1 change: 1 addition & 0 deletions tests/test_mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def test_format_date():
assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
assert format_query_date(' NOW ') == 'NOW'
assert format_query_date(None) == '*'

api = SentinelAPI(**_api_auth)
for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
Expand Down

0 comments on commit e421a54

Please sign in to comment.