From e4689356337d84b93d7611a77d6cb0b8d0355469 Mon Sep 17 00:00:00 2001 From: Jonathan Willitts Date: Fri, 12 Apr 2024 16:00:41 +0100 Subject: [PATCH] Use only floor/ceil_secs when comparing with consent start/end datetimes --- edc_consent/consent_definition.py | 14 ++++++-------- edc_consent/site_consents.py | 7 ++----- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/edc_consent/consent_definition.py b/edc_consent/consent_definition.py index caeefe0..a90bd6e 100644 --- a/edc_consent/consent_definition.py +++ b/edc_consent/consent_definition.py @@ -10,8 +10,8 @@ from edc_protocol.research_protocol_config import ResearchProtocolConfig from edc_screening.utils import get_subject_screening_model from edc_sites import site_sites -from edc_utils import floor_secs, formatted_date, formatted_datetime -from edc_utils.date import ceil_datetime, floor_datetime, to_local +from edc_utils import ceil_secs, floor_secs, formatted_date, formatted_datetime +from edc_utils.date import to_local from .exceptions import ( ConsentDefinitionError, @@ -158,9 +158,7 @@ def verbose_name(self) -> str: def valid_for_datetime_or_raise(self, report_datetime: datetime) -> None: if report_datetime and not ( - floor_secs(floor_datetime(self.start)) - <= floor_secs(floor_datetime(report_datetime)) - <= floor_secs(floor_datetime(self.end)) + floor_secs(self.start) <= report_datetime <= ceil_secs(self.end) ): date_string = formatted_date(report_datetime) raise ConsentDefinitionValidityPeriodError( @@ -177,9 +175,9 @@ def check_date_within_study_period(self) -> None: study_close_datetime = protocol.study_close_datetime for index, attr in enumerate(["start", "end"]): if not ( - floor_secs(floor_datetime(study_open_datetime)) - <= floor_secs(floor_datetime(getattr(self, attr))) - <= floor_secs(ceil_datetime(study_close_datetime)) + floor_secs(study_open_datetime) + <= getattr(self, attr) + <= ceil_secs(study_close_datetime) ): date_string = formatted_datetime(getattr(self, attr)) raise ConsentDefinitionError( diff --git a/edc_consent/site_consents.py b/edc_consent/site_consents.py index ca58108..a6f1c11 100644 --- a/edc_consent/site_consents.py +++ b/edc_consent/site_consents.py @@ -8,8 +8,7 @@ from django.apps import apps as django_apps from django.core.management.color import color_style from django.utils.module_loading import import_module, module_has_submodule -from edc_utils import floor_secs, formatted_date -from edc_utils.date import floor_datetime +from edc_utils import ceil_secs, floor_secs, formatted_date from .exceptions import ( AlreadyRegistered, @@ -256,9 +255,7 @@ def _filter_cdefs_by_report_datetime_or_raise( cdefs = [ cdef for cdef in cdefs - if floor_secs(floor_datetime(cdef.start)) - <= floor_secs(floor_datetime(report_datetime)) - <= floor_secs(floor_datetime(cdef.end)) + if floor_secs(cdef.start) <= report_datetime <= ceil_secs(cdef.end) ] if not cdefs: date_string = formatted_date(report_datetime)