You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Golang's time.ParseDuration routine parses a very human-readable string format for duration values. This functionality was ported into the Abseil C++ library which makes it easy to consume the same duration strings in both C++ and Golang. Java does have support for Duration parsing to a java.time.Duration, but not in the same format. If the same routines were ported to Guava, then the same format could be used easily across all three languages.
Proposed API change:
packagecom.google.common.base;
importjava.time.Duration;
/** * Collection of utilities for working with duration and timestamp values with an emphasis on supporting * cross-language conventions. */publicfinalclassTime {
/** * Parses input {@code text} into a {@code java.time.Duration} using the duration format string * implemented in Golang's {@code time.ParseDuration} and Abseil C++ {@code time::ParseDuration} */publicstaticDurationparseDuration(CharSequencetext) {
...
}
}
Thanks. Internally, I notice that we have something like this in the internals of our flag-parsing library (though I notice that ours also supports days; oops...). But I don't see anything publicly accessible.
I do see an internal feature request (issue 132633641, for others at Google) to provide a public API for formatting durations. Parts of the discussion there suggest that we'd be sticking to the ISO 8601 "PT720H" format, but parts suggest that we'd consider something more like the golang/Abseil format.
The bigger question, though, is when/whether we are going to open-source even our existing utilities for java.time, whether into Guava or into another project. In the past, we've opened some feature requests (example) against ThreeTen-Extra. That project seems like the ideal home for such things. Now, I don't think we've absolutely ruled other approaches out. But I would definitely suggest starting there, especially because our team's major push on datetime work is in the past.
I have an implementation of this functionality that I've created for Google CEL (Issue
135933541), but I don't think it belongs in the CEL libraries. I'll follow up with ThreeTen-Extra to see if this is something they're willing to support.
Golang's
time.ParseDuration
routine parses a very human-readable string format for duration values. This functionality was ported into the Abseil C++ library which makes it easy to consume the same duration strings in both C++ and Golang. Java does have support for Duration parsing to ajava.time.Duration
, but not in the same format. If the same routines were ported to Guava, then the same format could be used easily across all three languages.Proposed API change:
For reference:
https://github.com/abseil/abseil-cpp/blob/9fde5a6eb081ea080f5aa895102a9154c3a2d09f/absl/time/time.h#L548
https://golang.org/pkg/time/#ParseDuration
The text was updated successfully, but these errors were encountered: