Skip to content

Commit

Permalink
Fix deprecated datetime.datetime.utcnow() usage
Browse files Browse the repository at this point in the history
DeprecationWarning: datetime.datetime.utcnow() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.now(datetime.UTC).

Signed-off-by: Zac Medico <[email protected]>
  • Loading branch information
zmedico committed Nov 4, 2024
1 parent c7d5d4e commit eec935e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/portage/repository/storage/hardlink_rcu.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,11 @@ async def garbage_collection(self):
st = os.stat(snap_path)
except OSError:
continue
snap_timestamp = datetime.datetime.utcfromtimestamp(st.st_mtime)
if (datetime.datetime.utcnow() - snap_timestamp) < snap_ttl:
snap_timestamp = datetime.datetime.fromtimestamp(
st.st_mtime, tz=datetime.timezone.utc
)
if (
datetime.datetime.now(datetime.timezone.utc) - snap_timestamp
) < snap_ttl:
continue
await self._check_call(["rm", "-rf", snap_path])
6 changes: 5 additions & 1 deletion lib/portage/sync/modules/rsync/rsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ def update(self):
raise RuntimeError("Timestamp not found in Manifest")
if (
self.max_age != 0
and (datetime.datetime.utcnow() - ts.ts).days > self.max_age
and (
datetime.datetime.now(datetime.timezone.utc)
- ts.ts.replace(tzinfo=datetime.timezone.utc)
).days
> self.max_age
):
out.quiet = False
out.ewarn(
Expand Down
2 changes: 1 addition & 1 deletion lib/portage/tests/sync/test_sync_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def bump_timestamp():
)
)

bump_timestamp.timestamp = datetime.datetime.utcnow()
bump_timestamp.timestamp = datetime.datetime.now(datetime.timezone.utc)

bump_timestamp_cmds = ((homedir, bump_timestamp),)

Expand Down

0 comments on commit eec935e

Please sign in to comment.