diff --git a/debian/control b/debian/control index ee11a1c..81a973b 100644 --- a/debian/control +++ b/debian/control @@ -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} diff --git a/pygeoapi/api.py b/pygeoapi/api.py index b649e21..7cf5cdd 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -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']: diff --git a/requirements.txt b/requirements.txt index 4e39b94..9e247b7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ click -python-dateutil Flask +python-dateutil +pytz PyYAML unicodecsv diff --git a/tests/test_api.py b/tests/test_api.py index 1184472..ad4a818 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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_):