I am using the `kotlin.time.Duration` concept in m...
# announcements
y
I am using the
kotlin.time.Duration
concept in my code and see that I can convert to
String
pretty easily. I am not seeing a way to go the other way around, which makes it quite hard to use it as a field in a form or to save/retrieve in preferences... Am I missing something?
y
your best bet is to use something like
toLongMilliseconds()
, save that, and then when you retrieve it do a
.milliseconds
on that long value to retrieve it as a milliseconds value.
y
that works to save/read.. but that is super user unfriendly (please convert 1h15m in milliseconds before entering the value...)
y
Oh so you mean like the pretty
toString
function? hmmm one second I'm gonna take a look at that source code and see what can be done
For user input you should probably use something like a DateTimePicker like the Material components one. I'm saying this because looking at the toString code it's probably too complicated and error-prone to use for user input, especially because user input usually just cannot be trusted.
y
ok thank you. I will take a look at this
i
We have
Duration.parse
function in mind, so I've opened https://youtrack.jetbrains.com/issue/KT-45325 to track this feature request.
👍 1
y
Sounds great thank you