diff --git a/.env.example b/.env.example index 94d30b2..5370d3a 100644 --- a/.env.example +++ b/.env.example @@ -187,6 +187,11 @@ API_ADMIN_KEY= # External web port WEB_PORT=8080 +# Timezone for displaying dates/times on the web dashboard +# Uses standard IANA timezone names (e.g., America/New_York, Europe/London) +# Default: UTC +TZ=UTC + # ------------------- # Network Information # ------------------- diff --git a/src/meshcore_hub/web/app.py b/src/meshcore_hub/web/app.py index 669c6a6..f924ffd 100644 --- a/src/meshcore_hub/web/app.py +++ b/src/meshcore_hub/web/app.py @@ -44,7 +44,7 @@ def _create_timezone_filters(tz_name: str) -> dict: def format_datetime( value: str | datetime | None, - fmt: str = "%Y-%m-%d %H:%M:%S %Z", + fmt: str = "%Y-%m-%d %H:%M:%S", ) -> str: """Format a UTC datetime string or object to the configured timezone. @@ -79,7 +79,7 @@ def _create_timezone_filters(tz_name: str) -> dict: # Fallback to original value if parsing fails return str(value)[:19].replace("T", " ") if value else "-" - def format_time(value: str | datetime | None, fmt: str = "%H:%M:%S %Z") -> str: + def format_time(value: str | datetime | None, fmt: str = "%H:%M:%S") -> str: """Format just the time portion in the configured timezone.""" return format_datetime(value, fmt) @@ -89,10 +89,10 @@ def _create_timezone_filters(tz_name: str) -> dict: return { "localtime": format_datetime, - "localtime_short": lambda v: format_datetime(v, "%Y-%m-%d %H:%M %Z"), + "localtime_short": lambda v: format_datetime(v, "%Y-%m-%d %H:%M"), "localdate": format_date, "localtimeonly": format_time, - "localtimeonly_short": lambda v: format_time(v, "%H:%M %Z"), + "localtimeonly_short": lambda v: format_time(v, "%H:%M"), } @@ -215,6 +215,13 @@ def create_app( for name, func in tz_filters.items(): templates.env.filters[name] = func + # Compute timezone abbreviation (e.g., "GMT", "EST", "PST") + try: + tz = ZoneInfo(settings.tz) + app.state.timezone_abbr = datetime.now(tz).strftime("%Z") + except Exception: + app.state.timezone_abbr = "UTC" + app.state.templates = templates # Initialize page loader for custom markdown pages @@ -398,5 +405,5 @@ def get_network_context(request: Request) -> dict: "custom_pages": custom_pages, "logo_url": request.app.state.logo_url, "version": __version__, - "timezone": request.app.state.timezone, + "timezone": request.app.state.timezone_abbr, } diff --git a/src/meshcore_hub/web/templates/advertisements.html b/src/meshcore_hub/web/templates/advertisements.html index 72bd04d..4e6737d 100644 --- a/src/meshcore_hub/web/templates/advertisements.html +++ b/src/meshcore_hub/web/templates/advertisements.html @@ -7,7 +7,10 @@ {% block content %}