-
Notifications
You must be signed in to change notification settings - Fork 653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unit parsing/pretty printing support for TimeAmount
#2504
Comments
The pretty printed version should probably just be |
Seems useful in the long tail so I wouldn't be opposed to this. We just need to agree on what formats we accept when parsing.
I think we should allow an optional space between number and unit and accept:
|
I really don't want us to get into the business of parsing textual time intervals. That way lies madness. I'm fine with us printing in somewhat nice formats, but the slippery feature slope here is very steep. Immediate follow-up questions:
I'm really reluctant to even start down this road. |
@glbrntt arbitrary spaces are already allowed @Lukasa The problem is that everybody then has to repeat this. We can put it into NIO extras but I really think we should have that. Your concerns are real but that can be solved by documentation where we document what we support. This isn't suggesting to add the one parsing function, it's merely suggesting to add one that you can use if you need specifically this. Happens often to me, unhappy that I have to C&P the code. |
Everyone who speaks English and only wants a specific set of letters. My problem here is that parsing time intervals from text is a general problem. If that problem is in scope, then it's actually in scope and we should try to solve it, but that does not involve this specific format. Documenting what we support doesn't prevent any of the actual problems, it just invites people to widen our support, unless we have a very clear concrete reason for why this format and only this format are supported in the library. |
Specifically it's not only this format. This would be one format. Just like |
So my question here is why should NIO define a custom format language for time units? Why is this not more properly part of Foundation or the Swift standard library? |
Because it's for |
Disclaimer: noob learning question, might be dumb.
So what if we made another step to remove the amount of code that covers general concerns in NIO, and replaced If that is viable so far, we could then have a small library with some regular time duration formats outside NIO, in one of the satellite support libraries that SSWG has, similar to If that is still viable, then we would probably have to add |
Yes, we can and will bump the Swift version and "optional" support isn't a problem even before that. However |
For what it's worth I also keep pasting around code doing such formating into every project we work on tbh. It'd definitely be worth adding in NIO. I don't agree that it suddenly becomes a localization issue. It's fine to have basic functionality and limit yourself to the "basic" version of it. Method names should be long "nanoseconds", formatting "ns" or the other short versions. Space or not in parsing either should be fine. |
FWIW I've always thought golang had good APIs around duration strings. I too have written some extensions to |
Please could we add this? I don't know how many times I've copy & pasted this already :| |
I frequently need to parse
500 ms
intoTimeAmount.milliseconds(500)
and also render.nanoseconds(17)
as17 ns
. So I usually have to write code akin toand I don't think I should have to write this. NIO should have it :).
The text was updated successfully, but these errors were encountered: