tools (common/date_utils): new get_timezone_name to retrieve it from a tzinfo and a timestamp
This commit is contained in:
parent
63d62f66f0
commit
4a8635d4a2
1 changed files with 18 additions and 0 deletions
|
|
@ -247,3 +247,21 @@ def delta2human(start_ts: Union[float, int], end_ts: Union[float, int]) -> str:
|
|||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue