Skip to content

Commit caf88bd

Browse files
Merge pull request #87 from ipnet-mesh/feat/timezones
Move timezone display to page headers instead of each timestamp
2 parents 981402f + 9eb1acf commit caf88bd

File tree

6 files changed

+30
-8
lines changed

6 files changed

+30
-8
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ API_ADMIN_KEY=
187187
# External web port
188188
WEB_PORT=8080
189189

190+
# Timezone for displaying dates/times on the web dashboard
191+
# Uses standard IANA timezone names (e.g., America/New_York, Europe/London)
192+
# Default: UTC
193+
TZ=UTC
194+
190195
# -------------------
191196
# Network Information
192197
# -------------------

src/meshcore_hub/web/app.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _create_timezone_filters(tz_name: str) -> dict:
4444

4545
def format_datetime(
4646
value: str | datetime | None,
47-
fmt: str = "%Y-%m-%d %H:%M:%S %Z",
47+
fmt: str = "%Y-%m-%d %H:%M:%S",
4848
) -> str:
4949
"""Format a UTC datetime string or object to the configured timezone.
5050
@@ -79,7 +79,7 @@ def format_datetime(
7979
# Fallback to original value if parsing fails
8080
return str(value)[:19].replace("T", " ") if value else "-"
8181

82-
def format_time(value: str | datetime | None, fmt: str = "%H:%M:%S %Z") -> str:
82+
def format_time(value: str | datetime | None, fmt: str = "%H:%M:%S") -> str:
8383
"""Format just the time portion in the configured timezone."""
8484
return format_datetime(value, fmt)
8585

@@ -89,10 +89,10 @@ def format_date(value: str | datetime | None, fmt: str = "%Y-%m-%d") -> str:
8989

9090
return {
9191
"localtime": format_datetime,
92-
"localtime_short": lambda v: format_datetime(v, "%Y-%m-%d %H:%M %Z"),
92+
"localtime_short": lambda v: format_datetime(v, "%Y-%m-%d %H:%M"),
9393
"localdate": format_date,
9494
"localtimeonly": format_time,
95-
"localtimeonly_short": lambda v: format_time(v, "%H:%M %Z"),
95+
"localtimeonly_short": lambda v: format_time(v, "%H:%M"),
9696
}
9797

9898

@@ -215,6 +215,13 @@ def create_app(
215215
for name, func in tz_filters.items():
216216
templates.env.filters[name] = func
217217

218+
# Compute timezone abbreviation (e.g., "GMT", "EST", "PST")
219+
try:
220+
tz = ZoneInfo(settings.tz)
221+
app.state.timezone_abbr = datetime.now(tz).strftime("%Z")
222+
except Exception:
223+
app.state.timezone_abbr = "UTC"
224+
218225
app.state.templates = templates
219226

220227
# Initialize page loader for custom markdown pages
@@ -398,5 +405,5 @@ def get_network_context(request: Request) -> dict:
398405
"custom_pages": custom_pages,
399406
"logo_url": request.app.state.logo_url,
400407
"version": __version__,
401-
"timezone": request.app.state.timezone,
408+
"timezone": request.app.state.timezone_abbr,
402409
}

src/meshcore_hub/web/templates/advertisements.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
{% block content %}
88
<div class="flex items-center justify-between mb-6">
99
<h1 class="text-3xl font-bold">Advertisements</h1>
10-
<span class="badge badge-lg">{{ total }} total</span>
10+
<div class="flex items-center gap-2">
11+
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
12+
<span class="badge badge-lg">{{ total }} total</span>
13+
</div>
1114
</div>
1215

1316
{% if api_error %}

src/meshcore_hub/web/templates/map.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<div class="flex items-center justify-between mb-6">
77
<h1 class="text-3xl font-bold">Map</h1>
88
<div class="flex items-center gap-2">
9+
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
910
<span id="node-count" class="badge badge-lg">Loading...</span>
1011
<span id="filtered-count" class="badge badge-lg badge-ghost hidden"></span>
1112
</div>

src/meshcore_hub/web/templates/messages.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
{% block content %}
88
<div class="flex items-center justify-between mb-6">
99
<h1 class="text-3xl font-bold">Messages</h1>
10-
<span class="badge badge-lg">{{ total }} total</span>
10+
<div class="flex items-center gap-2">
11+
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
12+
<span class="badge badge-lg">{{ total }} total</span>
13+
</div>
1114
</div>
1215

1316
{% if api_error %}

src/meshcore_hub/web/templates/nodes.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
{% block content %}
88
<div class="flex items-center justify-between mb-6">
99
<h1 class="text-3xl font-bold">Nodes</h1>
10-
<span class="badge badge-lg">{{ total }} total</span>
10+
<div class="flex items-center gap-2">
11+
{% if timezone and timezone != 'UTC' %}<span class="text-sm opacity-60">{{ timezone }}</span>{% endif %}
12+
<span class="badge badge-lg">{{ total }} total</span>
13+
</div>
1114
</div>
1215

1316
{% if api_error %}

0 commit comments

Comments
 (0)