FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add support for nanosecond precision when parsing rfc3339 strings by olavloite · Pull Request #752 · googleapis/google-http-java-client · GitHub

Add support for nanosecond precision when parsing rfc3339 strings - #752

Merged
kolea2 merged 5 commits into
googleapis:masterfrom
olavloite:date-time-parse-nanosec
Jul 31, 2019
Merged

Add support for nanosecond precision when parsing rfc3339 strings#752
kolea2 merged 5 commits into
googleapis:masterfrom
olavloite:date-time-parse-nanosec

Conversation

Copy link
Copy Markdown
Contributor

The original parseRfc3339 method of DateTime returns a DateTime 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:

  • The input value 2018-12-31T23:59:59.9999Z would be truncated to 2018-12-31T23:59:59.999Z
  • The input value 2018-12-31T23:59:59.999999999Z would be rounded up to 2019-01-01T00:00:00Z

After this change the method will always truncate any time information beyond millisecond precision when returning a DateTime instance.

olavloite requested review from a team and kolea2 July 25, 2019 11:21
googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 25, 2019

elharo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

chingor13 added the semver: minor A new feature was added. No breaking changes. label Jul 25, 2019

Copy link
Copy Markdown
Contributor Author

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.

Shouldn't that be 1.31.0?

elharo commented Jul 26, 2019

Copy link
Copy Markdown
Contributor

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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<>();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

That's a good point. I've changed the test case accordingly.

kolea2 merged commit 1d496dc into googleapis:master Jul 31, 2019
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this pull request Aug 11, 2022
clundin25 pushed a commit to clundin25/google-http-java-client that referenced this pull request Aug 11, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement. semver: minor A new feature was added. No breaking changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL