fix: 🐛 Now shows when today is a bank holiday
This commit is contained in:
@@ -48,9 +48,9 @@ Because we all have that one colleague who keeps asking "How many days till the
|
|||||||
|
|
||||||
This script does not guarantee:
|
This script does not guarantee:
|
||||||
|
|
||||||
That you'll actually take your holiday
|
* That you'll actually take your holiday
|
||||||
That the government won't change their mind about holidays
|
* That the government won't change their mind about holidays
|
||||||
That your boss will let you go on holiday
|
* That your boss will let you go on holiday
|
||||||
But it does guarantee that you'll know exactly when the next one is!
|
But it does guarantee that you'll know exactly when the next one is!
|
||||||
|
|
||||||
Made with ❤️ and ☕ by someone who's definitely going to take their holiday
|
Made with ❤️ and ☕ by someone who's definitely going to take their holiday
|
||||||
|
|||||||
@@ -24,24 +24,27 @@ def get_next_bank_holiday(holidays_data):
|
|||||||
next_holiday = None
|
next_holiday = None
|
||||||
min_diff = None
|
min_diff = None
|
||||||
|
|
||||||
# Process England and Wales holidays (main data source)
|
if "england-and-wales" not in holidays_data:
|
||||||
if "england-and-wales" in holidays_data:
|
return None
|
||||||
for event in holidays_data["england-and-wales"]["events"]:
|
|
||||||
try:
|
for event in holidays_data["england-and-wales"]["events"]:
|
||||||
# Parse the date string manually since we don't have dateutil
|
try:
|
||||||
holiday_date = datetime.strptime(event["date"], "%Y-%m-%d").date()
|
holiday_date = datetime.strptime(event["date"], "%Y-%m-%d").date()
|
||||||
if holiday_date >= today:
|
|
||||||
diff = (holiday_date - today).days
|
if holiday_date < today:
|
||||||
if min_diff is None or diff < min_diff:
|
|
||||||
min_diff = diff
|
|
||||||
next_holiday = {
|
|
||||||
"title": event["title"],
|
|
||||||
"date": holiday_date,
|
|
||||||
"days_until": diff,
|
|
||||||
}
|
|
||||||
except (ValueError, KeyError):
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
diff = (holiday_date - today).days
|
||||||
|
if min_diff is None or diff < min_diff:
|
||||||
|
min_diff = diff
|
||||||
|
next_holiday = {
|
||||||
|
"title": event["title"],
|
||||||
|
"date": holiday_date,
|
||||||
|
"days_until": diff,
|
||||||
|
}
|
||||||
|
except (ValueError, KeyError):
|
||||||
|
continue
|
||||||
|
|
||||||
return next_holiday
|
return next_holiday
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user