luci-mod-system: fix time display logic
authorJo-Philipp Wich <jo@mein.io>
Tue, 19 Oct 2021 21:08:36 +0000 (23:08 +0200)
committerJo-Philipp Wich <jo@mein.io>
Tue, 19 Oct 2021 21:09:46 +0000 (23:09 +0200)
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>
modules/luci-mod-system/htdocs/luci-static/resources/view/system/system.js
modules/luci-mod-system/root/usr/share/rpcd/acl.d/luci-mod-system.json

index 1c2aa46c5201e9844ad219aee1b501650c27c8d6..d207a5c9944c91e4d98b6b1aaef01b1a40b4b9c3 100644 (file)
@@ -29,9 +29,9 @@ callInitAction = rpc.declare({
 });
 
 callGetLocaltime = rpc.declare({
-       object: 'luci',
-       method: 'getLocaltime',
-       expect: { result: 0 }
+       object: 'system',
+       method: 'info',
+       expect: { localtime: 0 }
 });
 
 callSetLocaltime = rpc.declare({
@@ -47,6 +47,19 @@ callTimezone = rpc.declare({
        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({
        renderWidget: function(section_id, option_id, cfgvalue) {
                return E([], [
@@ -54,7 +67,7 @@ CBILocalTime = form.DummyValue.extend({
                                'id': 'localtime',
                                'type': 'text',
                                'readonly': true,
-                               'value': new Date(cfgvalue * 1000).toLocaleString()
+                               'value': formatTime(cfgvalue)
                        }),
                        E('br'),
                        E('span', { 'class': 'control-group' }, [
@@ -285,7 +298,7 @@ return view.extend({
                return m.render().then(function(mapEl) {
                        poll.add(function() {
                                return callGetLocaltime().then(function(t) {
-                                       mapEl.querySelector('#localtime').value = new Date(t * 1000).toLocaleString();
+                                       mapEl.querySelector('#localtime').value = formatTime(t);
                                });
                        });
 
index 9acb6e4471b0ebb071d22b6546a8bf8cacaa56b1..732a73a760c6db97e263d59a931982464cd5f4e6 100644 (file)
@@ -3,7 +3,8 @@
                "description": "Grant access to system configuration",
                "read": {
                        "ubus": {
-                               "luci": [ "getInitList", "getLEDs", "getLocaltime", "getTimezones", "getUSBDevices" ]
+                               "luci": [ "getInitList", "getLEDs", "getTimezones", "getUSBDevices" ],
+                               "system": [ "info" ]
                        },
                        "uci": [ "luci", "system" ]
                },