From 1b0e3ffccbac1d3df621de46a1171ddc16726402 Mon Sep 17 00:00:00 2001 From: Rae Knowler Date: Wed, 15 Nov 2023 11:42:16 +0100 Subject: [PATCH 1/2] fix: If modified date has no TZ, assume it's Europe/Zurich --- ckanext/dcatapchharvest/harvest_helper.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ckanext/dcatapchharvest/harvest_helper.py b/ckanext/dcatapchharvest/harvest_helper.py index 3b2a49c..d68ef9f 100644 --- a/ckanext/dcatapchharvest/harvest_helper.py +++ b/ckanext/dcatapchharvest/harvest_helper.py @@ -1,12 +1,14 @@ import ckan.plugins.toolkit as tk import ckan.model as model from dateutil.parser import parse as dateutil_parse, ParserError +from dateutil.tz import tz import logging log = logging.getLogger(__name__) NOTIFICATION_USER = 'harvest-notification' +DEFAULT_TIMEZONE = tz.gettz('Europe/Zurich') def map_resources_to_ids(pkg_dict, package_id): @@ -94,15 +96,30 @@ def _changes_in_date(existing_datetime, new_datetime): return False if not existing_datetime or not new_datetime: return True + try: - if dateutil_parse(existing_datetime) == dateutil_parse(new_datetime): - return False + existing = dateutil_parse(existing_datetime) + if existing.tzinfo is None: + existing = existing.replace(tzinfo=DEFAULT_TIMEZONE) + log.debug( + "Datetime %s has no time zone info: assuming Europe/Zurich" % + existing_datetime + ) + new = dateutil_parse(existing_datetime) + if new.tzinfo is None: + new = new.replace(tzinfo=DEFAULT_TIMEZONE) + log.debug( + "Datetime %s has no time zone info: assuming Europe/Zurich" % + new_datetime + ) except (ParserError, OverflowError) as e: log.info( "Error when parsing dates {}, {}: {}".format( existing_datetime, new_datetime, e ) ) + return False + if new == existing: return False return True From 9d32daadf1b2460f665e5e1064c111b40f5ca6ac Mon Sep 17 00:00:00 2001 From: Rae Knowler Date: Wed, 15 Nov 2023 14:21:04 +0100 Subject: [PATCH 2/2] fix: Fix wrong variable --- ckanext/dcatapchharvest/harvest_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/dcatapchharvest/harvest_helper.py b/ckanext/dcatapchharvest/harvest_helper.py index d68ef9f..1678b29 100644 --- a/ckanext/dcatapchharvest/harvest_helper.py +++ b/ckanext/dcatapchharvest/harvest_helper.py @@ -105,7 +105,7 @@ def _changes_in_date(existing_datetime, new_datetime): "Datetime %s has no time zone info: assuming Europe/Zurich" % existing_datetime ) - new = dateutil_parse(existing_datetime) + new = dateutil_parse(new_datetime) if new.tzinfo is None: new = new.replace(tzinfo=DEFAULT_TIMEZONE) log.debug(