Skip to content

Commit

Permalink
replace utcnow (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram authored Nov 22, 2023
1 parent f42b477 commit 0ed03c2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
3 changes: 2 additions & 1 deletion src/stdatamodels/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions tests/test_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone

import pytest

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0ed03c2

Please sign in to comment.