1
0
mirror of https://github.com/golang/go synced 2024-10-03 23:21:22 -06:00
Commit Graph

18 Commits

Author SHA1 Message Date
Rob Pike
3cca069220 time: allow long fractions in ParseDuration
The code scanned for an integer after a decimal point, which
meant things could overflow if the number was very precise
(0.1234123412341234123412342134s). This fix changes the
parser to stop adding precision once we run out of bits, rather
than trigger an erroneous overflow.

We could parse durations using floating-point arithmetic,
but since the type is int64 and float64 has only has 53 bits
of precision, that would be imprecise.

Fixes #15011.

Change-Id: If85e22b8f6cef12475e221169bb8f493bb9eb590
Reviewed-on: https://go-review.googlesource.com/29338
Reviewed-by: Costin Chirvasuta <costinc@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-09-19 19:46:09 +00:00
Gabriel Russell
eb29ac7a7c time: fix optional fractional seconds range err
The optional fractional seconds overrides any range error
from the second parsing. Instead don't look for optional fractional
seconds if a range error has occured.

Change-Id: I27e0a2432740f6753668bd8833e48b9495bc4036
Reviewed-on: https://go-review.googlesource.com/27590
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-08-23 15:58:08 +00:00
Ian Lance Taylor
894803c11e time: document that RFC822/1123 don't parse all RFC formats
Fixes #14505.

Change-Id: I46196b26c9339609e6e3ef9159de38c5b50c2a1b
Reviewed-on: https://go-review.googlesource.com/23922
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2016-06-09 15:32:48 +00:00
Brad Fitzpatrick
5fea2ccc77 all: single space after period.
The tree's pretty inconsistent about single space vs double space
after a period in documentation. Make it consistently a single space,
per earlier decisions. This means contributors won't be confused by
misleading precedence.

This CL doesn't use go/doc to parse. It only addresses // comments.
It was generated with:

$ perl -i -npe 's,^(\s*// .+[a-z]\.)  +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.)  +([A-Z])')
$ go test go/doc -update

Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7
Reviewed-on: https://go-review.googlesource.com/20022
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Dave Day <djd@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02 00:13:47 +00:00
Russ Cox
e84dad3f6e time: restore old error text for day out of range
Go 1.5 and earlier said "day out of range".
As part of working on this code it morphed into "day of month out of range".
To avoid churn in the output restore the old text.

This fixes some tests reported privately.

Change-Id: If179676cd49f9a471a9441fec2f5220c85eb0799
Reviewed-on: https://go-review.googlesource.com/18386
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-01-08 03:15:20 +00:00
Russ Cox
39c3e0f642 time: document that RFC1123 is wrong for times in UTC
Fixes #13781.

Change-Id: Icfac8f2bfc3a4106f646409cfdc053df1e0cd76a
Reviewed-on: https://go-review.googlesource.com/18314
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2016-01-06 17:59:15 +00:00
Rob Pike
5ef899111e time: reject invalid day of month in Parse
There was back-and-forth on this but it has been decided to fix the original
complaint, which was easy.

Fixes #7268.

Change-Id: I6b607c49ad44579086aba2c4f4c5424b97fbed64
Reviewed-on: https://go-review.googlesource.com/17710
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
2015-12-10 19:12:13 +00:00
Ian Lance Taylor
3b3f422afe time: fix handling of -07, handle Z07
The existing code has partial support for -07 (just the hours of a time
zone offset).  Complete the support, add support for Z07, and add a few
tests.

Fixes #13426.

Change-Id: Ic6377bbf3e65b4bb761b9779f7e80c07ce4f57e8
Reviewed-on: https://go-review.googlesource.com/17260
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-12-02 01:35:09 +00:00
Edward Muller
f4b4d2f4d9 time: _2006 is a literal _, followed by 2006
Otherwise _2006 is treated as _2 and then an error.

Fixes #11334

Change-Id: I40a385b45e279e9f4538bf419baab72781cdb215
Reviewed-on: https://go-review.googlesource.com/16311
Reviewed-by: Rob Pike <r@golang.org>
2015-11-18 00:06:39 +00:00
Rob Pike
8b96be15f6 time: allow any one- or two-digit day of the month when parsing.
In Parse, one can now say Feb 31 or even Feb 99. This is easy
to explain, consistent with time.Date, and even maybe useful.

Fixes #12333.
Fixes #7268. (By disagreeing with it.)

Change-Id: I7b95c842528bed66933681c8b9cc00640fccfcb4
Reviewed-on: https://go-review.googlesource.com/14123
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-09-10 20:27:53 +00:00
Marvin Stenger
c12e38aa04 time: fixed handling of "5" in Format's layout string
Fixes #12440

Change-Id: Iead77fe34d986cfd5c16bac671fe13c8d012a754
Reviewed-on: https://go-review.googlesource.com/14178
Reviewed-by: Rob Pike <r@golang.org>
2015-09-09 18:41:34 +00:00
Rob Pike
47f22ab775 time: make it clearer how to format a fractional second
Fixes #10963.

Change-Id: I8d769b4d25b306f2df41f882ec01d97bbd63171d
Reviewed-on: https://go-review.googlesource.com/12221
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
2015-07-15 05:13:05 +00:00
Caleb Spare
35bda67d87 time: add Time.AppendFormat
This is a version of Time.Format that doesn't require allocation.

This is an updated version of 0af302f507
submitted by @bradfitz which was later rolled back.

Fixes #5192
Updates #5195

Change-Id: I4e6255bee1cf3914a6cc8d9d2a881cfeb273c08e
Reviewed-on: https://go-review.googlesource.com/1760
Reviewed-by: Rob Pike <r@golang.org>
2015-04-10 20:18:22 +00:00
Martin Möhrmann
d5ef698142 time: unify formatting of decimals for timestamps
Change function appendUint to appendInt with variable-width 0-padding.

This allows the decimal for the year to be generated without extra code
to handle the wider padding and directly handles negative numbers.

Removes the special casing for numbers with one and two digits.
The special case for 0 was unreachable.

The new version is slightly slower.

benchmark              old ns/op     new ns/op     delta
BenchmarkFormat        444           454           +2.25%
BenchmarkFormatNow     398           415           +4.27%

Change-Id: I4ddef96bf07ad35dca76053321d510441ec6d4f5
Reviewed-on: https://go-review.googlesource.com/2751
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-04-08 16:17:22 +00:00
Rob Pike
8537ccdd7f time: add a thorough example for time.Format
People will still not look at it, but at least we will have a stronger defense.

Change-Id: Ieea6a3d42d06e1067e424e35b87dbcb01c9523cb
Reviewed-on: https://go-review.googlesource.com/7859
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2015-03-26 18:44:42 +00:00
Josh Bleecher Snyder
2adc4e8927 all: use "reports whether" in place of "returns true if(f)"
Comment changes only.

Change-Id: I56848814564c4aa0988b451df18bebdfc88d6d94
Reviewed-on: https://go-review.googlesource.com/7721
Reviewed-by: Rob Pike <r@golang.org>
2015-03-18 15:14:06 +00:00
Martin Möhrmann
d1210acffd time: correctly parse large input durations and avoid precision loss
Do not lose precision for durations specified without fractions
that can be represented by an int64 such as 1<<53+1 nanoseconds.
Previously there was some precision lost in floating point conversion.

Handle overflow for durations above 1<<63-1 nanoseconds but not earlier.

Add tests to cover the above cases.

Change-Id: I4bcda93cee1673e501ecb6a9eef3914ee29aecd2
Reviewed-on: https://go-review.googlesource.com/2461
Reviewed-by: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2015-01-15 00:15:58 +00:00
Russ Cox
c007ce824d build: move package sources from src/pkg to src
Preparation was in CL 134570043.
This CL contains only the effect of 'hg mv src/pkg/* src'.
For more about the move, see golang.org/s/go14nopkg.
2014-09-08 00:08:51 -04:00