tools (common/template): let specify timezone name in date_fmt filter

This commit is contained in:
Goffi 2023-03-30 16:53:41 +02:00
commit 92f669ca8b

View file

@ -761,14 +761,23 @@ class Renderer(object):
current = ctx["gidx"].current(value)
return value if not current else "{}_{}".format(value, current)
def _date_fmt(self, timestamp, fmt="short", date_only=False, auto_limit=7,
auto_old_fmt="short", auto_new_fmt="relative"):
def _date_fmt(
self,
timestamp: Union[int, float],
fmt: str = "short",
date_only: bool = False,
auto_limit: int = 7,
auto_old_fmt: str = "short",
auto_new_fmt: str = "relative",
tz_name: Optional[str] = None
) -> str:
if is_undefined(fmt):
fmt = "short"
try:
return date_utils.date_fmt(
timestamp, fmt, date_only, auto_limit, auto_old_fmt,
locale_str = self._locale_str
auto_new_fmt, locale_str = self._locale_str,
tz_info=tz_name or date_utils.TZ_UTC
)
except Exception as e:
log.warning(_("Can't parse date: {msg}").format(msg=e))