Skip to content

Commit 6e4bf20

Browse files
committed
Replace deprecated datetime.utcnow() with datetime.now(timezone.utc)
datetime.utcnow() emits DeprecationWarning under Python 3.12+ and is scheduled for removal in a future version. Switch to the recommended timezone-aware alternative. Note: datetime.timezone is Python 3.2+, so this drops Python 2.7 support. Python 2.7 has been EOL since 2020.
1 parent c2a0f18 commit 6e4bf20

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

aprslib/parsing/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import re
22
from math import sqrt
3-
from datetime import datetime
3+
from datetime import datetime, timezone
44
from aprslib import base91
55
from aprslib.exceptions import ParseError
66
from aprslib.parsing import logger
@@ -80,7 +80,7 @@ def parse_timestamp(body, packet_type=''):
8080
match = re.findall(r"^((\d{6})(.))$", body[0:7])
8181
if match:
8282
rawts, ts, form = match[0]
83-
utc = datetime.utcnow()
83+
utc = datetime.now(timezone.utc)
8484

8585
timestamp = 0
8686

tests/test_parse_common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
import string
33
from random import randint, randrange, sample
4-
from datetime import datetime
4+
from datetime import datetime, timezone
55

66
from aprslib import base91
77
from aprslib.parsing.common import *
@@ -178,8 +178,8 @@ def test_status_timestamp_invalid(self):
178178
})
179179

180180
def test_timestamp_valid(self):
181-
date = datetime.utcnow()
182-
td = date - datetime(1970, 1, 1)
181+
date = datetime.now(timezone.utc)
182+
td = date - datetime(1970, 1, 1, tzinfo=timezone.utc)
183183
timestamp = int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
184184

185185
# hhmmss format

0 commit comments

Comments
 (0)