Skip to content

Commit

Permalink
Replace use of datetime.datetime.utcfromtimestamp()
Browse files Browse the repository at this point in the history
This is deprecated in Python 3.12.

Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Jan 16, 2024
1 parent fba72ac commit fd98bd4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion patchwork/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import codecs
import datetime
from datetime import timezone
from email.header import decode_header
from email.header import make_header
from email.utils import mktime_tz
Expand Down Expand Up @@ -468,7 +469,9 @@ def find_date(mail):
return tz_utils.now()

try:
d = datetime.datetime.utcfromtimestamp(mktime_tz(t))
d = datetime.datetime.fromtimestamp(
mktime_tz(t), tz=timezone.utc
).replace(tzinfo=None)
except (OverflowError, ValueError, OSError):
# If you have a date like:
# - Date: Wed, 4 Jun 207777777777777777777714 17:50:46 0
Expand Down
5 changes: 4 additions & 1 deletion patchwork/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later

import datetime
from datetime import timezone
from email.encoders import encode_7or8bit
from email.header import Header
from email.mime.nonmultipart import MIMENonMultipart
Expand Down Expand Up @@ -76,7 +77,9 @@ def _submission_to_mbox(submission):
if is_patch and submission.diff:
body += '\n' + submission.diff

delta = submission.date - datetime.datetime.utcfromtimestamp(0)
delta = submission.date - datetime.datetime.fromtimestamp(
0, tz=timezone.utc
).replace(tzinfo=None)
utc_timestamp = delta.seconds + delta.days * 24 * 3600

mail = PatchMbox(body)
Expand Down

0 comments on commit fd98bd4

Please sign in to comment.