Convert string to duration

Hello community,
is there any nodes or WF I can use convert string 1,50 to duration PT1H30M etc?
for example:
0,93 --> PT56M
1,08 -->PT1H5M

Hi,

Here is my suggestion:

I splitted the hour and the minutes using the β€œ.” as the delimiter in β€œCell Splitter” node. (I assumed that your duration format is a double but you can change the settings to have β€œ,” as the delimiter) Then to avoid using several nodes, I prefered to use a β€œColumn Expressions” node with a somehow complex expression (or maybe it’s better to say nested expressions):
if (regexMatcher(column("column1"), ".*-.*")){
join("-", regexReplace(column("column1_Arr[0]"), "-",""), "H","-", regexReplace(round(60 * (toDouble(join("0.", regexReplace(column("column1_Arr[1]"), "-", "")))) / 100, 2), "(^[^1-9]*)", ""), "m")
}
else join(column("column1_Arr[0]"), "H", regexReplace(round(60 * (toDouble(join("0.", column("column1_Arr[1]")))) / 100, 2), "^[^1-9]*", ""), "m")
This expression creates the duration format.
Finally, we have a β€œString to Duration” node to convert the string column to the duration type.

Please check the workflow and let me know if it’s working as expected:
duration.knwf (20.2 KB)

Best,
Armin

2 Likes

Thank you!
Unfortunately I got error with negative data

image

I have edited the workflow (the expression for the Column Expressions node).
Now any negative value will be converted to negative duration (no matter the negative sign is at the beginning or at the end).
But I doubt whether it’s what you want or not.
Now the workflow will convert the values as shown below:
β€œ0.53-” => β€œ-32m”
β€œ1.08-” => β€œ-1H - 5m”
β€œ1.08” => β€œ1H 5m”

Is that what you want?

Thank you, will look on that,