C
C#2y ago
CTJ

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
13 Replies
Angius
Angius2y ago
new TimeSpan(3, 0, 5, 0) days, hours, minutes, seconds
Doombox
Doombox2y ago
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
CTJ
CTJ2y ago
Wow these look good according to github page
Doombox
Doombox2y ago
depending on what the scope of your input is though a naive parser of your own would be fine
CTJ
CTJ2y ago
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
Doombox
Doombox2y ago
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
CTJ2y ago
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
Doombox
Doombox2y ago
I mean you could also accept !someCommand d:1 h:2 m:3 and then you can make a really simple parser
CTJ
CTJ2y ago
That 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!
Doombox
Doombox2y ago
no worries, /close the thread when you're happy it's solved sunglas
CTJ
CTJ2y ago
Alright!
Accord
Accord2y ago
✅ This post has been marked as answered!
CTJ
CTJ2y ago
Epic
Want results from more Discord servers?
Add your server
More Posts
How do you pass into a method a generic after you've reflected? [Answered]Suppose I suspect that this IEnumerable (non-generic) is also an IReadOnlyList<T> where T : struct. Signalr not sending message(s) to specific user(s)in the hub i have setup this signature for a method ```cs public async Task SendMessage(string sendRider line problemI'd moved to rider but a line make me angry, anybody can help me about how can I remove this?Is it possible to publish a WPF Application into a single file with the font inside of the EXE?Is it possible to publish a WPF Application into a single file with the font inside of the EXE?Binding to Dictionary in WPF with a binding KEYhello i have a very specific problem related to WPF : i have a listbox with itemsSource <ListBox Itset default value of parameter to other parameter [Answered]ok, i am aware that this is probably not possible, but can i set default value of parameter x to vaChecking if an arbitrary (remote) URL is a file attachment, and extracting it if it is? [Answered]If I'm given an arbitrary URL (I don't have control over it), how can I check if it appears to be a How does assigning default values when creating an instance work? [Answered]I'm not sure how to ask this question. I also can't for the life of me remember what this style of iProcess.EnableRaisingEvents does not work on WindowsI have an app that have 20 workers that are other processes. On production, on ubuntu, when I close Top-level statements in MSVSSay you've created a new project with top-level statements in MSVS. Is it possible to change it to *