luci-mod-status: use localized time

use localized time

Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
This commit is contained in:
Andy Chiang
2025-10-16 00:48:26 +07:00
committed by Paul Donald
parent edb481a1ac
commit e67465da5e
2 changed files with 24 additions and 13 deletions

View 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 = [

View 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" ]
}