fix: treat leap day properly in nomcom eligibility calc (#4393)

* fix: treat leap day in get_8989_eligibility_querysets()

* test: treat leap day properly in nomcom tests
This commit is contained in:
Jennifer Richards 2022-08-31 18:03:38 -03:00 committed by GitHub
parent fb56131960
commit b85ecce89f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 8 deletions

View file

@ -2452,8 +2452,13 @@ class rfc8989EligibilityTests(TestCase):
for nomcom in self.nomcoms:
elig_date=get_eligibility_date(nomcom)
day_before = elig_date-datetime.timedelta(days=1)
year_before = datetime.date(elig_date.year-1,elig_date.month,elig_date.day)
three_years_before = datetime.date(elig_date.year-3,elig_date.month,elig_date.day)
# special case for Feb 29
if elig_date.month == 2 and elig_date.day == 29:
year_before = datetime.date(elig_date.year - 1, 2, 28)
three_years_before = datetime.date(elig_date.year - 3, 2, 28)
else:
year_before = datetime.date(elig_date.year - 1, elig_date.month, elig_date.day)
three_years_before = datetime.date(elig_date.year - 3, elig_date.month, elig_date.day)
just_after_three_years_before = three_years_before + datetime.timedelta(days=1)
just_before_three_years_before = three_years_before - datetime.timedelta(days=1)
@ -2513,10 +2518,15 @@ class rfc8989EligibilityTests(TestCase):
elig_date = get_eligibility_date(nomcom)
last_date = elig_date
first_date = datetime.date(last_date.year-5,last_date.month,last_date.day)
# special case for Feb 29
if last_date.month == 2 and last_date.day == 29:
first_date = datetime.date(last_date.year - 5, 2, 28)
middle_date = datetime.date(last_date.year - 3, 2, 28)
else:
first_date = datetime.date(last_date.year - 5, last_date.month, last_date.day)
middle_date = datetime.date(last_date.year - 3, last_date.month, last_date.day)
day_after_last_date = last_date+datetime.timedelta(days=1)
day_before_first_date = first_date-datetime.timedelta(days=1)
middle_date = datetime.date(last_date.year-3,last_date.month,last_date.day)
eligible = set()
ineligible = set()
@ -2663,7 +2673,14 @@ class VolunteerDecoratorUnitTests(TestCase):
author_person = PersonFactory()
for i in range(2):
da = WgDocumentAuthorFactory(person=author_person)
DocEventFactory(type='published_rfc',doc=da.document,time=datetime.date(elig_date.year-3,elig_date.month,elig_date.day))
DocEventFactory(
type='published_rfc',
doc=da.document,
time=datetime.date(
elig_date.year - 3,
elig_date.month,
28 if elig_date.month == 2 and elig_date.day == 29 else elig_date.day,
))
nomcom.volunteer_set.create(person=author_person)
volunteers = nomcom.volunteer_set.all()

View file

@ -538,7 +538,14 @@ def get_8989_eligibility_querysets(date, base_qs):
previous_five = previous_five_meetings(date)
three_of_five_qs = new_three_of_five_eligible(previous_five=previous_five, queryset=base_qs)
three_years_ago = datetime.date(date.year-3,date.month,date.day)
# If date is Feb 29, neither 3 nor 5 years ago has a Feb 29. Use Feb 28 instead.
if date.month == 2 and date.day == 29:
three_years_ago = datetime.date(date.year - 3, 2, 28)
five_years_ago = datetime.date(date.year - 5, 2, 28)
else:
three_years_ago = datetime.date(date.year - 3, date.month, date.day)
five_years_ago = datetime.date(date.year - 5, date.month, date.day)
officer_qs = base_qs.filter(
# is currently an officer
Q(role__name_id__in=('chair','secr'),
@ -555,7 +562,6 @@ def get_8989_eligibility_querysets(date, base_qs):
)
).distinct()
five_years_ago = datetime.date(date.year-5,date.month,date.day)
rfc_pks = set(DocEvent.objects.filter(type='published_rfc',time__gte=five_years_ago,time__lte=date).values_list('doc__pk',flat=True))
iesgappr_pks = set(DocEvent.objects.filter(type='iesg_approved',time__gte=five_years_ago,time__lte=date).values_list('doc__pk',flat=True))
qualifying_pks = rfc_pks.union(iesgappr_pks.difference(rfc_pks))