Fix deprecated utcfromtimestamp() usage.
Fixes the following build warning:
build_image.py:53: DeprecationWarning: datetime.datetime.utcfromtimestamp() is deprecated and scheduled for removal in a future version. Use timezone-aware objects to represent datetimes in UTC: datetime.datetime.fromtimestamp(timestamp, datetime.UTC).
Bug: 402676308
Test: presubmit
Change-Id: I5fe76402231a43aedf5ff5b3ad945fc117d64ffa
diff --git a/tools/releasetools/build_image.py b/tools/releasetools/build_image.py
index b6c96c4..08b4d6a 100755
--- a/tools/releasetools/build_image.py
+++ b/tools/releasetools/build_image.py
@@ -49,8 +49,8 @@
# Use a fixed timestamp (01/01/2009 00:00:00 UTC) for files when packaging
# images. (b/24377993, b/80600931)
FIXED_FILE_TIMESTAMP = int((
- datetime.datetime(2009, 1, 1, 0, 0, 0, 0, None) -
- datetime.datetime.utcfromtimestamp(0)).total_seconds())
+ datetime.datetime(2009, 1, 1, 0, 0, 0, 0, datetime.UTC) -
+ datetime.datetime.fromtimestamp(0, datetime.UTC)).total_seconds())
class BuildImageError(Exception):
diff --git a/tools/releasetools/common.py b/tools/releasetools/common.py
index b6cbb15..e5f5f92 100644
--- a/tools/releasetools/common.py
+++ b/tools/releasetools/common.py
@@ -2993,7 +2993,7 @@
os.chmod(filename, perms)
# Use a fixed timestamp so the output is repeatable.
- # Note: Use of fromtimestamp rather than utcfromtimestamp here is
+ # Note: Use of fromtimestamp without specifying a timezone here is
# intentional. zip stores datetimes in local time without a time zone
# attached, so we need "epoch" but in the local time zone to get 2009/01/01
# in the zip archive.