Page 1 of 1

Timer Extension

Posted: 09 Aug 2017, 20:05
by ketut
Hi all,

I wanna setup time so that it move like "watch". I try to use Timer Extension, but it fails. how to do that?

Best regards

Ketut

Re: Timer Extension

Posted: 14 Aug 2017, 17:38
by jeanmichel
Hi Ketut,

It will not be possible to query the date from the server every second. The easiest option is to read the date field by identifying it and naming it. You can then use the timer extension to +1 sec every second. So it's not the real time but it should be the same as on the server ....
Our recommendation implementing the above is following:

Name the date field as init_time.

Set the timer tick interval to 1000 (1 sec) and then put code below to ontick property

var stf = FIELDS('init_time');
var s = stf.getProperty('value');
console.log('from: input:' + s);
if ( !AXES._sdate ) {
AXES._sdate = new Date(s);
AXES._edate = new Date(AXES._sdate.valueOf() + 1000);
} else {
AXES._edate = new Date(AXES._edate.valueOf() + 1000);
}
var n = AXES._edate.toLocaleDateString()+ ' ' + AXES._edate.toLocaleTimeString();
console.log( n );
stf.setProperty('value',n);
stf.refresh();

here a reference for javascript date function if he need more date information. https://www.w3schools.com/jsref/jsref_obj_date.asp

Re: Timer Extension

Posted: 14 Aug 2017, 20:06
by ketut
Hi JM

is timer extension put directly to date field or I should add user field first?

regards
Ketut

Re: Timer Extension

Posted: 15 Aug 2017, 07:15
by jeanmichel
Hi Ketut,

You should add a user field first.