def filter_datetime(jinja_ctx, context, **kw): """Format datetime in a certain timezone.""" now = context if not now: return "" tz = kw.get("timezone", None) if tz: tz = timezone(tz) else: tz = datetime.timezone.utc locale = kw.get("locale", "en_US") arrow = Arrow.fromdatetime(now, tzinfo=tz) # Convert to target timezone tz = kw.get("target_timezone") if tz: arrow = arrow.to(tz) else: tz = arrow.tzinfo format = kw.get("format", "YYYY-MM-DD HH:mm") text = arrow.format(format, locale=locale) if kw.get("show_timezone"): text = text + " ({})".format(tz) return text
def format_dt_tz(now: t.Optional[date_type] = None, **kw): """Format datetime in a certain timezone.""" if not now: return "" tz = kw.get("timezone", None) if tz: tz = timezone(tz) else: tz = datetime.timezone.utc locale = kw.get("locale", "en_US") arrow = Arrow.fromdatetime(now, tzinfo=tz) # Convert to target timezone tz = kw.get("target_timezone") if tz: arrow = arrow.to(tz) else: tz = arrow.tzinfo format_ = kw.get("format", "YYYY-MM-DD HH:mm") text = arrow.format(format_, locale=locale) if kw.get("show_timezone"): text = text + " ({})".format(tz) return text
def hmsS(self, ar): return ar.format('hh:mm:ss.SSSSS')