Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Hi, Everyone
I want to calculate the downtime status which shows in below image,
I am creating a program that has 'from_date and 'to_date' and their program so I want to display time status which is shown in the below image.
use case.
can you please help how can I do that,
I would say the best way to approach this is to generate the counter Server side - this does mean you need to know what time zone the user is in potentially.
A timer or scheduler runs and generates the appropriate number and using GetProperties push on update your information is pushed to the connected mashup.
Turning that around, you can use a Refresh timer on the mashup to call a service to get the latest number to display.
As a third option you might be able to do it with an expression as well
There isn't an OOTB countdown available.
So you have to calculate the time remaining from some initiating event.
You need to determine what you will use to start the countdown.
This could be the same scheduler/timer to check a calendar or a button on a mashup, or a change in information in the system.
I have created a thingworx service that calculates the downtime status but I am not getting actual time difference between date-time. please check the below code please correct me where I was wrong
var row ;
var milliseconds;
var d1 ;
var d2 ;
var date = new Date();
//var time = new Date();
var diff;
var timeINString;
// result: INFOTABLE dataShape: ""
var result = Things["PostgreSQL_DB"].getAllProgramList();
result.AddField({name : "difference", baseType : "STRING"});
var tableLength =result.rows.length;
for (var x=0; x < tableLength; x++) {
row = result.rows[x];
d1 = row.from_time;
d2 = date;
d3 = row.to_time;
// date1:DATETIME
var date1 = new Date();
// dateDifference(date1:DATETIME, date2:DATETIME):NUMBER
var timediiff = dateDifference(d1, date1);
// row.difference =timediiff;
var t = new Date(timediiff);
if (t.getHours() < 5 && t.getHours() > 1) {
row.difference ='start in'+ t.getHours() +' hours';
}else if(t.getMinutes() < 60 && t.getMinutes() > 1 ){
row.difference ='start in'+ t.getMinutes()+' minutes';
}else if(t.getSeconds() < 60 && t.getSeconds() < 1){
row.difference ='start in'+ t.getSeconds()+' second';
}else if(t <= row.from_time){
row.difference ='ON';
}else if(t > row.to_time){
row.difference ='OFF';
}
}
here is my output please check the program from_time and to_time and system current time.
The problem I am facing is a difference of two times(according to program) is not correctly shown in the difference column.
Example.
program id 54 will start on 2020-10-06 19:00:00.000 and the current time is 2020-10-06 18:37:10.382,
It means the program will start in 27minutes but the result in the different column showing 45 minutes.
I hope you get my point.please suggest me right way