commit: c060c60de4406e9a6b8da50db1bc659d44b5de49 Author: Florian Schmaus <flow <AT> gentoo <DOT> org> AuthorDate: Fri Sep 12 12:32:22 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Fri Sep 12 21:17:57 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c060c60d
bintree: factor out convUnixTs into portage.util.time:unix_to_iso_time We will use this function at another place in a follow up commit and this function may be used in the future in other places as well, so the factor function out. Signed-off-by: Florian Schmaus <flow <AT> gentoo.org> Part-of: https://github.com/gentoo/portage/pull/1461 Signed-off-by: Sam James <sam <AT> gentoo.org> lib/portage/dbapi/bintree.py | 13 ++++--------- lib/portage/util/time.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py index a3505d1590..4009f76e6f 100644 --- a/lib/portage/dbapi/bintree.py +++ b/lib/portage/dbapi/bintree.py @@ -18,6 +18,7 @@ portage.proxy.lazyimport.lazyimport( "portage.update:update_dbentries", "portage.util:atomic_ofstream,ensure_dirs,normalize_path," + "writemsg,writemsg_stdout", + "portage.util.time:unix_to_iso_time", "portage.util.path:first_existing", "portage.util._async.SchedulerInterface:SchedulerInterface", "portage.util._urlopen:urlopen@_urlopen,have_pep_476@_have_pep_476,http_to_timestamp", @@ -61,7 +62,6 @@ from portage import _unicode_decode from portage import _unicode_encode import codecs -import datetime import errno import io import json @@ -1623,16 +1623,11 @@ class binarytree: if repo.frozen: desc = "frozen" else: - - def convUnixTs(ts): - dt = datetime.datetime.fromtimestamp( - int(ts), datetime.timezone.utc - ) - return dt.isoformat() - desc = "up-to-date" if remote_timestamp and verbose: - extra_info = f" (local: {convUnixTs(local_timestamp)}, remote: {convUnixTs(remote_timestamp)})" + local_iso_time = unix_to_iso_time(local_timestamp) + remote_iso_time = unix_to_iso_time(remote_timestamp) + extra_info = f" (local: {local_iso_time}, remote: {remote_iso_time})" writemsg_stdout("\n") writemsg_stdout( diff --git a/lib/portage/util/time.py b/lib/portage/util/time.py new file mode 100644 index 0000000000..92e83904da --- /dev/null +++ b/lib/portage/util/time.py @@ -0,0 +1,15 @@ +# Copyright 2025 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +import datetime + +__all__ = ["unix_to_iso_time"] + + +def unix_to_iso_time(unix_ts): + local_timezone = datetime.datetime.now().astimezone().tzinfo + dt = datetime.datetime.fromtimestamp( + int(unix_ts), + local_timezone, + ) + return dt.isoformat()
