Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace utcnow #231

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not inline dt inside entry?

})

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
Loading