Fix deprecation warning with datetime.utcnow

We need to generate a timezone aware "now" time
the proper way since the utcnow() method was
deprecated in python 3.12.

[1] https://blog.ganssle.io/articles/2019/11/utcnow.html

Change-Id: Ic91dbd3d0fb0bab5725d09fd8d658baaefed8440
This commit is contained in:
Goutham Pacha Ravi 2024-06-29 00:23:36 -07:00
parent c39c412d6f
commit de2e2ab58e

View File

@ -96,7 +96,7 @@ def to_datetime(s, default=None):
if s is None:
return default
s = s.rpartition('.')[0]
return datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S')
return datetime.datetime.strptime(s, '%Y-%m-%d %H:%M:%S').replace(tzinfo=datetime.timezone.utc)
def find_latest_revision(review):
@ -125,7 +125,7 @@ def when_majority(review, required_count):
"Return the date when the vote reached the required count."
n = 0
votes = review['labels'].get('Rollcall-Vote', {}).get('all', [])
now = datetime.datetime.now()
now = datetime.datetime.now(datetime.timezone.utc)
for vote in sorted(votes, key=lambda x: to_datetime(x.get('date'), now)):
if vote.get('value'):
n += 1
@ -195,7 +195,7 @@ def get_one_status(change, delegates, tc_members):
latest = find_latest_revision(change)
latest_created = to_datetime(latest['created'])
now = datetime.datetime.utcnow()
now = datetime.datetime.now(datetime.timezone.utc)
age = now - latest_created
earliest = ''