Mercurial > libervia-backend
comparison sat/tools/common/template.py @ 4030:73936abc6838
tools (common/template): let specify timezone name in `date_fmt` filter
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 30 Mar 2023 16:53:41 +0200 |
parents | dd1d1a582438 |
children | a2d4bd1943ba |
comparison
equal
deleted
inserted
replaced
4029:432f7e422a27 | 4030:73936abc6838 |
---|---|
759 def _cur_gidx(self, ctx, value): | 759 def _cur_gidx(self, ctx, value): |
760 """Use current current global index as suffix""" | 760 """Use current current global index as suffix""" |
761 current = ctx["gidx"].current(value) | 761 current = ctx["gidx"].current(value) |
762 return value if not current else "{}_{}".format(value, current) | 762 return value if not current else "{}_{}".format(value, current) |
763 | 763 |
764 def _date_fmt(self, timestamp, fmt="short", date_only=False, auto_limit=7, | 764 def _date_fmt( |
765 auto_old_fmt="short", auto_new_fmt="relative"): | 765 self, |
766 timestamp: Union[int, float], | |
767 fmt: str = "short", | |
768 date_only: bool = False, | |
769 auto_limit: int = 7, | |
770 auto_old_fmt: str = "short", | |
771 auto_new_fmt: str = "relative", | |
772 tz_name: Optional[str] = None | |
773 ) -> str: | |
766 if is_undefined(fmt): | 774 if is_undefined(fmt): |
767 fmt = "short" | 775 fmt = "short" |
768 try: | 776 try: |
769 return date_utils.date_fmt( | 777 return date_utils.date_fmt( |
770 timestamp, fmt, date_only, auto_limit, auto_old_fmt, | 778 timestamp, fmt, date_only, auto_limit, auto_old_fmt, |
771 locale_str = self._locale_str | 779 auto_new_fmt, locale_str = self._locale_str, |
780 tz_info=tz_name or date_utils.TZ_UTC | |
772 ) | 781 ) |
773 except Exception as e: | 782 except Exception as e: |
774 log.warning(_("Can't parse date: {msg}").format(msg=e)) | 783 log.warning(_("Can't parse date: {msg}").format(msg=e)) |
775 return timestamp | 784 return timestamp |
776 | 785 |