http://www.antihttps.com/tc13_ff_time-zones.htmFix for wrong time in Firefox when hardware clock set to local time in Tiny Core Linux 13
2022-03-13
Websites using Javascript are able to access your system's current time through Firefox. Increasingly sites have started using this for log-in time-out durations, and when a wildly inaccurate current time is provided by Firefox, these sites won't let you log in at all (usually just immediately reloading the log-in page without showing any error message, in my experience).
If the hardware clock (RTC) is set to local time ("noutc" boot code), the default configuration of Tiny Core seems to prevent Firefox from determining the correct time-zone offset (though file time-stamps and other programs such as the date command will still show the correct time). The problem is that it reads the system clock as UTC time, and applies the local time-zone offset on top of that, so eg. Firefox makes a UTC+10 time-zone into UTC+20 because the offset gets added twice. Unfortunately my research failed to turn up any way to force Firefox to use the system's own time-zone calculations (like other software does) rather than doing them itself.
Firefox's current time value can be shown by selecting "Tools>Web Developer Tools" from the top menu in Firefox (or Ctrl+Shift+i), selecting the "Console" tab from the new pane at the bottom of the screen, then entering:
Date()
I've spent way too many hours today slowly narrowing down the right combination of settings to fix this problem, but here's what I eventually came up with:
load the tzdata extension:
tce-load -wil tzdata
Add /etc/localtime to /opt/.filetool.lst:
echo etc/localtime >> /opt/.filetool.lst
When the tzdata extension loaded, it made a symlink at /etc/localtime which should point to the zoneinfo file matching your time-zone, but it may have been wrong (check with "ls -l /etc/localtime"). If so, delete the symlink and make a new one to the correct time-zone for your location:
rm /etc/localtime
ln -s /usr/local/share/zoneinfo/[time-zone] /etc/localtime
echo tzdata.tcz >> /etc/sysconfig/tcedir/onboot.lst
Browse the /usr/local/share/zoneinfo/ directory to find the correct [time-zone] for your location, mine's "Australia/Victoria".
Or, rather than linking you can also just copy the zoneinfo file to /etc/localtime so that you don't have to add tzdata.tcz to /etc/sysconfig/tcedir/onboot.lst:
rm /etc/localtime
cp /usr/local/share/zoneinfo/[time-zone] /etc/localtime
Either way, the necessary files won't be loaded when the time is set during start-up (by the /etc/init.d/tc-config script), so you need to run the hwclock command again in bootlocal.sh:
echo 'hwclock -ls &' >> /opt/bootlocal.sh
If you backup ("filetool -b") and reboot now, the date command should return the correct local time and Firefox might show the correct time (with a UTC+[number] at the end without a time-zone name). However I found that Firefox's time wasn't adjusted for daylight savings (showing UTC+10 when it should have been UTC+11).
The solution for this is to set the TZ environment variable, in my case to "Australia/Victoria", after which Firefox applies the correct daylight savings time offset (and shows the full time-zone name "Australian Eastern Daylight Time"). But now the output of the date command is wrong, showing UTC time as local time.
My only solution to this is to keep the TZ environment variable unset normally, and always start Firefox like this:
TZ=Australia/Victoria firefox
So I've edited menu entries to use that. If you're using the .desktop file loaded with the firefox-esr or firefox_getLatest extension to add the menu item for Firefox, then it might be more complicated. You might want make a script to do the above and place it in a directory that's earlier in your PATH, eg. /usr/bin. Note that this will prevent the firefox extension from being loaded in ondemand mode though.
Overall my solution isn't elegant, but it works for me. Others are welcome to suggest improvements at the forum thread.
(
http://forum.tinycorelinux.net/index.php/topic,25641.0.html)
Firefox time-zone setting docs(
https://kb.mozillazine.org/Time_and_time_zone_settings)(outdated and don't help with this problem much).
[EDIT]: Re-arranged code tags. Rich