Genesys Cloud (formerly PureCloud)

Discussion Thread View
Expand all | Collapse all

Convert second in minute seconde

Jump to Best Answer
  • 1.  Convert second in minute seconde

    Posted 01-26-2021 05:45
    Edited by Jeremy Monzo 01-26-2021 13:38
    Hello,

    I retrieve in a script a integer variable which contain a number of second (Ex :90).
    I would like convert this number of second in different format (Ex: MM:SS, it means  1:30).
    I have used dynamic variableand function from  math.js.
    I found the formula mod(90/60) which returns 30, But now I would like retrieve the integer part, it means 1 minute ( I found the formula round but it deosn't fit my requirement), we can use also the fucntion substr for retrieve the first caracter but it seems complex for my basic requirement.

    What is the simple way to achieve my requirement without create many different variable?
    thanks for your hints

    thanks
    jeremy
    #ArchitectureandDesign
    #Unsure/Other

    ------------------------------
    Jeremy
    ------------------------------


  • 2.  RE: Convert second in minute seconde

    GENESYS
    Posted 01-27-2021 06:49
    Hi Jeremy,

    If you are using Architect to set the Script that is popping you could set the variable for the script in Architect.

    Use the MakeDuration(Day,Hour,Min,Second) to convert your integer to a time. Because I was using a String variable in my script I used ToString(MakeDuration(0,0,0,90)). You would replace "90" with the variable you have containing the integer (value in seconds) to a time.

    When I pop the script I get the value coming through as PT1M30S, but you could use other String functions to split this down to properly display.

    Hope that helps,

    ------------------------------
    Craig Stevenson
    Genesys - Employees
    ------------------------------



  • 3.  RE: Convert second in minute seconde

    Posted 01-27-2021 07:01
    Hi Craig,

    Thanks for your feedback.

    In fact, the calculation of estimated wait time is executed in the script and not in the Architect flow, like this I can be most precise regarding the  estimated waiting time metric. Could I reuse the function ToString(MakeDuration(0,0,0,90)) or something equivalent  in the script?

    BR
    jeremy


    ------------------------------
    Jeremy
    ------------------------------



  • 4.  RE: Convert second in minute seconde

    GENESYS
    Posted 01-27-2021 07:25
    The Architect Expressions can't be used within a script. You would need to use a Dynamic variable like you are doing and work out a formula to use. For instance if you wanted to work out hours,  mins and seconds from an integer value that contained seconds you would need to follow a few steps and it might take a few different variables to do it.

    Let's say you had 8,274 seconds.

    First, find the number of whole hours

    8,274 seconds = 8,274 seconds ÷ 3,600
    8,274 seconds = 2.29833 hours
    full hours = 2

    Find the number of whole minutes

    minutes = .29833 hours × 60 minutes
    minutes = 17.9 minutes
    full minutes = 17

    Find the remaining seconds

    seconds = .9 minutes × 60 seconds
    seconds = 54 seconds

    Finish up by rewriting as HH:MM:SS

    time = 2:17:54

    If we put this same method onto your example of 90 seconds we would get:

    90 / 3600 = 0.025 (zero hours)
    0.025 (the decimal portion of the above result) * 60 = 1.5 (1 minute)
    0.5 (the decimal portion of the above result) *60 = 30 (seconds)

    So you would always take the integer part of the result as the time (hours, mins or secs) and use the decimal part on the next calculation.

    Using a Dynamic Variable, or a few dynamic variables this should be possible.

    Let me know if this doesn't make sense or you run into problems.


    ------------------------------
    Craig Stevenson
    Genesys - Employees
    ------------------------------



  • 5.  RE: Convert second in minute seconde

    Posted 01-27-2021 07:53
    Thanks Craig for your detailed explanation.

    "So you would always take the integer part of the result as the time (hours, mins or secs) and use the decimal part on the next calculation.", that's the key point, I have tried to found a function which enables to do this  from  math.js. but I didn't find.
    Besides, I have to optimize the way of achieve this result because I have to display the EWT for several in queue in the script.

    Jeremy


    ------------------------------
    Jeremy
    ------------------------------



  • 6.  RE: Convert second in minute seconde

    Posted 01-27-2021 08:02
    Craig,

    I think I found something interesting here : https://mathjs.org/docs/datatypes/units.html
    In the table there is the base : time for convert unit.

    BR
    jeremy

    ------------------------------
    Jeremy
    ------------------------------



  • 7.  RE: Convert second in minute seconde
    Best Answer

    GENESYS
    Posted 01-27-2021 08:49

    Hi Jeremy,
    I'm not sure Genesys Cloud supports that. The Dynamic Variable page on the Resource Centre states "selected Math.js expressions".

    I managed to get this to work.
    I created 3 Dynamic variables of the type Number. They are called Hours, Mins and Secs. I have a variable in my script named NumberToConvert.

    On Hours I have the expression: fix({{NumberToConvert}} / 3600)
    On Mins I have the expression: fix(({{NumberToConvert}} - ({{Hours}} * 3600) ) / 60)
    On Secs I have the expression: fix({{NumberToConvert}} - (({{Hours}} * 3600) + ({{Mins}} * 60)))

    I can then use those 3 variables to build the time the way I want to display it on my script. The "fix" function rounds the number down to the nearest integer.

    I think this might give you what you are looking for.



    ------------------------------
    Craig Stevenson
    Genesys - Employees
    ------------------------------



  • 8.  RE: Convert second in minute seconde

    Posted 01-28-2021 03:14
    Many Thanks Graig, the fix function is what I need.

    ------------------------------
    Jeremy
    ------------------------------