Forum Discussion

Astroraf's avatar
Astroraf
Data Pipeline
08-14-2024
Solved

How to display the Second difference in an indicator widget in hh:mm:ss?

I have an indicator widget where my formula in the indicator widget goes as follows:

SUM(SDiff([Hours in pickup_datetime],[Hours in dropoff_datetime]))

I want the widget to display the difference in hh:mm:ss seconds. Is there a way to do this in the script editor? 

 

 

DRay intapiuser 

  • This is from an old post but this seems to have worked for me utilizing this code. Would love to see if this works for other people to confirm. 

     

     

    widget.on('processresult', function (s,e){

    function convertRawTime(num){

    var sign = num < 0 ? '-' : '';
    var hours = (parseInt( Math.abs(num) / 3600 )%24);
    var minutes = parseInt( Math.abs(num) / 60 )%60;
    var seconds = parseInt( Math.abs(num) % 60);

    var hoursText = hours < 10 ? "0" + hours : hours;
    var minutesText = minutes < 10 ? "0" + minutes : minutes;
    var secondsText = seconds < 10 ? "0" + seconds : seconds;
    if (hours==0){
    var secondsText = seconds < 10 ? "0" + seconds : seconds;
    return sign + minutes + ":" + secondsText
    } else {
    var hoursText = hours < 10 ? "0" + hours : hours;
    var minutesText = minutes < 10 ? "0" + minutes : minutes;
    var secondsText = seconds < 10 ? "0" + seconds : seconds;
    return sign + hoursText + ":" + minutesText + ":" + secondsText

    }
    };

    // update the primary indicator
    e.result.value.text=convertRawTime(e.result.value.data);

    // update the secondary indicator, if there is one
    if (e.result.hasOwnProperty('secondary')) {
    e.result.secondary.text=convertRawTime(e.result.secondary.data);
    }

    });

     

1 Reply

  • Astroraf's avatar
    Astroraf
    Data Pipeline

    This is from an old post but this seems to have worked for me utilizing this code. Would love to see if this works for other people to confirm. 

     

     

    widget.on('processresult', function (s,e){

    function convertRawTime(num){

    var sign = num < 0 ? '-' : '';
    var hours = (parseInt( Math.abs(num) / 3600 )%24);
    var minutes = parseInt( Math.abs(num) / 60 )%60;
    var seconds = parseInt( Math.abs(num) % 60);

    var hoursText = hours < 10 ? "0" + hours : hours;
    var minutesText = minutes < 10 ? "0" + minutes : minutes;
    var secondsText = seconds < 10 ? "0" + seconds : seconds;
    if (hours==0){
    var secondsText = seconds < 10 ? "0" + seconds : seconds;
    return sign + minutes + ":" + secondsText
    } else {
    var hoursText = hours < 10 ? "0" + hours : hours;
    var minutesText = minutes < 10 ? "0" + minutes : minutes;
    var secondsText = seconds < 10 ? "0" + seconds : seconds;
    return sign + hoursText + ":" + minutesText + ":" + secondsText

    }
    };

    // update the primary indicator
    e.result.value.text=convertRawTime(e.result.value.data);

    // update the secondary indicator, if there is one
    if (e.result.hasOwnProperty('secondary')) {
    e.result.secondary.text=convertRawTime(e.result.secondary.data);
    }

    });