luci-mod-dashboard: 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:55 +07:00
committed by Paul Donald
parent b0004ad39c
commit 71ea35fc7f
2 changed files with 23 additions and 11 deletions

View File

@@ -3,6 +3,7 @@
'require fs';
'require rpc';
'require network';
'require uci';
var callSystemBoard = rpc.declare({
object: 'system',
@@ -14,6 +15,12 @@ var callSystemInfo = rpc.declare({
method: 'info'
});
var callGetUnixtime = rpc.declare({
object: 'luci',
method: 'getUnixtime',
expect: { result: 0 }
});
return baseclass.extend({
params: [],
@@ -23,7 +30,9 @@ return baseclass.extend({
network.getWANNetworks(),
network.getWAN6Networks(),
L.resolveDefault(callSystemBoard(), {}),
L.resolveDefault(callSystemInfo(), {})
L.resolveDefault(callSystemInfo(), {}),
L.resolveDefault(callGetUnixtime(), 0),
uci.load('system')
]);
},
@@ -298,20 +307,22 @@ return baseclass.extend({
const boardinfo = data[2];
const systeminfo = data[3];
const unixtime = data[4];
let datestr = null;
if (systeminfo.localtime) {
const date = new Date(systeminfo.localtime * 1000);
if (unixtime) {
const date = new Date(unixtime * 1000);
const zn = uci.get('system', '@system[0]', 'zonename')?.replaceAll(' ', '_') || 'UTC';
const ts = uci.get('system', '@system[0]', 'clock_timestyle');
const 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);
}
this.params.router = {

View File

@@ -16,6 +16,7 @@
},
"ubus": {
"file": [ "list", "read" ],
"luci": [ "getUnixtime" ],
"system": [ "board", "info" ]
}
}