8000 migrate from utcfromtimestamp to fromtimestamp (#25918) · matplotlib/matplotlib@6df1bb3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6df1bb3

Browse files
authored
migrate from utcfromtimestamp to fromtimestamp (#25918)
closes #25912
1 parent 8293774 commit 6df1bb3

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

doc/api/prev_api_changes/api_changes_3.7.0/removals.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Removals
77
These methods convert from unix timestamps to matplotlib floats, but are not
88
used internally to Matplotlib, and should not be needed by end users. To
99
convert a unix timestamp to datetime, simply use
10-
`datetime.datetime.utcfromtimestamp`, or to use NumPy `~numpy.datetime64`
10+
`datetime.datetime.fromtimestamp`, or to use NumPy `~numpy.datetime64`
1111
``dt = np.datetime64(e*1e6, 'us')``.
1212

1313
Locator and Formatter wrapper methods

doc/conf.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import matplotlib
2525

26+
from datetime import timezone
2627
from datetime import datetime
2728
import time
2829

@@ -73,8 +74,8 @@ def _parse_skip_subdirs_file():
7374

7475
# Parse year using SOURCE_DATE_EPOCH, falling back to current time.
7576
# https://reproducible-builds.org/specs/source-date-epoch/
76-
sourceyear = datetime.utcfromtimestamp(
77-
int(os.environ.get('SOURCE_DATE_EPOCH', time.time()))).year
77+
sourceyear = datetime.fromtimestamp(
78+
int(os.environ.get('SOURCE_DATE_EPOCH', time.time())), timezone.utc).year
7879

7980
# If your extensions are in another directory, add it here. If the directory
8081
# is relative to the documentation root, use os.path.abspath to make it

lib/matplotlib/backends/backend_pdf.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import codecs
8+
from datetime import timezone
89
from datetime import datetime
910
from enum import Enum
1011
from functools import total_ordering
@@ -148,7 +149,7 @@ def _create_pdf_info_dict(backend, metadata):
148149
# See https://reproducible-builds.org/specs/source-date-epoch/
149150
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
150151
if source_date_epoch:
151-
source_date = datetime.utcfromtimestamp(int(source_date_epoch))
152+
source_date = datetime.fromtimestamp(int(source_date_epoch), timezone.utc)
152153
source_date = source_date.replace(tzinfo=UTC)
153154
else:
154155
source_date = datetime.today()

lib/matplotlib/backends/backend_ps.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,9 @@ def _print_ps(
826826
# See https://reproducible-builds.org/specs/source-date-epoch/
827827
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
828828
dsc_comments["CreationDate"] = (
829-
datetime.datetime.utcfromtimestamp(
830-
int(source_date_epoch)).strftime("%a %b %d %H:%M:%S %Y")
829+
datetime.datetime.fromtimestamp(
830+
int(source_date_epoch),
831+
datetime.timezone.utc).strftime("%a %b %d %H:%M:%S %Y")
831832
if source_date_epoch
832833
else time.ctime())
833834
dsc_comments = "\n".join(

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ def _write_metadata(self, metadata):
380380
# See https://reproducible-builds.org/specs/source-date-epoch/
381381
date = os.getenv("SOURCE_DATE_EPOCH")
382382
if date:
383-
date = datetime.datetime.utcfromtimestamp(int(date))
383+
date = datetime.datetime.fromtimestamp(int(date), datetime.timezone.utc)
384384
metadata['Date'] = date.replace(tzinfo=UTC).isoformat()
385385
else:
386386
metadata['Date'] = datetime.datetime.today().isoformat()

0 commit comments

Comments
 (0)
0