WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Fix for wrong time in Firefox when hardware clock set to local time  (Read 6066 times)

Offline CNK

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 265
Getting past the forum's "500 error"s was proving impossible without deleting everything that mentioned a command or directory. So I've redone this post as a web page.

The opening paragraphs, which the forum software doesn't object to:

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:
Code: [Select]
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:

Offline gadget42

  • Hero Member
  • *****
  • Posts: 725
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #1 on: March 13, 2022, 05:49:20 AM »
http://www.antihttps.com/tc13_ff_time-zones.htm

Fix 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:

Code: [Select]
  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:

Code: [Select]
  tce-load -wil tzdata
Add /etc/localtime to /opt/.filetool.lst:

Code: [Select]
  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:

Code: [Select]
  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:

Code: [Select]
  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:

Code: [Select]
  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:

Code: [Select]
  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
« Last Edit: March 13, 2022, 09:52:00 AM by Rich »
The fluctuation theorem has long been known for a sudden switch of the Hamiltonian of a classical system Z54 . For a quantum system with a Hamiltonian changing from... https://forum.tinycorelinux.net/index.php/topic,25972.msg166580.html#msg166580

Offline CNK

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 265
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #2 on: March 13, 2022, 07:40:35 AM »
@gadget42
Thanks, though it's not really readable with those long unwrapped lines. Maybe if the text is run through fold first though - I'll keep that in mind.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11516
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #3 on: March 13, 2022, 09:53:10 AM »
Hi CNK
Is this better?  :)

Offline gadget42

  • Hero Member
  • *****
  • Posts: 725
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #4 on: March 13, 2022, 10:00:28 AM »
@Rich: thanks Rich!
The fluctuation theorem has long been known for a sudden switch of the Hamiltonian of a classical system Z54 . For a quantum system with a Hamiltonian changing from... https://forum.tinycorelinux.net/index.php/topic,25972.msg166580.html#msg166580

Offline CNK

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 265
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #5 on: March 13, 2022, 06:45:30 PM »
@Rich
Yes, minus some paragraph spacing that's exactly what I tried to post in the first place. For me the second code block set off the 500 errors, and most of the following ones did too (along with directory paths in the paragraph text). Maybe it's less buggy when editing/replying, or you have some special moderator powers over it? Or if there's some sort of escape-sequence for invalid characters then please share. But anyway, thanks!

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11516
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #6 on: March 13, 2022, 08:37:51 PM »
Hi CNK
... Maybe it's less buggy when editing/replying, ...
Nope.
Quote
... or you have some special moderator powers over it? ...
Absolutely not.
Quote
... Or if there's some sort of escape-sequence for invalid characters ...
Not that I'm aware of.

All I did was:
Remove the code tags gadget42 wrapped your text in, clicked preview, and saw no error.
Wrapped the first group of commands in code tags, clicked preview, and saw no error.
Wrapped the next group of commands in code tags, clicked preview, and saw no error.
 ...........
Wrapped the last group of commands in code tags, clicked preview, and saw no error.
I'm guessing the forum software was no longer offended by your post.  ;D

Or you can see my other explanation here:
http://forum.tinycorelinux.net/index.php/topic,25148.msg161629.html#msg161629

Offline CNK

  • Wiki Author
  • Sr. Member
  • *****
  • Posts: 265
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #7 on: March 14, 2022, 02:39:47 AM »
All I did was:
Remove the code tags gadget42 wrapped your text in, clicked preview, and saw no error.
Wrapped the first group of commands in code tags, clicked preview, and saw no error.
Wrapped the next group of commands in code tags, clicked preview, and saw no error.
 ...........
Wrapped the last group of commands in code tags, clicked preview, and saw no error.
I'm guessing the forum software was no longer offended by your post.  ;D

Or you can see my other explanation here:
http://forum.tinycorelinux.net/index.php/topic,25148.msg161629.html#msg161629

I just tried clicking the Quote link on gadget42's post, then Preview, and I get the 500 error from that. Also the same after removing the quote block.

Tested the original again, also still gives me the 500 error (either in a reply or a new topic).

So it seems other people can post what I wrote, but not me. Very strange.

Offline gadget42

  • Hero Member
  • *****
  • Posts: 725
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #8 on: March 14, 2022, 09:42:42 AM »
eventually the forum may well become unmanageable/unbearable/non-functional due to the inability to properly maintain it.

sharing is caring
The fluctuation theorem has long been known for a sudden switch of the Hamiltonian of a classical system Z54 . For a quantum system with a Hamiltonian changing from... https://forum.tinycorelinux.net/index.php/topic,25972.msg166580.html#msg166580

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11516
Re: Fix for wrong time in Firefox when hardware clock set to local time
« Reply #9 on: March 14, 2022, 10:06:20 AM »
Hi CNK
Like I said in the link to my other explanation:
Quote
It seems to be caused by certain words at certain times. There also seems to be a certain amount of randomness to
it, ...
One day it gives me grief when trying to post a command, another day it happily lets me post that same command.