Using the duration data type?

Hello, I want to implement a variable containing a time period with no real time frame, e.g a variable that could store “two months”, “one and a half year” or “two months, tree days” without defining dates. I therefore wanted to use the duration data type, but im unable to convert int to duration using a function or value processing. I think im not able to use the library related to duration (day.js) at all as i cannot import it? Is this coming in the future? I would love to use the slider with this datatype as well. If this datatype is not available to use yet, i would love any tips on how to implement this in any other way. :smiley:

1 Like

Hi Selma and welcome to the community.

The Duration type takes a value in milliseconds as it’s input.
In your case, it might be possible to have the user input an integer (e.g. amount of hours, minutes, etc.) then update the duration field with the correct values.

E.g. if the user inputs 2 hours, then you’d have to do 2 * 1000 * 60 * 60

function hoursToMs(hours) {
 return hours * (1000 * 60 * 60);
}

This will return the duration of 2 hours in milliseconds. You can then update the duration field with this value to get the correct duration.

Remember to use the value processor to format the Duration to make it more human readable.