fix: UttlesfordDistrictCouncil year and bin type parsing#1823
fix: UttlesfordDistrictCouncil year and bin type parsing#1823Russell-IO wants to merge 6 commits into
Conversation
Replace hardcoded 2024 year with dynamic year calculation that uses the current year, or next year if the collection date has already passed. This fixes incorrect dates being returned for all collections.
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. 📝 WalkthroughWalkthroughUttlesford parser: derive bin types from image filenames and compute collection year dynamically (use current year, increment if parsed date already passed). East Herts parser: skip rows with empty/whitespace "NextDate" values to avoid creating invalid BinType/collection entries. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1823 +/- ##
=======================================
Coverage 86.67% 86.67%
=======================================
Files 9 9
Lines 1141 1141
=======================================
Hits 989 989
Misses 152 152 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Pull request overview
Fixes incorrect bin collection years for Uttlesford District Council by removing a hardcoded 2024 and selecting the appropriate year dynamically.
Changes:
- Replace hardcoded year
2024with the current year at runtime. - Roll collection dates into the next year when the computed date has already passed.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| current_year = datetime.now().year | ||
| collection_date = collection_date.replace(year=current_year) | ||
| if collection_date < datetime.now(): |
There was a problem hiding this comment.
The collection_date < datetime.now() comparison includes the current time-of-day, but collection_date is parsed with a default time of 00:00. This means a collection scheduled for today will almost always be treated as “already passed” and have its year incremented. Consider capturing now = datetime.now() once and comparing collection_date.date() < now.date() (or otherwise normalizing times) before applying the +1 year adjustment.
| current_year = datetime.now().year | |
| collection_date = collection_date.replace(year=current_year) | |
| if collection_date < datetime.now(): | |
| now = datetime.now() | |
| current_year = now.year | |
| collection_date = collection_date.replace(year=current_year) | |
| if collection_date.date() < now.date(): |
Use .date() comparison to avoid incorrectly treating today's collections as past dates due to time-of-day differences.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py`:
- Around line 96-100: The code uses datetime.strptime(...) to build
collection_date (midnight) then compares it to datetime.now() (includes time),
causing a collection on the current day to be seen as past and rolled to next
year; fix by capturing today = datetime.now().date() once and compare
collection_date.date() to today (or assign the year using today's year and if
collection_date.date() < today then use today.year + 1) so the comparison is
date-only. Update the logic around collection_date, collection_date_str,
datetime.strptime and datetime.now() to use the single captured today value and
date() comparisons.
🧹 Nitpick comments (1)
uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py (1)
96-100: Consider making thedatetimeimport explicit for clarity.While
datetimeis available via the star import fromcommon.py, explicitly importingfrom datetime import datetimemakes the dependency clearer and reduces reliance on star imports—a best practice for maintainability.🔧 Suggested change
+from datetime import datetime from uk_bin_collection.uk_bin_collection.common import *
Make datetime dependency explicit rather than relying on star import from common.py for better maintainability.
The council website has incorrect alt text on images in the data table. Map image filenames (key-brown.png, key-black.png, key-green.png) to the correct bin types instead of relying on the erroneous alt attributes.
Skip bin types that have empty date strings in the API response to prevent datetime parsing errors.
Extract bin color from image filename (brown, black, green) instead of mapping to full waste type descriptions.
|
This PR has been merged into the February 2026 consolidated release PR #1837. Thank you for your contribution! |
UttlesfordDistrictCouncil
EastHertsCouncil
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.