luci-mod-status: use localized time
authorAndy Chiang <[email protected]>
Wed, 15 Oct 2025 17:48:26 +0000 (00:48 +0700)
committerPaul Donald <[email protected]>
Mon, 20 Oct 2025 18:40:46 +0000 (20:40 +0200)
use localized time

Signed-off-by: Andy Chiang <[email protected]>
modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js
modules/luci-mod-status/root/usr/share/rpcd/acl.d/luci-mod-status-index.json

index 45f7b4acae6d4593ad077adf33685e101796f1b4..4c7876d5b9217c529117f7d9ba89dd9500e39630 100644 (file)
@@ -2,6 +2,13 @@
 'require baseclass';
 'require fs';
 'require rpc';
+'require uci';
+
+var callGetUnixtime = rpc.declare({
+       object: 'luci',
+       method: 'getUnixtime',
+       expect: { result: 0 }
+});
 
 var callLuciVersion = rpc.declare({
        object: 'luci',
@@ -25,30 +32,34 @@ return baseclass.extend({
                return Promise.all([
                        L.resolveDefault(callSystemBoard(), {}),
                        L.resolveDefault(callSystemInfo(), {}),
-                       L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' })
+                       L.resolveDefault(callLuciVersion(), { revision: _('unknown version'), branch: 'LuCI' }),
+                       L.resolveDefault(callGetUnixtime(), 0),
+                       uci.load('system')
                ]);
        },
 
        render: function(data) {
                var boardinfo   = data[0],
                    systeminfo  = data[1],
-                   luciversion = data[2];
+                   luciversion = data[2],
+                   unixtime    = data[3];
 
                luciversion = luciversion.branch + ' ' + luciversion.revision;
 
                var datestr = null;
 
-               if (systeminfo.localtime) {
-                       var date = new Date(systeminfo.localtime * 1000);
+               if (unixtime) {
+                       var date = new Date(unixtime * 1000),
+                               zn = uci.get('system', '@system[0]', 'zonename')?.replaceAll(' ', '_') || 'UTC',
+                               ts = uci.get('system', '@system[0]', 'clock_timestyle'),
+                               hc = uci.get('system', '@system[0]', 'clock_hourcycle');
 
-                       datestr = '%04d-%02d-%02d %02d:%02d:%02d'.format(
-                               date.getUTCFullYear(),
-                               date.getUTCMonth() + 1,
-                               date.getUTCDate(),
-                               date.getUTCHours(),
-                               date.getUTCMinutes(),
-                               date.getUTCSeconds()
-                       );
+                       datestr = new Intl.DateTimeFormat(undefined, {
+                               dateStyle: 'medium',
+                               timeStyle: (ts == 0) ? 'long' : 'full',
+                               hourCycle: hc,
+                               timeZone: zn
+                       }).format(date);
                }
 
                var fields = [
index c9e3c836cb9e1c0470f150ae7b062c6389f31029..f2253f39c0ec2cf725d06349b4c7cd386d9add26 100644 (file)
@@ -9,7 +9,7 @@
                                "/www/luci-static/resources/view/status/include": [ "list" ]
                        },
                        "ubus": {
-                               "luci": [ "getVersion" ],
+                               "luci": [ "getVersion", "getUnixtime" ],
                                "file": [ "list", "read" ],
                                "system": [ "board", "info" ]
                        }