Skip to content

Commit

Permalink
compare use same timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Apr 24, 2024
1 parent 3860f02 commit 4acf59f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions edc_consent/consent_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions edc_consent/site_consents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4acf59f

Please sign in to comment.