Skip to content
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

time: Parse with RFC3339Nano should accept nanoseconds #3523

Closed
rsc opened this issue Apr 13, 2012 · 2 comments
Closed

time: Parse with RFC3339Nano should accept nanoseconds #3523

rsc opened this issue Apr 13, 2012 · 2 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Apr 13, 2012

I think we should make 05.999 accept fractional
seconds the same way that 05 does.

---------- Forwarded message ----------
From: Jonathan Gold <jgold.bg@gmail.com>
Date: Wed, Apr 11, 2012 at 10:42
Subject: [go-nuts] Time parsing surprise -- worth a doc clarification?
To: golang-nuts@googlegroups.com

I was surprised to find that a string generated by time.Format() using layout
time.RFC3339Nano would not successfully parse using time.Parse() with that same
layout, but that it would parse using layout time.RFC3339 (sans "Nano").

After digging deeper into the docs though I understood why:

   // A decimal point followed by one or more zeros represents a fractional
   // second, printed to the given number of decimal places.  A decimal point
   // followed by one or more nines represents a fractional second, printed to
   // the given number of decimal places, with trailing zeros removed.
   // When parsing (only), the input may contain a fractional second
   // field immediately after the seconds field, even if the layout does not
   // signify its presence. In that case a decimal point followed by a maximal
   // series of digits is parsed as a fractional second.

So, I grant that the library is correct (and awesome!), but found it nontheless
counterintuitive in this regard.  Can I submit a patch to the docs above,
perhaps amending them something like:

   ...
   // signify its presence. In that case a decimal point followed by a maximal
   // series of digits is parsed as a fractional second.
   //
   // Note that this may lead to some subtle behaviors. In particular, a string
   // generated by time.Format() using some layout may not parse using that
   // same layout. For example, the layout time.RFC3339Nano uses the fractional
   // second specifier .999999999, which will generate a fractional string
   // .012345 for a time instance with 12345000 nanoseconds (note that trailing
   // zeroes are dropped), but this will not parse using that same layout.
   // It will however parse using time.RFC3339, which tolerates and correctly
   // parses the variable-length fraction string .012345.

jonathan
@robpike
Copy link
Contributor

robpike commented Jun 4, 2012

Comment 1:

http://code.google.com/p/go/source/detail?r=4f82ce08466d

Status changed to Fixed.

@ianlancetaylor
Copy link
Contributor

Comment 2:

Issue #4641 has been merged into this issue.

@rsc rsc added fixed labels Jan 11, 2013
@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants