Skip to content

Commit eb29ac7

Browse files
gabrielrussellbradfitz
authored andcommitted
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 03723c9 commit eb29ac7

File tree

2 files changed

+3
-0
lines changed

2 files changed

+3
-0
lines changed

src/time/format.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,7 @@ func parse(layout, value string, defaultLocation, local *Location) (Time, error)
844844
sec, value, err = getnum(value, std == stdZeroSecond)
845845
if sec < 0 || 60 <= sec {
846846
rangeErrString = "second"
847+
break
847848
}
848849
// Special case: do we have a fractional second but no
849850
// fractional second in the format?

src/time/format_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,8 @@ var parseErrorTests = []ParseErrorTest{
440440
{RFC3339, "2006-01-02T15:04_abc", `parsing time "2006-01-02T15:04_abc" as "2006-01-02T15:04:05Z07:00": cannot parse "_abc" as ":"`},
441441
{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"`},
442442
{RFC3339, "2006-01-02T15:04:05Z_abc", `parsing time "2006-01-02T15:04:05Z_abc": extra text: _abc`},
443+
// invalid second followed by optional fractional seconds
444+
{RFC3339, "2010-02-04T21:00:67.012345678-08:00", "second out of range"},
443445
}
444446

445447
func TestParseErrors(t *testing.T) {

0 commit comments

Comments
 (0)