]> Cypherpunks repositories - gostls13.git/commitdiff
time: fix optional fractional seconds range err
authorGabriel Russell <gabriel.russell@gmail.com>
Tue, 23 Aug 2016 12:31:26 +0000 (08:31 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 23 Aug 2016 15:58:08 +0000 (15:58 +0000)
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>
src/time/format.go
src/time/format_test.go

index c2ae7930203814fc52b81e153e7ef7f2934ca5fa..18a73c45baf59285256a928e289e0eaf7a482da2 100644 (file)
@@ -844,6 +844,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
                        sec, value, err = getnum(value, std == stdZeroSecond)
                        if sec < 0 || 60 <= sec {
                                rangeErrString = "second"
+                               break
                        }
                        // Special case: do we have a fractional second but no
                        // fractional second in the format?
index 8c47dbcdd1cfe72739a8107d48e7eec96f702631..640e8180e39d4584996740fc46a701e098453bfa 100644 (file)
@@ -440,6 +440,8 @@ var parseErrorTests = []ParseErrorTest{
        {RFC3339, "2006-01-02T15:04_abc", `parsing time "2006-01-02T15:04_abc" as "2006-01-02T15:04:05Z07:00": cannot parse "_abc" as ":"`},
        {RFC3339, "2006-01-02T15:04:05_abc", `parsing time "2006-01-02T15:04:05_abc" as "2006-01-02T15:04:05Z07:00": cannot parse "_abc" as "Z07:00"`},
        {RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: _abc`},
+       // invalid second followed by optional fractional seconds
+       {RFC3339, "2010-02-04T21:00:67.012345678-08:00", "second out of range"},
 }
 
 func TestParseErrors(t *testing.T) {