luci-mod-status: use localized time#8014
Conversation
|
If we continue to use systeminfo.localtime, we can only set the timeZone to UTC like this: Which will not display the correct zonename. If we want display the correct zonename on the homepage, we need unixtime. On this basis, if we do not want the timezone change follow browser timezone, we can set timeZone like this: zonename can be written to /tmp/ZA via /etc/init.d/system at startup like /tmp/TZ,and get it via rpc. Should we continue to wait for unixtime or use localtime first? Any thoughts from @systemcrash @hnyman ? |
|
The user timezone is set in the system settings, so it's accessible. Yours: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString |
0b18817 to
d1ffc40
Compare
|
Well, let us use Intl.DateTimeFormat, but we no unixtime now, so we can only use localtime with UTC first. Remove timeZone and use the system's timezone so that the correct zonename can be displayed like this: |
If timeZone is not specified, the system settings are used, which is fine for most people. However, if someone's system and the router are in different timezone, do we need to specify timeZone as the zonename value from /etc/config/system in the js file so that the router can output a fixed timezone instead of the system settings? All this has to wait until unixtime is available. |
|
@systemcrash |
|
See 5443299. Now: callGetUnixtime = rpc.declare({
object: 'luci',
method: 'getUnixtime',
expect: { result: 0 }
}); |
|
Great, then I can use unixtime and add timezone display. I will push it again later. |
47464b0 to
d5f4bfa
Compare
|
Now I think you need to provide it with the TZ set in system.system so that the Local Time displayed on the unit is actually the local time on the unit, using its timezone, and not the timezone set on the user's (web browser's) system. |
|
Please be careful with the timezone related things. It's handling in OpenWrt is complex enough due to minimal approach, where most routers do not have "normal" large zoneinfo packages installed, and instead LuCI contains a POSIX string based list of current time zones. But some people do have zoneinfo installed. And there may be differences in musl / glibc handling of timezones. |
add zonename for localized time Link: openwrt/luci#8014 Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
|
luci part is complete, now we need use /tmp/ZN to fixed timezone. |
base-files: add zonename for localized time Link: openwrt/luci#8014 Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
add zonename for localized time Link: openwrt/luci#8014 Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
|
Why not just use something simpler like |
|
so /tmp/ZN is necessary |
That's what uci.get does. I don't follow. Your second picture which show RangeError uses a TZ which is identical informat to what I have in my |
I tried to get the zonename via uci.get in js, but there is a drawback. If zonename changes, the value obtained by uci.load and uci.get will not change. We need to manually refresh the web page. And when manually refresh the web page, uci.load will still access from flash. The existing solution will write the new zonename to /tmp/ZN through /etc/init.d/system if the zonename is updated. Each Polling will automatically get the latest value. This also avoids the need to access the flash every time we open a web page due to uci.load and uci.get. Therefore, whether from the perspective of polling or reducing flash access, writing zonename to /tmp/ZN through /etc/init.d/system is the best solution. |
|
Maybe, but configured timezones rarely change, so that's unnecessary. And it's only used in the browser display, so I don't see the point. |
|
Well, I'll use uci.get instead. It is true that timezone rarely change. |
92dc501 to
7e52d47
Compare
|
I have added the option to customize the time format. Shown as: |
80813c1 to
dd46fbf
Compare
|
Use h12 and h24 - using h11 you can see weird things like 00pm/am. |
|
Found another bug. You must process the timeZone zonename and replace all spaces for 'Africa/Dar es Salaam': 'EAT-3',
...
'Africa/El Aaiun': 'XXX-2<+01>-1,0/0,J365/23',
...
'Africa/Sao Tome': 'GMT0',
...etc fixed in d9a087e |
We should use h12, but not h24, otherwise it will be like this: |
dd46fbf to
6faa381
Compare
I thought of a situation where if someone's current zonename happens to contain spaces, it will crash after the upgrade. Should this problem be handled at the js level? . . . |
|
ofc |
The timezones are supposed to have underscore. The system page could replace the underscore in the displayed entries, but that's just an aesthetic. That's for later. |
6faa381 to
7b566e0
Compare
7b566e0 to
433b0dd
Compare
|
GUI aesthetics are also handled... |
633891b to
d82f8be
Compare
d82f8be to
305ec36
Compare
|
Looks good now. Please squash your commits to one per file. |
use localized time Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
use localized time Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
use localized time Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
set an appropriate width for #localtime Signed-off-by: Andy Chiang <AndyChiang_git@outlook.com>
305ec36 to
ba98cae
Compare
|
Now there are 4 commits. |
|
Excellent work. Thanks @AndyChiang888 |



Use localized time for luci-mod-status luci-mod-system and luci-mod-dashboard.
This will allow display appropriate time format for each region/language.
Signed-off-by: <my@email.address>row (viagit commit --signoff)<package name>: titlefirst line subject for packagesPKG_VERSIONin the Makefile