luci-mod-system: fix time display logic
Use the system/info ubus call to obtain a TZ adjusted epoch value and
format the date time string manually instead of relying on the browsers
local representation.
Fixes: #5454
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
(cherry picked from commit 07569c5af2
)
This commit is contained in:
parent
790bb936f2
commit
68815c88b0
2 changed files with 20 additions and 6 deletions
|
@ -29,9 +29,9 @@ callInitAction = rpc.declare({
|
||||||
});
|
});
|
||||||
|
|
||||||
callGetLocaltime = rpc.declare({
|
callGetLocaltime = rpc.declare({
|
||||||
object: 'luci',
|
object: 'system',
|
||||||
method: 'getLocaltime',
|
method: 'info',
|
||||||
expect: { result: 0 }
|
expect: { localtime: 0 }
|
||||||
});
|
});
|
||||||
|
|
||||||
callSetLocaltime = rpc.declare({
|
callSetLocaltime = rpc.declare({
|
||||||
|
@ -47,6 +47,19 @@ callTimezone = rpc.declare({
|
||||||
expect: { '': {} }
|
expect: { '': {} }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function formatTime(epoch) {
|
||||||
|
var date = new Date(epoch * 1000);
|
||||||
|
|
||||||
|
return '%04d-%02d-%02d %02d:%02d:%02d'.format(
|
||||||
|
date.getUTCFullYear(),
|
||||||
|
date.getUTCMonth() + 1,
|
||||||
|
date.getUTCDate(),
|
||||||
|
date.getUTCHours(),
|
||||||
|
date.getUTCMinutes(),
|
||||||
|
date.getUTCSeconds()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
CBILocalTime = form.DummyValue.extend({
|
CBILocalTime = form.DummyValue.extend({
|
||||||
renderWidget: function(section_id, option_id, cfgvalue) {
|
renderWidget: function(section_id, option_id, cfgvalue) {
|
||||||
return E([], [
|
return E([], [
|
||||||
|
@ -54,7 +67,7 @@ CBILocalTime = form.DummyValue.extend({
|
||||||
'id': 'localtime',
|
'id': 'localtime',
|
||||||
'type': 'text',
|
'type': 'text',
|
||||||
'readonly': true,
|
'readonly': true,
|
||||||
'value': new Date(cfgvalue * 1000).toLocaleString()
|
'value': formatTime(cfgvalue)
|
||||||
}),
|
}),
|
||||||
E('br'),
|
E('br'),
|
||||||
E('span', { 'class': 'control-group' }, [
|
E('span', { 'class': 'control-group' }, [
|
||||||
|
@ -285,7 +298,7 @@ return view.extend({
|
||||||
return m.render().then(function(mapEl) {
|
return m.render().then(function(mapEl) {
|
||||||
poll.add(function() {
|
poll.add(function() {
|
||||||
return callGetLocaltime().then(function(t) {
|
return callGetLocaltime().then(function(t) {
|
||||||
mapEl.querySelector('#localtime').value = new Date(t * 1000).toLocaleString();
|
mapEl.querySelector('#localtime').value = formatTime(t);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
"description": "Grant access to system configuration",
|
"description": "Grant access to system configuration",
|
||||||
"read": {
|
"read": {
|
||||||
"ubus": {
|
"ubus": {
|
||||||
"luci": [ "getInitList", "getLEDs", "getLocaltime", "getTimezones", "getUSBDevices" ]
|
"luci": [ "getInitList", "getLEDs", "getTimezones", "getUSBDevices" ],
|
||||||
|
"system": [ "info" ]
|
||||||
},
|
},
|
||||||
"uci": [ "luci", "system" ]
|
"uci": [ "luci", "system" ]
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue