Mercurial > libervia-backend
comparison sat/tools/common/date_utils.py @ 4029:432f7e422a27
tools (common/date_utils): new `get_timezone_name` to retrieve it from a tzinfo and a timestamp
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 30 Mar 2023 16:52:18 +0200 |
parents | 883db2790b11 |
children |
comparison
equal
deleted
inserted
replaced
4028:883db2790b11 | 4029:432f7e422a27 |
---|---|
245 text_elems.append(f"1 {unit[:-1]}") | 245 text_elems.append(f"1 {unit[:-1]}") |
246 elif value > 1: | 246 elif value > 1: |
247 text_elems.append(f"{value} {unit}") | 247 text_elems.append(f"{value} {unit}") |
248 | 248 |
249 return ", ".join(text_elems) | 249 return ", ".join(text_elems) |
250 | |
251 | |
252 def get_timezone_name(tzinfo, timestamp: Union[float, int]) -> str: | |
253 """ | |
254 Get the DST-aware timezone name for a given timezone and timestamp. | |
255 | |
256 @param tzinfo: The timezone to get the name for | |
257 @param timestamp: The timestamp to use, as a Unix timestamp (number of seconds since | |
258 the Unix epoch). | |
259 @return: The DST-aware timezone name. | |
260 """ | |
261 | |
262 dt = datetime.datetime.fromtimestamp(timestamp) | |
263 dt_tz = dt.replace(tzinfo=tzinfo) | |
264 tz_name = dt_tz.tzname() | |
265 if tz_name is None: | |
266 raise exceptions.InternalError("tz_name should not be None") | |
267 return tz_name |