From a52657e6841878453124358bc2e142cde9ec68b9 Mon Sep 17 00:00:00 2001 From: kqjy Date: Fri, 16 Jan 2026 20:19:52 +0800 Subject: [PATCH] enhance date formats with timezone --- app/__init__.py | 24 ++++++++++++++++++++++++ templates/buckets.html | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index 87d71d2..c5f38a9 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -227,6 +227,30 @@ def create_app( except (ValueError, OSError): return "Unknown" + @app.template_filter("format_datetime") + def format_datetime_filter(dt, include_tz: bool = True) -> str: + """Format datetime object as human-readable string in configured timezone.""" + from datetime import datetime, timezone as dt_timezone + from zoneinfo import ZoneInfo + if not dt: + return "" + try: + display_tz = app.config.get("DISPLAY_TIMEZONE", "UTC") + if display_tz and display_tz != "UTC": + try: + tz = ZoneInfo(display_tz) + if dt.tzinfo is None: + dt = dt.replace(tzinfo=dt_timezone.utc) + dt = dt.astimezone(tz) + except (KeyError, ValueError): + pass + tz_abbr = dt.strftime("%Z") or "UTC" + if include_tz: + return f"{dt.strftime('%b %d, %Y %H:%M')} ({tz_abbr})" + return dt.strftime("%b %d, %Y %H:%M") + except (ValueError, AttributeError): + return str(dt) + if include_api: from .s3_api import s3_api_bp from .kms_api import kms_api_bp diff --git a/templates/buckets.html b/templates/buckets.html index 696272a..bf185c3 100644 --- a/templates/buckets.html +++ b/templates/buckets.html @@ -51,7 +51,7 @@
{{ bucket.meta.name }}
- Created {{ bucket.meta.created_at.strftime('%b %d, %Y %H:%M') }} ({{ bucket.meta.created_at.strftime('%Z') or 'UTC' }}) + Created {{ bucket.meta.created_at | format_datetime }}
{{ bucket.access_label }}