Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events to Bills: Add -1 Day to Match Query #141

Merged
merged 7 commits into from
Sep 16, 2024
7 changes: 6 additions & 1 deletion openstates/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import logging
import typing
from datetime import datetime, timedelta
from django.db.models import Q, Model
from django.db.models.signals import post_save
from .. import settings
Expand Down Expand Up @@ -168,8 +169,12 @@ def resolve_bill(self, bill_id: str, *, date: str) -> typing.Optional[_ID]:
if bill_transform_func:
bill_id = bill_transform_func(bill_id)

# move the start_date up a bit in case the event is on the last day of a session to compare with end_date
date = datetime.fromisoformat(date)
new_date = date - timedelta(days=1)

objects = Bill.objects.filter(
Q(legislative_session__end_date__gte=date)
Q(legislative_session__end_date__gte=new_date)
| Q(legislative_session__end_date=""),
legislative_session__start_date__lte=date,
legislative_session__jurisdiction_id=self.jurisdiction_id,
Expand Down
2 changes: 1 addition & 1 deletion openstates/importers/tests/test_event_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_other_jurisdiction():
def ge():
event = ScrapeEvent(
name="America's Birthday",
start_date="2014-07-04T05:00Z",
start_date="2014-07-04T05:00:00+00:00",
location_name="America",
all_day=True,
)
Expand Down
Loading