diff --git a/src/soccer_managers.py b/src/soccer_managers.py index 125b45e4..947dd1e5 100644 --- a/src/soccer_managers.py +++ b/src/soccer_managers.py @@ -102,12 +102,9 @@ class BaseSoccerManager: else: self.logger.info("Favorite teams filtering disabled. Showing all teams.") - self.config_manager = ConfigManager() - def _get_timezone(self): try: - timezone_str = self.config_manager.get_timezone() - self.logger.debug(f"[Soccer] Config timezone: {timezone_str}") + timezone_str = self.config.get('timezone', 'UTC') return pytz.timezone(timezone_str) except pytz.UnknownTimeZoneError: self.logger.warning(f"[Soccer] Unknown timezone: {timezone_str}, falling back to UTC") @@ -508,7 +505,6 @@ class BaseSoccerManager: if start_time_utc: local_time = start_time_utc.astimezone(self._get_timezone()) game_time = local_time.strftime("%I:%M%p").lower().lstrip('0') # e.g., 2:30pm - self.logger.debug(f"[Soccer] Timezone conversion - UTC: {start_time_utc}, Local: {local_time}, Formatted: {game_time}") # Check date format from config use_short_date_format = self.config.get('display', {}).get('use_short_date_format', False) diff --git a/test/test_soccer_timezone_fix.py b/test/test_soccer_timezone_fix.py new file mode 100644 index 00000000..4e9a91af --- /dev/null +++ b/test/test_soccer_timezone_fix.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +""" +Test script to verify the soccer manager timezone fix. +""" + +import sys +import os +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + +from datetime import datetime +import pytz + +def test_timezone_fix(): + """Test that the timezone logic works correctly.""" + + # Mock config with America/Chicago timezone + config = { + 'timezone': 'America/Chicago' + } + + # Simulate the _get_timezone method logic + def _get_timezone(): + try: + timezone_str = config.get('timezone', 'UTC') + return pytz.timezone(timezone_str) + except pytz.UnknownTimeZoneError: + print(f"Warning: Unknown timezone: {timezone_str}, falling back to UTC") + return pytz.utc + except Exception as e: + print(f"Error getting timezone: {e}, falling back to UTC") + return pytz.utc + + # Test timezone conversion + utc_time = datetime.now(pytz.utc) + local_time = utc_time.astimezone(_get_timezone()) + + print(f"UTC time: {utc_time}") + print(f"Local time (America/Chicago): {local_time}") + print(f"Timezone name: {local_time.tzinfo}") + + # Verify it's not UTC + if str(local_time.tzinfo) != 'UTC': + print("āœ… SUCCESS: Timezone conversion is working correctly!") + print(f" Expected: America/Chicago timezone") + print(f" Got: {local_time.tzinfo}") + else: + print("āŒ FAILURE: Still using UTC timezone!") + return False + + # Test time formatting (same as in soccer manager) + formatted_time = local_time.strftime("%I:%M%p").lower().lstrip('0') + print(f"Formatted time: {formatted_time}") + + # Test with a specific UTC time to verify conversion + test_utc = datetime(2024, 1, 15, 19, 30, 0, tzinfo=pytz.utc) # 7:30 PM UTC + test_local = test_utc.astimezone(_get_timezone()) + test_formatted = test_local.strftime("%I:%M%p").lower().lstrip('0') + + print(f"\nTest conversion:") + print(f" 7:30 PM UTC -> {test_local.strftime('%I:%M %p')} {test_local.tzinfo}") + print(f" Formatted: {test_formatted}") + + return True + +if __name__ == "__main__": + print("Testing soccer manager timezone fix...") + success = test_timezone_fix() + if success: + print("\nšŸŽ‰ All tests passed!") + else: + print("\nšŸ’„ Tests failed!") + sys.exit(1)