Skip to content

Use regular ".now" instead of ".utcnow" with UTC zone #3670

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

Merged
merged 2 commits into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use regular ".now" instead of ".utcnow" with UTC zone
It is mandated by starting to receive a DeprecationWarning in python 3.12

    DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC)

discovered while addressing some other rot in heudiconv.
  • Loading branch information
yarikoptic authored and effigies committed Oct 6, 2024
commit f7a37efc1b3a7001b6b224b007abe524a60b6a17
6 changes: 3 additions & 3 deletions nipype/interfaces/base/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from copy import deepcopy
from textwrap import wrap
import re
from datetime import datetime as dt
from datetime import datetime as dt, UTC
from dateutil.parser import parse as parseutc
import platform

Expand Down Expand Up @@ -72,15 +72,15 @@ def __enter__(self):
if self._runtime.redirect_x:
self._runtime.environ["DISPLAY"] = config.get_display()

self._runtime.startTime = dt.isoformat(dt.utcnow())
self._runtime.startTime = dt.isoformat(dt.now(UTC))
self._resmon.start()
# TODO: Perhaps clean-up path and ensure it exists?
os.chdir(self._runtime.cwd)
return self._runtime

def __exit__(self, exc_type, exc_value, exc_tb):
"""Tear-down interface execution."""
self._runtime.endTime = dt.isoformat(dt.utcnow())
self._runtime.endTime = dt.isoformat(dt.now(UTC))
timediff = parseutc(self._runtime.endTime) - parseutc(self._runtime.startTime)
self._runtime.duration = (
timediff.days * 86400 + timediff.seconds + timediff.microseconds / 1e6
Expand Down
4 changes: 2 additions & 2 deletions nipype/pipeline/engine/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import os
import os.path as op
import sys
from datetime import datetime
from datetime import datetime, UTC
from copy import deepcopy
import pickle
import shutil
Expand Down Expand Up @@ -627,7 +627,7 @@ def run(self, plugin=None, plugin_args=None, updatehash=False):
if str2bool(self.config["execution"]["create_report"]):
self._write_report_info(self.base_dir, self.name, execgraph)
runner.run(execgraph, updatehash=updatehash, config=self.config)
datestr = datetime.utcnow().strftime("%Y%m%dT%H%M%S")
datestr = datetime.now(UTC).strftime("%Y%m%dT%H%M%S")
if str2bool(self.config["execution"]["write_provenance"]):
prov_base = op.join(self.base_dir, "workflow_provenance_%s" % datestr)
logger.info("Provenance file prefix: %s" % prov_base)
Expand Down