Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: If modified date has no TZ, assume it's Europe/Zurich #91

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions ckanext/dcatapchharvest/harvest_helper.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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(new_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