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
Thank you!
Unfortunately I got error with negative data
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,