'require tools.widgets as widgets';
var callRcList, callRcInit, callTimezone,
- callGetLocaltime, callSetLocaltime, CBILocalTime;
+ callGetUnixtime, callSetLocaltime, CBILocalTime;
callRcList = rpc.declare({
object: 'rc',
expect: { result: false }
});
-callGetLocaltime = rpc.declare({
- object: 'system',
- method: 'info',
- expect: { localtime: 0 }
+callGetUnixtime = rpc.declare({
+ object: 'luci',
+ method: 'getUnixtime',
+ expect: { result: 0 }
});
callSetLocaltime = rpc.declare({
});
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()
- );
+ var date = new Date(epoch * 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');
+
+ return new Intl.DateTimeFormat(undefined, {
+ dateStyle: 'medium',
+ timeStyle: (ts == 0) ? 'long' : 'full',
+ hourCycle: hc,
+ timeZone: zn
+ }).format(date);
}
CBILocalTime = form.DummyValue.extend({
return Promise.all([
callRcList('sysntpd'),
callTimezone(),
- callGetLocaltime(),
+ callGetUnixtime(),
uci.load('luci'),
uci.load('system')
]);
render: function(rpc_replies) {
var ntpd_enabled = rpc_replies[0],
timezones = rpc_replies[1],
- localtime = rpc_replies[2],
+ unixtime = rpc_replies[2],
m, s, o;
m = new form.Map('system',
*/
o = s.taboption('general', CBILocalTime, '_systime', _('Local Time'));
- o.cfgvalue = function() { return localtime };
+ o.cfgvalue = function() { return unixtime };
o.ntpd_support = ntpd_enabled;
o = s.taboption('general', form.Value, 'hostname', _('Hostname'));
uci.set('system', section_id, 'timezone', tz);
};
+ o = s.taboption('general', form.Flag, 'clock_timestyle', _('Full TimeZone Name'), _('Unchecked means the timezone offset (E.g. GMT+1) is displayed'));
+ o.default = o.enabled;
+
+ o = s.taboption('general', form.ListValue, 'clock_hourcycle', _('Time Format'));
+ o.value('', _('Default'));
+ o.value('h12', _('12-Hour Clock'));
+ o.value('h23', _('24-Hour Clock'));
+
/*
* Logging
*/
return m.render().then(function(mapEl) {
poll.add(function() {
- return callGetLocaltime().then(function(t) {
+ return callGetUnixtime().then(function(t) {
mapEl.querySelector('#localtime').value = formatTime(t);
});
});