forked from iarv/meshcore-hub
Merge pull request #87 from ipnet-mesh/feat/timezones
Move timezone display to page headers instead of each timestamp
This commit is contained in:
@@ -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
|
||||
# -------------------
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
{% block content %}
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Advertisements</h1>
|
||||
<div class="flex items-center gap-2">
|
||||
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
|
||||
<span class="badge badge-lg">{{ total }} total</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if api_error %}
|
||||
<div class="alert alert-warning mb-6">
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Map</h1>
|
||||
<div class="flex items-center gap-2">
|
||||
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
|
||||
<span id="node-count" class="badge badge-lg">Loading...</span>
|
||||
<span id="filtered-count" class="badge badge-lg badge-ghost hidden"></span>
|
||||
</div>
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
{% block content %}
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Messages</h1>
|
||||
<div class="flex items-center gap-2">
|
||||
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
|
||||
<span class="badge badge-lg">{{ total }} total</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if api_error %}
|
||||
<div class="alert alert-warning mb-6">
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
{% block content %}
|
||||
<div class="flex items-center justify-between mb-6">
|
||||
<h1 class="text-3xl font-bold">Nodes</h1>
|
||||
<div class="flex items-center gap-2">
|
||||
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
|
||||
<span class="badge badge-lg">{{ total }} total</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if api_error %}
|
||||
<div class="alert alert-warning mb-6">
|
||||
|
||||
Reference in New Issue
Block a user