diff --git a/CHANGES.rst b/CHANGES.rst index 42889c7f..61bc2261 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -16,6 +16,8 @@ Other - Add mrsptcorr ref_file to core.schema [#228] +- Replace uses of ``utcnow`` (deprecated in python 3.12) [#231] + - Updated JWST MIRI imager photom model to include time-dependent correction coeffs. [#235] diff --git a/src/stdatamodels/util.py b/src/stdatamodels/util.py index 3fdcbbc2..96f7fe3f 100644 --- a/src/stdatamodels/util.py +++ b/src/stdatamodels/util.py @@ -227,9 +227,10 @@ def create_history_entry(description, software=None): elif software is not None: software = Software(software) + dt = datetime.datetime.now(datetime.timezone.utc).replace(tzinfo=None) entry = HistoryEntry({ 'description': description, - 'time': datetime.datetime.utcnow() + 'time': dt }) if software is not None: diff --git a/tests/test_util.py b/tests/test_util.py index b32ca8a0..a2266f7c 100644 --- a/tests/test_util.py +++ b/tests/test_util.py @@ -1,4 +1,4 @@ -from datetime import datetime, timedelta +from datetime import datetime, timedelta, timezone import pytest @@ -259,7 +259,8 @@ def test_create_history_entry(): assert isinstance(entry, HistoryEntry) assert entry["description"] == "Once upon a time..." assert entry.get("software") is None - assert (datetime.utcnow() - entry["time"]) < timedelta(seconds=10) + dt = datetime.now(timezone.utc).replace(tzinfo=None) + assert (dt - entry["time"]) < timedelta(seconds=10) software = {"name": "PolarBearSoft", "version": "1.2.3"} entry = util.create_history_entry("There was a tie-dyed polar bear...", software)