From 6e4bf203a9d5458ce63ed795785d89069b46c9d0 Mon Sep 17 00:00:00 2001 From: Jeremy Elson Date: Wed, 20 May 2026 14:52:17 -0700 Subject: [PATCH] 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. --- aprslib/parsing/common.py | 4 ++-- tests/test_parse_common.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/aprslib/parsing/common.py b/aprslib/parsing/common.py index fa5a465..f2eb05d 100644 --- a/aprslib/parsing/common.py +++ b/aprslib/parsing/common.py @@ -1,6 +1,6 @@ import re from math import sqrt -from datetime import datetime +from datetime import datetime, timezone from aprslib import base91 from aprslib.exceptions import ParseError from aprslib.parsing import logger @@ -80,7 +80,7 @@ def parse_timestamp(body, packet_type=''): match = re.findall(r"^((\d{6})(.))$", body[0:7]) if match: rawts, ts, form = match[0] - utc = datetime.utcnow() + utc = datetime.now(timezone.utc) timestamp = 0 diff --git a/tests/test_parse_common.py b/tests/test_parse_common.py index 69c8d73..c68b8f1 100644 --- a/tests/test_parse_common.py +++ b/tests/test_parse_common.py @@ -1,7 +1,7 @@ import unittest import string from random import randint, randrange, sample -from datetime import datetime +from datetime import datetime, timezone from aprslib import base91 from aprslib.parsing.common import * @@ -178,8 +178,8 @@ def test_status_timestamp_invalid(self): }) def test_timestamp_valid(self): - date = datetime.utcnow() - td = date - datetime(1970, 1, 1) + date = datetime.now(timezone.utc) + td = date - datetime(1970, 1, 1, tzinfo=timezone.utc) timestamp = int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6) # hhmmss format