Returns the current running time of the timer in [ms].
// This code prints the current running time to the consoleconstcurrTime=timeControl.getCurrentTime();console.log("currTime =", currTime);
Return
integer: time in [ms]
currTime=1234
setAllowBackwardsJump()
Due to a slow internet connection and/or network latency, clocks can jump backwards when starting, pausing, or restarting. Use the setAllowBackwardsJump() call to set this behavior.
Parameter
// This code avoids backwards jumpstimeControl.allowBackwardsJump(false);
Return
none
setIntervalTime()
Sets the interval frequency for the timer.
Parameter
// This code sets the interval frequency to 1000 [ms]consttInterval=1000;timeControl.setIntervalTime(tInterval );
Return
none
setOffsetToServerTime()
Sets the offset from the local browser to the Singular server time.
Parameter
// This code sets the offset to the Singular server time in [ms]consttOffset=876;timeControl.setOffsetToServerTime(tOffset);
Return
none
setRoundToInterval()
Rounds the time to the interval frequency.
Parameter
// This code sets the round-to-interval flagtimeControl.setRoundToInterval(true);
Return
none
setTimeControl()
The time control object defines the current timer state.
// This code shows examples of the time control objectconsttStart=Date.now();consttcStart= {"UTC": tStart,// set start time to current UTC time in [ms]"isRunning":true,// start timer"value":0// offset is 0};// .... laterconsttPause=Date.now();consttcPause= {"UTC": tPause,// set start time to current UTC time in [ms]"isRunning":false,// start false"value": tcPause - tcStart // offset is 0};// .... even laterconsttcContinue= {"UTC":Date.now(),// set start time to current UTC time in [ms]"isRunning":true,// start false"value": tcPause - tcStart // offset is 0};
Parameter
// This code starts the timertimeControl.setTimeControl(tcStart)(;
Return
none
setUpdateCallback()
Sets the time control callback function. This function is called at every interval.
Parameter
// The code below updates the timer callback functiontimeControl.setUpdateCallback(() => {console.log("elapsed time = %d[ms]",timeControl.getCurrentTime());// add your code here ...});
Return
none
let tControl = { UTC:0, isRunning:false, value: value};// The code below creates a timecontrol objectconsttimeControl=SingularWidget.createTimeControl();// set update callback functiontimeControl.setUpdateCallback(updateCallback);// this will stop the clock from jumping backwards when it is stopped. A jump// backwards can happen due to network latencytimeControl.setAllowBackwardsJump(false);// round the time to the interval frequencytimeControl.setRoundToInterval(true);// tell the timer control object how often to update the callbacktimeControl.setIntervalTime(100); //millisecondstimeControl.setTimeControl(tControl); // todo...constupdateCallback= () => {// get current timer valuelet currentTime =timeControl.getCurrentTime();console.log("currentTime = %d[ms]", currentTime);}