diff --git a/edc_consent/consent_definition.py b/edc_consent/consent_definition.py index 6bbe0b3..7854d4c 100644 --- a/edc_consent/consent_definition.py +++ b/edc_consent/consent_definition.py @@ -69,8 +69,12 @@ def __post_init__(self): raise ConsentDefinitionError(f"Invalid gender. Got {self.gender}.") if not self.start.tzinfo: raise ConsentDefinitionError(f"Naive datetime not allowed. Got {self.start}.") + elif str(self.start.tzinfo) != "UTC": + raise ConsentDefinitionError(f"Start date must be UTC. Got {self.start}.") if not self.end.tzinfo: raise ConsentDefinitionError(f"Naive datetime not allowed Got {self.end}.") + elif str(self.end.tzinfo) != "UTC": + raise ConsentDefinitionError(f"End date must be UTC. Got {self.end}.") self.check_date_within_study_period() @property diff --git a/edc_consent/site_consents.py b/edc_consent/site_consents.py index b5ccdb9..84b0ff6 100644 --- a/edc_consent/site_consents.py +++ b/edc_consent/site_consents.py @@ -9,7 +9,7 @@ from django.core.management.color import color_style from django.utils.module_loading import import_module, module_has_submodule from edc_sites.site import sites as site_sites -from edc_utils import ceil_secs, floor_secs, formatted_date +from edc_utils import ceil_secs, floor_secs, formatted_date, to_utc from .exceptions import ( AlreadyRegistered, @@ -141,7 +141,7 @@ def get_consent_or_raise( subject_identifier=subject_identifier, raise_if_not_consented=raise_if_not_consented, ) - if consent_obj and report_datetime < consent_obj.consent_datetime: + if consent_obj and to_utc(report_datetime) < consent_obj.consent_datetime: if not cdef.updates: dte = formatted_date(report_datetime) raise ConsentDefinitionNotConfiguredForUpdate( @@ -257,7 +257,7 @@ def _filter_cdefs_by_report_datetime_or_raise( cdefs = [ cdef for cdef in cdefs - if floor_secs(cdef.start) <= report_datetime <= ceil_secs(cdef.end) + if floor_secs(cdef.start) <= to_utc(report_datetime) <= ceil_secs(cdef.end) ] if not cdefs: date_string = formatted_date(report_datetime)