Skip to content

Commit

Permalink
using isoparse for less strict validations on date
Browse files Browse the repository at this point in the history
  • Loading branch information
DraKen0009 committed Jan 23, 2025
1 parent 2f59824 commit a9e68af
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions care/emr/resources/questionnaire/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from datetime import datetime
from urllib.parse import urlparse

from dateutil.parser import isoparse
from django.utils import timezone
from rest_framework.exceptions import ValidationError

Expand Down Expand Up @@ -63,9 +64,9 @@ def validate_data(values, value_type, questionnaire_ref): # noqa PLR0912
if value.value.lower() not in ["true", "false", "1", "0"]:
errors.append(f"Invalid boolean value: {value.value}")
elif value_type == QuestionType.date.value:
datetime.strptime(value.value, "%Y-%m-%d").date() # noqa DTZ007
isoparse(value.value).date()
elif value_type == QuestionType.datetime.value:
datetime.strptime(value.value, "%Y-%m-%dT%H:%M:%S") # noqa DTZ007
isoparse(value.value)
elif value_type == QuestionType.time.value:
datetime.strptime(value.value, "%H:%M:%S") # noqa DTZ007
elif value_type == QuestionType.choice.value:
Expand Down

0 comments on commit a9e68af

Please sign in to comment.