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
Add Duration.parse #16059
Comments
This comment was originally written by @seaneagan Would probably want to change Duration.toString() to match ISO-8601 or whatever format is chosen for Duration.parse. |
Added Area-Library, Library-Core, Triaged labels. |
Removed Type-Defect label. |
Issue #19891 has been merged into this issue. |
Yep, this would have been nice to have today. |
I also needed this today. |
Worked on this and added support for it in https://dart-review.googlesource.com/c/sdk/+/118566. |
I would like to have a |
@lohnn why was this never merged? Or, maybe better: what can I do to get it merged? |
I guess my PR just didn't get any attention. I can take a shot at updating it and then report back here. Then we can see what we need to do to get it merged? |
@lohnn Would definitely be useful!
static int _parseTime(String duration, String timeUnit) {
final timeMatch = RegExp('(\\d+)$timeUnit').firstMatch(duration);
if (timeMatch == null) {
return 0;
}
return int.parse(timeMatch.group(1));
}
|
I am definitely in favor of this, though I'm not sure what format it should parse. For my use case, Duration should be able to parse back the output of it's var d = const Duration(days: 1, hours: 1, minutes: 33, microseconds: 500);
print(d.toString()); // 25:33:00.000500 I can see the argument for using the ISO 8601 standard though, perhaps both should be implemented. |
This issue was originally filed by @seaneagan
Duration.parse based on ISO-8601 (like DateTime.parse) would be useful for things like command line options, configuration files, url parameters.
Java: http://download.java.net/jdk8/docs/api/java/time/Duration.html
Go has it's own formatting, which I like better, but is not standardized AFAIK: http://golang.org/pkg/time/#ParseDuration
The text was updated successfully, but these errors were encountered: