# HG changeset patch # User Goffi # Date 1680187938 -7200 # Node ID 432f7e422a270c93452daa3ca9143b3f92f37dbb # Parent 883db2790b11f4b4d47800cfe11e33f718186b0e tools (common/date_utils): new `get_timezone_name` to retrieve it from a tzinfo and a timestamp diff -r 883db2790b11 -r 432f7e422a27 sat/tools/common/date_utils.py --- a/sat/tools/common/date_utils.py Thu Mar 30 16:51:09 2023 +0200 +++ b/sat/tools/common/date_utils.py Thu Mar 30 16:52:18 2023 +0200 @@ -247,3 +247,21 @@ text_elems.append(f"{value} {unit}") return ", ".join(text_elems) + + +def get_timezone_name(tzinfo, timestamp: Union[float, int]) -> str: + """ + Get the DST-aware timezone name for a given timezone and timestamp. + + @param tzinfo: The timezone to get the name for + @param timestamp: The timestamp to use, as a Unix timestamp (number of seconds since + the Unix epoch). + @return: The DST-aware timezone name. + """ + + dt = datetime.datetime.fromtimestamp(timestamp) + dt_tz = dt.replace(tzinfo=tzinfo) + tz_name = dt_tz.tzname() + if tz_name is None: + raise exceptions.InternalError("tz_name should not be None") + return tz_name