fix timezone aware date parsing (#337)
* fix timezone aware date parsing * fix ref * add deps
This commit is contained in:
Vendored
+2
@@ -20,6 +20,7 @@ Depends: ${python:Depends},
|
||||
python-click,
|
||||
python-dateutil,
|
||||
python-flask,
|
||||
python-tz,
|
||||
python-unicodecsv,
|
||||
python-yaml,
|
||||
${misc:Depends}
|
||||
@@ -35,6 +36,7 @@ Depends: ${python3:Depends},
|
||||
python3-click,
|
||||
python3-dateutil,
|
||||
python3-flask,
|
||||
python3-tz,
|
||||
python3-unicodecsv,
|
||||
python3-yaml,
|
||||
${misc:Depends}
|
||||
|
||||
@@ -36,6 +36,7 @@ import logging
|
||||
import urllib.parse
|
||||
|
||||
from dateutil.parser import parse as dateparse
|
||||
import pytz
|
||||
|
||||
from pygeoapi import __version__
|
||||
from pygeoapi.linked_data import (geojson2geojsonld, jsonldify,
|
||||
@@ -569,14 +570,25 @@ class API(object):
|
||||
'temporal' in self.config['datasets'][dataset]['extents']):
|
||||
te = self.config['datasets'][dataset]['extents']['temporal']
|
||||
|
||||
if te['begin'].tzinfo is None:
|
||||
te['begin'] = te['begin'].replace(tzinfo=pytz.UTC)
|
||||
if te['end'].tzinfo is None:
|
||||
te['end'] = te['end'].replace(tzinfo=pytz.UTC)
|
||||
|
||||
if '/' in datetime_: # envelope
|
||||
LOGGER.debug('detected time range')
|
||||
LOGGER.debug('Validating time windows')
|
||||
datetime_begin, datetime_end = datetime_.split('/')
|
||||
if datetime_begin != '..':
|
||||
datetime_begin = dateparse(datetime_begin)
|
||||
if datetime_begin.tzinfo is None:
|
||||
datetime_begin = datetime_begin.replace(
|
||||
tzinfo=pytz.UTC)
|
||||
|
||||
if datetime_end != '..':
|
||||
datetime_end = dateparse(datetime_end)
|
||||
if datetime_end.tzinfo is None:
|
||||
datetime_end = datetime_end.replace(tzinfo=pytz.UTC)
|
||||
|
||||
if te['begin'] is not None and datetime_begin != '..':
|
||||
if datetime_begin < te['begin']:
|
||||
@@ -588,6 +600,9 @@ class API(object):
|
||||
|
||||
else: # time instant
|
||||
datetime__ = dateparse(datetime_)
|
||||
if datetime__ != '..':
|
||||
if datetime__.tzinfo is None:
|
||||
datetime__ = datetime__.replace(tzinfo=pytz.UTC)
|
||||
LOGGER.debug('detected time instant')
|
||||
if te['begin'] is not None and datetime__ != '..':
|
||||
if datetime__ < te['begin']:
|
||||
|
||||
+2
-1
@@ -1,5 +1,6 @@
|
||||
click
|
||||
python-dateutil
|
||||
Flask
|
||||
python-dateutil
|
||||
pytz
|
||||
PyYAML
|
||||
unicodecsv
|
||||
|
||||
+4
-2
@@ -215,7 +215,9 @@ def test_describe_collections(config, api_):
|
||||
'crs': 'http://www.opengis.net/def/crs/OGC/1.3/CRS84'
|
||||
},
|
||||
'temporal': {
|
||||
'interval': [['2000-10-30T18:24:39', '2007-10-30T08:57:29']],
|
||||
'interval': [
|
||||
['2000-10-30T18:24:39+00:00', '2007-10-30T08:57:29+00:00']
|
||||
],
|
||||
'trs': 'http://www.opengis.net/def/uom/ISO-8601/0/Gregorian'
|
||||
}
|
||||
}
|
||||
@@ -254,7 +256,7 @@ def test_describe_collections_json_ld(config, api_):
|
||||
|
||||
assert 'http://schema.org/temporalCoverage' in dataset
|
||||
assert dataset['http://schema.org/temporalCoverage'][0][
|
||||
'@value'] == '2000-10-30T18:24:39/2007-10-30T08:57:29'
|
||||
'@value'] == '2000-10-30T18:24:39+00:00/2007-10-30T08:57:29+00:00'
|
||||
|
||||
|
||||
def test_get_collection_items(config, api_):
|
||||
|
||||
Reference in New Issue
Block a user