From 67530164b49742543058352f8eeca2d17b450e16 Mon Sep 17 00:00:00 2001 From: Onur Ege Date: Sun, 5 Apr 2026 19:35:47 +0300 Subject: [PATCH] fix: replace deprecated datetime.utcnow() in Elexon plotting and tests Python 3.12+ deprecates datetime.utcnow(). Replaced with datetime.now(UTC) in both elexon_plots.py and its test file, preserving existing behavior for start/end datetime calculations. - src/plots/elexon_plots.py: import UTC, use datetime.now(UTC) - tests/test_elexon_plot.py: import UTC, use datetime.now(UTC) Fixes #403 Co-Authored-By: Claude Opus 4.6 --- src/plots/elexon_plots.py | 4 ++-- tests/test_elexon_plot.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plots/elexon_plots.py b/src/plots/elexon_plots.py index ea6edc65..d774b1f4 100644 --- a/src/plots/elexon_plots.py +++ b/src/plots/elexon_plots.py @@ -1,6 +1,6 @@ from typing import Callable, List, Optional, Tuple, Union import pandas as pd -from datetime import datetime, date, timedelta +from datetime import datetime, date, timedelta, UTC from plotly import graph_objects as go import streamlit as st from elexonpy.api_client import ApiClient @@ -132,7 +132,7 @@ def determine_start_and_end_datetimes( - start_datetime_utc: datetime object in UTC - end_datetime_utc: datetime object in UTC """ - now = datetime.utcnow() + now = datetime.now(UTC) # Determine start_datetime_utc if start_datetimes: diff --git a/tests/test_elexon_plot.py b/tests/test_elexon_plot.py index 2b94df0e..61ab68c6 100644 --- a/tests/test_elexon_plot.py +++ b/tests/test_elexon_plot.py @@ -1,7 +1,7 @@ from unittest.mock import Mock, patch import pandas as pd import pytest -from datetime import datetime +from datetime import datetime, UTC from plotly import graph_objects as go from plots.elexon_plots import add_elexon_plot, determine_start_and_end_datetimes, fetch_forecast_data from elexonpy.api_client import ApiClient @@ -9,7 +9,7 @@ def test_determine_start_and_end_datetimes_no_input(): # Test with no input - now = datetime.utcnow() + now = datetime.now(UTC) start, end = determine_start_and_end_datetimes([], []) assert start < now, "Start time should be before current time." assert end > start, "End time should be after start time."