1
0
mirror of https://github.com/golang/go synced 2024-11-18 05:14:43 -07:00

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>
This commit is contained in:
Gabriel Russell 2016-08-23 08:31:26 -04:00 committed by Brad Fitzpatrick
parent 03723c909e
commit eb29ac7a7c
2 changed files with 3 additions and 0 deletions

View 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?

View 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) {