C#
C#

help

Root Question Message

CTJ
CTJ8/18/2022
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 bellow
Angius
Angius8/18/2022
new TimeSpan(3, 0, 5, 0)
Angius
Angius8/18/2022
days, hours, minutes, seconds
Doombox
Doombox8/18/2022
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
Doombox
Doombox8/18/2022
other than that, parsing "human" input is a whole load of work, there are pretty simple naive approaches but they break down kinda fast
CTJ
CTJ8/18/2022
Wow these look good according to github page
Doombox
Doombox8/18/2022
depending on what the scope of your input is though a naive parser of your own would be fine
CTJ
CTJ8/18/2022
Well, it will be used with discord bot to specify duration of ceartain action
CTJ
CTJ8/18/2022
abnd I want to make it as easy as possible to use
Doombox
Doombox8/18/2022
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
CTJ
CTJ8/18/2022
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
CTJ
CTJ8/18/2022
Yee thats the plan for now
Doombox
Doombox8/18/2022
I mean you could also accept !someCommand d:1 h:2 m:3 and then you can make a really simple parser
CTJ
CTJ8/18/2022
That could go too
CTJ
CTJ8/18/2022
Alright, ill try microsoft parser first and see how it turns out
CTJ
CTJ8/18/2022
if it fails I can alwys go to simpler solution
CTJ
CTJ8/18/2022
Thanks for help!
Doombox
Doombox8/18/2022
no worries, /close the thread when you're happy it's solved :sunglas:
CTJ
CTJ8/18/2022
Alright!
CTJ
CTJ8/18/2022
Epic
ContactFrequently Asked QuestionsJoin The DiscordBugs & Feature RequestsTerms & Privacy