David Gibson's Speaking Clock*

* My Speaking Clock doesnt actually speak - you have to do the talking yourself. Would it be easier, in a radio broadcast studio, for presenters to read the time from a display like this, than from a conventional clock? Unlike the clock on the BBC's web site (see news item here) my clock is accurate!.



ERROR: Unable to draw analogue clock face. Why?

 

    

If this text appears for more than a fleeting moment then something may have gone wrong, e.g.

  • The web server is slow responding
  • You do not have JavaScript enabled
  • You are running an old version of JavaScript
  • There is a programming error - my fault
  • Your computer is still 'thinking about it'

This Clock is Accurate

This web page will attempt to obtain an accurate time setting from the web server. If this message alters, it has been successful. Your computer's local clock may well be wrong.

Correcting Your Computer's Internal Clock

You can correct the time on your computer by running an application that synchronises your machine to a time server. In Windows XP and later versions, this is built-in facility.

  • Select the Internet Time tab from the Date and Time Properties dialogue and select a time server. (Your ISP may be able to provide you with the name of their time server, or ask Google for a list).
  • You might find that your PC clock drifts significantly, and that contacting the time server weekly (which is the XP default) is not sufficient. Your email application might contact the time server every time it boots up - provided you have configured it to do so.
  • To contact the time server more frequently you can alter a registry value. In Windows XP you need to navigate to HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \ Services \ W32Time \ TimeProviders \ NtpClient. Then open SpecialPollInterval, select 'decimal' under Base and enter the value you require in seconds. Two hours would be 7200; daily 86400 and weekly 604800.
  • Update 26 March 2015: You may need to separately tell the registry to use the above parameter. In Windows XP navigate to HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ DateTime \ Servers. Then open the key for the server you wish to use, and add 0x1 as a second parameter, e.g. time.windows.com,0x1. This tells your machine to use SpecialPollInterval with that time server.
  • Update 26 March 2015: You can check that this is working by opening Date and Time in the Control Panel and checking when the Internet time was last updated; and when Windows is intending to make the next connection.
  • Update 26 March 2015: Warning: if you have other software that accesses a time server, you might find that it is no longer able to do so, with the 0x1 setting applied. If this is the case, simply configure your other software to use a different time server - i.e. one without the second parameter set.

How my Speaking Clock Works

14 June 2013: Why does the BBC state that "technical complexities" are preventing their web site clock from working? - see here. It cannot possibly take 100 man-days of programming for them to do what Ive just (more-or-less) done in (more-or-less) an afternoon!

  • A simple JavaScript routine takes care of the 'speaking clock'. It takes a Date object; extracts the hours, minutes and seconds and converts them to a notation that includes a 'half-minute' count, and which allows the minutes and seconds to be negative; like this...

     --> 

     Debugging information
  • The web page is updated dynamically with the new time string by manipulating the Document Object Method properties.
  • Your local computer clock may be in error so, when the page loads, it uses Ajax to request an accurate time from the web server, which runs a small PHP routine to supply a text string to your computer. (Follow this link to contact the server now, and view the string that it returns).
  • This string used to modify the JavaScript date object. (This does not correct your computer's time; it merely compensates for the error).
  • Finally, HTML5 Canvas is used to draw an analogue clock face, which is re-drawn in real time, to show the moving hands. Notice the deliberate 'wobble' on the second hand.

Refinements

Using Canvas is the weak point, because not all versions of Internet Explorer support this function - you need at least version 9. However, Firefox, Opera, Chrome, and Safari all support the canvas element.

There are other refinements possible, but the last 10% of the work always takes 90% of the time so I'll leave these for now. One problem is how often to correct the drift? At the moment, the clock refreshes its time every few minutes, which seems a good compromise (for a rarely-visited page like this) between overburdening the server and accumulating a noticable error - some PC clocks drift quite fast.

Another point to note is the accuracy of the time on the web server. The server itself is synchronised to an accurate time standard but simply "asking it the time" will not result in a perfectly accurate answer, because of delays in the network, and the time taken for the server (and your computer) to process the data. When your computer establishes a 'formal' link with a time server (using the SNTP protocol) these delays are measured and compensated for. In my software, the much simpler act of saying, in JavaScript, "just remind me of the server time" is less accurate, but probably good enough for the intended purpose.

Copyright

This set of computer files is copyright David Gibson 1999 and 2013, where indicated. Design Right to this product, as set out in the Copyright, Designs and Patents Act 1988, is owned by David Gibson. Visit my Home Page.




This page, http://site2.caves.org.uk/clock/index.html was last modified on Sun, 09 Sep 2018 10:48:46 +0000
(Running on britiac3 at 31.25.186.126)