luci-proto-wireguard: Display times which account for the timezone also
authorPaul Donald <[email protected]>
Tue, 28 Oct 2025 19:36:09 +0000 (20:36 +0100)
committerPaul Donald <[email protected]>
Tue, 28 Oct 2025 19:50:51 +0000 (20:50 +0100)
Signed-off-by: Paul Donald <[email protected]>
protocols/luci-proto-wireguard/htdocs/luci-static/resources/view/wireguard/status.js

index ff6756f05116834d85b4c493bddb215eb68c59d8..d6a8742fa15f4fff67e6396cd82460eeedee5a1c 100644 (file)
@@ -3,6 +3,7 @@
 'require rpc';
 'require poll';
 'require dom';
+'require uci';
 'require ui';
 
 
@@ -27,7 +28,15 @@ function timestampToStr(timestamp) {
        else
                ago = _('over a day ago');
 
-       return (new Date(timestamp * 1000)).toUTCString() + ' (' + ago + ')';
+       const date = new Date(timestamp * 1000);
+       const sys = uci.get('system', '@system[0]');
+
+       return new Intl.DateTimeFormat(undefined, {
+               dateStyle: 'medium',
+               timeStyle: (!sys?.clock_timestyle) ? 'long' : 'full',
+               hourCycle: (!sys?.clock_hourcycle) ? undefined : sys.clock_hourcycle,
+               timeZone: sys?.zonename?.replaceAll(' ', '_') || 'UTC',
+       }).format(date) + ' (' + ago + ')';
 }
 
 function handleInterfaceDetails(iface) {
@@ -115,6 +124,12 @@ function renderPeerTable(instanceName, peers) {
 }
 
 return view.extend({
+       load() {
+               return Promise.all([
+                       uci.load('system'),
+               ])
+       },
+
        renderIfaces: function(ifaces) {
                var res = [
                        E('h2', [ _('WireGuard Status') ])