From 0aab0c9bd20cf195d2449a1a4fca53a68f09497a Mon Sep 17 00:00:00 2001 From: totycro Date: Thu, 28 Jan 2021 04:21:09 +0100 Subject: [PATCH] Date now handling (#613) * Drop support for "now" in dategetter This value already leads to an error in queries, so it's not really supported at this point anyway. * Use None instead of ".." for open temporal intervals See https://github.com/opengeospatial/ogcapi-features/blob/master/core/openapi/schemas/extent.yaml#L86 * Allow empty string in dateranges to mean open interval See http://docs.opengeospatial.org/is/17-069r3/17-069r3.html#_parameter_datetime --- pygeoapi/api.py | 5 +++++ pygeoapi/util.py | 8 ++++---- tests/test_api.py | 2 ++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pygeoapi/api.py b/pygeoapi/api.py index 09280b2..58535c9 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -2600,6 +2600,11 @@ def validate_datetime(resource_def, datetime_=None): if '/' in datetime_: # envelope LOGGER.debug('detected time range') LOGGER.debug('Validating time windows') + + # normalize "" to ".." (actually changes datetime_) + datetime_ = re.sub(r'^/', '../', datetime_) + datetime_ = re.sub(r'/$', '/..', datetime_) + datetime_begin, datetime_end = datetime_.split('/') if datetime_begin != '..': datetime_begin = dateparse_begin(datetime_begin) diff --git a/pygeoapi/util.py b/pygeoapi/util.py index 1e91606..e67b4e0 100644 --- a/pygeoapi/util.py +++ b/pygeoapi/util.py @@ -68,14 +68,14 @@ def dategetter(date_property, collection): :param date_property: property representing the date :param collection: dictionary to check within - :returns: `str` (ISO8601) representing the date. ('..' if null or "now", - allowing for an open interval). + :returns: `str` (ISO8601) representing the date. (allowing for an open interval + using null). """ value = collection.get(date_property, None) - if value == 'now' or value is None: - return '..' + if value is None: + return None return value.isoformat() diff --git a/tests/test_api.py b/tests/test_api.py index 1f69572..ff2d700 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1157,6 +1157,8 @@ def test_validate_datetime(): '2001-10-30/2002-10-30') assert validate_datetime(config, '2004/..') == '2004/..' assert validate_datetime(config, '../2005') == '../2005' + assert validate_datetime(config, '2004/') == '2004/..' + assert validate_datetime(config, '/2005') == '../2005' assert validate_datetime(config, '2004-10/2005-10') == '2004-10/2005-10' assert (validate_datetime(config, '2001-10-30/2002-10-30') == '2001-10-30/2002-10-30')