Skip to content

Commit

Permalink
Merge branch 'main' into update-pull-request-template
Browse files Browse the repository at this point in the history
  • Loading branch information
Donna-H authored May 29, 2024
2 parents 333e3ad + 09b54b6 commit 1ca5dd5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions judgments/forms/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from crispy_forms_gds.fields import DateInputField
from django import forms
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator

from .validators import ValidateYearRange
Expand Down Expand Up @@ -80,9 +81,14 @@ def compress(self, data_list):
month = 1
if not day:
day = 1
if self.date_type == "to":
elif self.date_type == "to":
if not month:
month = 12
if not day:
day = monthrange(year, month)[1]
return date(year=year, month=month, day=day) # type: ignore
else:
raise RuntimeError("date_type is neither `from` nor `to`")
try:
return date(day=day, month=month, year=year)
except ValueError as e:
raise ValidationError(str(e)) from e

0 comments on commit 1ca5dd5

Please sign in to comment.