Skip to content

Commit f7a37ef

Browse files
yarikopticeffigies
authored andcommitted
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.
1 parent c5fa777 commit f7a37ef

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

nipype/interfaces/base/support.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from copy import deepcopy
1212
from textwrap import wrap
1313
import re
14-
from datetime import datetime as dt
14+
from datetime import datetime as dt, UTC
1515
from dateutil.parser import parse as parseutc
1616
import platform
1717

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

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

8181
def __exit__(self, exc_type, exc_value, exc_tb):
8282
"""Tear-down interface execution."""
83-
self._runtime.endTime = dt.isoformat(dt.utcnow())
83+
self._runtime.endTime = dt.isoformat(dt.now(UTC))
8484
timediff = parseutc(self._runtime.endTime) - parseutc(self._runtime.startTime)
8585
self._runtime.duration = (
8686
timediff.days * 86400 + timediff.seconds + timediff.microseconds / 1e6

nipype/pipeline/engine/workflows.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import os
99
import os.path as op
1010
import sys
11-
from datetime import datetime
11+
from datetime import datetime, UTC
1212
from copy import deepcopy
1313
import pickle
1414
import shutil
@@ -627,7 +627,7 @@ def run(self, plugin=None, plugin_args=None, updatehash=False):
627627
if str2bool(self.config["execution"]["create_report"]):
628628
self._write_report_info(self.base_dir, self.name, execgraph)
629629
runner.run(execgraph, updatehash=updatehash, config=self.config)
630-
datestr = datetime.utcnow().strftime("%Y%m%dT%H%M%S")
630+
datestr = datetime.now(UTC).strftime("%Y%m%dT%H%M%S")
631631
if str2bool(self.config["execution"]["write_provenance"]):
632632
prov_base = op.join(self.base_dir, "workflow_provenance_%s" % datestr)
633633
logger.info("Provenance file prefix: %s" % prov_base)

0 commit comments

Comments
 (0)