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
This commit is contained in:
@@ -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)
|
||||
|
||||
+4
-4
@@ -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()
|
||||
|
||||
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user