summaryrefslogtreecommitdiff
path: root/src/time/format_test.go
diff options
context:
space:
mode:
authorZeke Lu <lvzecai@gmail.com>2022-11-17 12:19:49 +0000
committerGopher Robot <gobot@golang.org>2022-11-17 15:49:25 +0000
commit42d975e5fe91fbe7719422248ad320c04dda5414 (patch)
treedb5f85b4f9962681f3581e14c651914a17bee3ea /src/time/format_test.go
parentbed970b3ffa81cd43ce520bdc75113dd069f41ef (diff)
downloadgo-git-42d975e5fe91fbe7719422248ad320c04dda5414.tar.gz
time: avoid creating a parse error from the next chunk of the value
When it reports a parse error, it uses the "value" variable as the value element of the parse error. Previously, in some of the cases, the "value" variable is always updated to the next chunk of the value to be parsed (even if an earlier chunk is invalid). The reported parse error is confusing in this case. This CL addresses this issue by holding the original value, and when it fails to parse the time, use it to create the parse error. Fixes #56730. Change-Id: I445b1d8a1b910208d0608b2186881746adb550e0 GitHub-Last-Rev: 67b1102b5e9b345beb2ddcc529a8e608e5afc865 GitHub-Pull-Request: golang/go#56754 Reviewed-on: https://go-review.googlesource.com/c/go/+/450936 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Joedian Reid <joedian@golang.org> Auto-Submit: Bryan Mills <bcmills@google.com> Run-TryBot: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/time/format_test.go')
-rw-r--r--src/time/format_test.go22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/time/format_test.go b/src/time/format_test.go
index b1d85f510b..8a26eaa35b 100644
--- a/src/time/format_test.go
+++ b/src/time/format_test.go
@@ -620,13 +620,13 @@ type ParseErrorTest struct {
}
var parseErrorTests = []ParseErrorTest{
- {ANSIC, "Feb 4 21:00:60 2010", "cannot parse"}, // cannot parse Feb as Mon
- {ANSIC, "Thu Feb 4 21:00:57 @2010", "cannot parse"},
+ {ANSIC, "Feb 4 21:00:60 2010", `cannot parse "Feb 4 21:00:60 2010" as "Mon"`},
+ {ANSIC, "Thu Feb 4 21:00:57 @2010", `cannot parse "@2010" as "2006"`},
{ANSIC, "Thu Feb 4 21:00:60 2010", "second out of range"},
{ANSIC, "Thu Feb 4 21:61:57 2010", "minute out of range"},
{ANSIC, "Thu Feb 4 24:00:60 2010", "hour out of range"},
- {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59x01 2010", "cannot parse"},
- {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.xxx 2010", "cannot parse"},
+ {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59x01 2010", `cannot parse "x01 2010" as ".000"`},
+ {"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.xxx 2010", `cannot parse ".xxx 2010" as ".000"`},
{"Mon Jan _2 15:04:05.000 2006", "Thu Feb 4 23:00:59.-123 2010", "fractional second out of range"},
// issue 4502. StampNano requires exactly 9 digits of precision.
{StampNano, "Dec 7 11:22:01.000000", `cannot parse ".000000" as ".000000000"`},
@@ -641,8 +641,8 @@ var parseErrorTests = []ParseErrorTest{
// issue 54569
{RFC3339, "0000-01-01T00:00:.0+00:00", `parsing time "0000-01-01T00:00:.0+00:00" as "2006-01-02T15:04:05Z07:00": cannot parse ".0+00:00" as "05"`},
// issue 21113
- {"_2 Jan 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
- {"_2 January 06 15:04 MST", "4 --- 00 00:00 GMT", "cannot parse"},
+ {"_2 Jan 06 15:04 MST", "4 --- 00 00:00 GMT", `cannot parse "--- 00 00:00 GMT" as "Jan"`},
+ {"_2 January 06 15:04 MST", "4 --- 00 00:00 GMT", `cannot parse "--- 00 00:00 GMT" as "January"`},
// invalid or mismatched day-of-year
{"Jan _2 002 2006", "Feb 4 034 2006", "day-of-year does not match day"},
@@ -653,8 +653,14 @@ var parseErrorTests = []ParseErrorTest{
{RFC3339, "\"", `parsing time "\"" as "2006-01-02T15:04:05Z07:00": cannot parse "\"" as "2006"`},
// issue 54570
- {RFC3339, "0000-01-01T00:00:00+00:+0", `parsing time "0000-01-01T00:00:00+00:+0" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00"`},
- {RFC3339, "0000-01-01T00:00:00+-0:00", `parsing time "0000-01-01T00:00:00+-0:00" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00"`},
+ {RFC3339, "0000-01-01T00:00:00+00:+0", `parsing time "0000-01-01T00:00:00+00:+0" as "2006-01-02T15:04:05Z07:00": cannot parse "+00:+0" as "Z07:00"`},
+ {RFC3339, "0000-01-01T00:00:00+-0:00", `parsing time "0000-01-01T00:00:00+-0:00" as "2006-01-02T15:04:05Z07:00": cannot parse "+-0:00" as "Z07:00"`},
+
+ // issue 56730
+ {"2006-01-02", "22-10-25", `parsing time "22-10-25" as "2006-01-02": cannot parse "22-10-25" as "2006"`},
+ {"06-01-02", "a2-10-25", `parsing time "a2-10-25" as "06-01-02": cannot parse "a2-10-25" as "06"`},
+ {"03:04PM", "12:03pM", `parsing time "12:03pM" as "03:04PM": cannot parse "pM" as "PM"`},
+ {"03:04pm", "12:03pM", `parsing time "12:03pM" as "03:04pm": cannot parse "pM" as "pm"`},
}
func TestParseErrors(t *testing.T) {