clock manipulation in realtime

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

03-Mar-17 18:34
I work for an ambulance company and I would like to create a clock that I can manipulate to show the next available time we would be able to do a non-emergency pickup. The server and the client are all in the same location so we don't have to deal with time zones. Here is a list/idea of how I want it to work.

The time should always show as current time+1 hour (if we're able to round up to the nearest 15 minute integer that would be a bonus XX:15, XX:30, XX:45, XX:00)
It should update automatically (no need to refresh the page)
When the time is manipulated it should say that time until the current real life time reaches current time +1 hour (ex. It's now 1200, the time was manipulated to 1330. The clock will show 1330 until the time is 1231 at which time the clock will show as 1331.)

As far as how to manipulate the time, buttons that say +15 minutes, +30 minutes, +1 hour or a drop down menu of times with submit on the same page would work fine.

I've tried to track down something like this but I can't find anything. I've tried to mash a few scripts together but they don't work together for one reason or another.

Any help at all in trying to get this to work would be appreciated.
03-Mar-17 18:48
"I've tried to mash a few scripts together but they don't work together for one reason or another. "

Using what code

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
03-Mar-17 18:53
Have you read this ... http://www.elated.com/articles/creating-a-javascript-clock/ ... ?

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
04-Mar-17 09:07
I can create a clock, that is not the issue.

For the sake of argument let's say I used the coding that you posted. How do I then change what that clock shows on the client side and prevent it from continuing to count until it reaches current time +1 hour?
04-Mar-17 12:28
That article IS for a client side clock, written in javascript, and like any programming language, you periodically check the output data (called polling) and your code takes appropriate actions based on the values.

For example (pseudo-code)

read(x)
if (x==some value) then
do this
else
do something else
end


So if you need to synchronise all the network client clocks, set up a NTP (Network Time Protocol) synch on your server and have the read() function be an AJAX call to the server and read the time from a local URL.

However; to offer any advice we first need to know what code the server runs.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
04-Mar-17 13:53
You've given me plenty of advice. So far I have a clock that will updated automatically with AJAX/NTP.

If it makes it any easier I will try and show you the logic behind what I'm attempting to do.

read (time module)
if ((time module) > (current time+1hour)) -> show altered time
else
show (current time)+ 1 hour

if (button A) is press -> alter (time module) to AA:AA
if (button B) is press -> alter (time module) to BB:BB


If you're asking what code am I attempting to use to do this I don't even have one because I don't know how to code it. My knowledge of Javascript sucks and I'm trying to learn it to make this work.
04-Mar-17 15:48
"If you're asking what code am I attempting to use to do this I don't even have one because I don't know how to code it."

The problem there is; javascript is all client side and what one user does will not be reflected in what other users see. So you need some server code. Plus as this seems to be a "mission critical" operation, javascript is far from ideal to handle it.
javascript runs in a browser context and because js is single threaded it does NOT continually refresh a URL as it tends to run out of resources rather quickly and crash the browser.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
04-Mar-17 17:35
Okay if Javascript isn't the way, what code should I use to make this happen?

Would this code work for pulling newly altered content?


setInterval(function(){
$('#my_div').load('/path/to/server/source');
}, 2000) /* time in milliseconds (ie 2 seconds)*/


If so, what coding can I use to alter the content on the webpage without having to manually alter the code in an editor?
05-Mar-17 11:58
"If so, what coding can I use to alter the content on the webpage without having to manually alter the code in an editor?"

Assuming the time is coming from a server being accessed via HTTP you would use the standard method of POSTing 'form' values to a URL that updates the parameters the server system uses to generate the data.

You seem to be stuck with the idea that this has to be done via a browser context, which is only true when a system has to be 'publicly accessible', on many disparate system, whereas I would surmise this is a closed system that is only available to 'in-house' operators.

You cannot ask "what language should this be developed in" until you have defined ALL the operating parameters.

Personally I would avoid the browser idea simply because of this;

"It should update automatically (no need to refresh the page)"

This is not something that browsers do very well, simply because they are designed to operate via HTTP, which is what is known as a "disconnected protocol". Meaning that it operates without the client having to be connected to a server continuously. The way it works is that the client makes a GET request to the server, then waits until the correct number of bytes have been delivered (or a timeout occurs) then 'drops' the connection so no matter what happens on the server no more communication will occur until a new request is made such as being 'refreshed'. When you try to make javascript continually refresh (server polling) 'bad things happen', and within a few iterations the browser (and probably the computer) WILL become unresponsive in a rather short space of time.

Now in HTML5 there is a feature called "Server-Sent Events" also known as 'Push Notifications' (https://www.w3schools.com/html/html5_serversentevents.asp) which are probably of no use at all, because as per usual Microsoft are WAY behind the evolutionary process of the Internet and Infernet Exploder does NOT really support this currently.


Depending of what operating systems this application has to run on would define what language(s) you could actually use to poll the server and display the data. Plus given the reason for this you may have to meet certain legal requirements, and or regulatory body requirements for the operation.

Personally I would be looking at using a Python client (https://www.python.org/) and a PHP/MySQL server application. (http://php.net/ https://www.mysql.com/), but if your environment is M$ Windows you may have to use a DOT NET Framework client (https://www.microsoft.com/net).

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/
06-Mar-17 11:42
Thank you for the very thorough explanation of how to approach this. You are the first person to suggest anything helpful.

I'm using IIS on the server and I already have PHP/MySQL running for Mediawiki. Anything that can be run on IIS I'm open to trying. I've never used PHP and in the past I've only attempted javascript, if at all, for anything.

So you basically answered my original question of, "how do I make this happen?" Now I just need to figure out the coding and comeback to you guys if it works... or doesn't work.
06-Mar-17 15:49
Okay, sounds like you might be using ASP.NET then, this being the default framework for IIS

So http://www.tek-tips.com/threadminder.cfm?pid=855

And there are several languages supprted by the framework, VB.NET and C# (Csharp) being two of them.

http://www.tek-tips.com/threadminder.cfm?pid=796
http://www.tek-tips.com/threadminder.cfm?pid=732

You may need an account to access those links.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/

 
New posts
Old posts

Follow Elated