TimeSpan formatter [Answered]
Hi, is there any function or library that would take an time length input, for example
5 min
or 3 days
and convert that to TimeSpan or other time durationm object?
kinda like js library in screenshot bellow13 Replies
new TimeSpan(3, 0, 5, 0)
days, hours, minutes, seconds
https://github.com/ti-ka/human-date-parser there's this (quite old) library which does something like that, https://github.com/microsoft/Recognizers-Text/ there's also this which seems to possibly do something similar, https://www.nuget.org/packages/Microsoft.Recognizers.Text.DateTime/ there is a discrete package just for that bit
other than that, parsing "human" input is a whole load of work, there are pretty simple naive approaches but they break down kinda fast
Wow these look good according to github page
depending on what the scope of your input is though a naive parser of your own would be fine
Well, it will be used with discord bot to specify duration of ceartain action
abnd I want to make it as easy as possible to use
actual human input is always a coin flip, I'd probably try one of these libraries and add enough user feedback so that people can figure it out
i saw that you can just poarse TImeSpan in form of 3:0:5:0 but I dont know if users will like this form
Yee thats the plan for now
I mean you could also accept
!someCommand d:1 h:2 m:3
and then you can make a really simple parserThat could go too
Alright, ill try microsoft parser first and see how it turns out
if it fails I can alwys go to simpler solution
Thanks for help!
no worries,
/close
the thread when you're happy it's solved Alright!
✅ This post has been marked as answered!
Epic