diff --git a/README.md b/README.md index 0c105ed..b62ab66 100644 --- a/README.md +++ b/README.md @@ -48,9 +48,9 @@ Because we all have that one colleague who keeps asking "How many days till the This script does not guarantee: -That you'll actually take your holiday -That the government won't change their mind about holidays -That your boss will let you go on holiday +* That you'll actually take your holiday +* That the government won't change their mind about holidays +* That your boss will let you go on holiday 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 diff --git a/main.py b/main.py index eee6d30..9afd1ff 100644 --- a/main.py +++ b/main.py @@ -24,24 +24,27 @@ def get_next_bank_holiday(holidays_data): next_holiday = None min_diff = None - # Process England and Wales holidays (main data source) - if "england-and-wales" in holidays_data: - for event in holidays_data["england-and-wales"]["events"]: - try: - # Parse the date string manually since we don't have dateutil - holiday_date = datetime.strptime(event["date"], "%Y-%m-%d").date() - if holiday_date >= today: - 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): + if "england-and-wales" not in holidays_data: + return None + + for event in holidays_data["england-and-wales"]["events"]: + try: + holiday_date = datetime.strptime(event["date"], "%Y-%m-%d").date() + + if holiday_date < today: 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