-
Notifications
You must be signed in to change notification settings - Fork 451
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 support for nanosecond precision when parsing rfc3339 strings #752
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No comment on the design yet, but adding public API normally suggests incrementing the minor version. In this case, I think it would need to bump to 1.4.0 in the pom.xml.
google-http-client/src/main/java/com/google/api/client/util/DateTime.java
Outdated
Show resolved
Hide resolved
google-http-client/src/main/java/com/google/api/client/util/DateTime.java
Outdated
Show resolved
Hide resolved
google-http-client/src/main/java/com/google/api/client/util/DateTime.java
Outdated
Show resolved
Hide resolved
Shouldn't that be 1.31.0? |
You're right. It should be 1.31.0 I get confused when version numbers hit double digits. :-) |
} | ||
|
||
/** A timestamp represented as the number of seconds and nanoseconds since Epoch. */ | ||
public static final class SecondsAndNanos implements Serializable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what our plans are for Java 8, but if we could use java.time I think we could avoid introducing this class and associated public API. @chingor13 has any final decision been made on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This library is very heavily used on android, so even if we move google-cloud-java to Java 8, we'd likely avoid using new features for a long time. java.time was introduced in Android at API level 26 (Oreo).
* </pre> | ||
*/ | ||
public void testParseRfc3339ToSecondsAndNanos() { | ||
Map<String, SecondsAndNanos> map = new HashMap<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it seems odd to collect these into a map to just iterate over them. We could implement a helper test assertion like assertParsedRdc3339(String, SecondsAndNanos)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point. I've changed the test case accordingly.
🤖 I have created a release \*beep\* \*boop\* --- ## [1.2.0](https://www.github.com/googleapis/google-auth-library-java/compare/v1.1.0...v1.2.0) (2021-09-30) ### Features * add support for Workforce Pools ([googleapis#729](https://www.github.com/googleapis/google-auth-library-java/issues/729)) ([5f3fed7](https://www.github.com/googleapis/google-auth-library-java/commit/5f3fed79e22f3c2d585c5b03c01791b0f8109929)) ### Bug Fixes * allow empty workforce_pool_user_project ([googleapis#752](https://www.github.com/googleapis/google-auth-library-java/issues/752)) ([e1cbce1](https://www.github.com/googleapis/google-auth-library-java/commit/e1cbce1a5cb269c6613bc6d40f06145bd45099c0)) * timing of stale token refreshes on ComputeEngine ([googleapis#749](https://www.github.com/googleapis/google-auth-library-java/issues/749)) ([c813d55](https://www.github.com/googleapis/google-auth-library-java/commit/c813d55a78053ecbec1a9640e6c9814da87319eb)) * workforce audience ([googleapis#741](https://www.github.com/googleapis/google-auth-library-java/issues/741)) ([a08cacc](https://www.github.com/googleapis/google-auth-library-java/commit/a08cacc7990b9058c8f1af3f9d8d816119562cc4)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
The original parseRfc3339 method of
DateTime
returns aDateTime
instance that has millisecond precision. The parse method therefore also disregards any time information beyond millisecond precision. For Spanner we would like to add nanosecond precision, and instead of replicating the parse method in the Spanner specific libraries, this change will add nanosecond support to this parse method, while retaining the original behavior of the parseRfc3339 method.The original parseRfc3339 method allows strings to contain more than millisecond precision. It does however not specify exactly what it does with any additional information, and the behavior is not consistent:
2018-12-31T23:59:59.9999Z
would be truncated to2018-12-31T23:59:59.999Z
2018-12-31T23:59:59.999999999Z
would be rounded up to2019-01-01T00:00:00Z
After this change the method will always truncate any time information beyond millisecond precision when returning a
DateTime
instance.