aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Hencke <robert.hencke@gmail.com>2012-04-16 11:56:37 +1000
committerRob Pike <r@golang.org>2012-04-16 11:56:37 +1000
commit65904a75bcc1e814bf4ff4329515f960a0f1b79d (patch)
tree8770ac91e2f48f0272176b50b71588c68b1de264
parentad0c81b124a021cc401da0ae1bfe274ac9c792c9 (diff)
downloadgo-65904a75bcc1e814bf4ff4329515f960a0f1b79d.tar.gz
go-65904a75bcc1e814bf4ff4329515f960a0f1b79d.zip
[release-branch.go1] time: parse fractional second with single digit
««« backport 99292bad0d6d time: parse fractional second with single digit Fixes #3487. R=golang-dev, r CC=golang-dev https://golang.org/cl/6011050 »»»
-rw-r--r--src/pkg/time/format.go2
-rw-r--r--src/pkg/time/time_test.go1
2 files changed, 2 insertions, 1 deletions
diff --git a/src/pkg/time/format.go b/src/pkg/time/format.go
index 98d4bb5c65..efca3a9269 100644
--- a/src/pkg/time/format.go
+++ b/src/pkg/time/format.go
@@ -714,7 +714,7 @@ func Parse(layout, value string) (Time, error) {
}
// Special case: do we have a fractional second but no
// fractional second in the format?
- if len(value) > 2 && value[0] == '.' && isDigit(value, 1) {
+ if len(value) >= 2 && value[0] == '.' && isDigit(value, 1) {
_, std, _ := nextStdChunk(layout)
if len(std) > 0 && std[0] == '.' && isDigit(std, 1) {
// Fractional second in the layout; proceed normally
diff --git a/src/pkg/time/time_test.go b/src/pkg/time/time_test.go
index fdff0ec36c..28047804e0 100644
--- a/src/pkg/time/time_test.go
+++ b/src/pkg/time/time_test.go
@@ -310,6 +310,7 @@ var parseTests = []ParseTest{
{"RFC1123", RFC1123, "Thu, 04 Feb 2010 21:00:57.01234 PST", true, true, 1, 5},
{"RFC1123Z", RFC1123Z, "Thu, 04 Feb 2010 21:00:57.01234 -0800", true, true, 1, 5},
{"RFC3339", RFC3339, "2010-02-04T21:00:57.012345678-08:00", true, false, 1, 9},
+ {"custom: \"2006-01-02 15:04:05\"", "2006-01-02 15:04:05", "2010-02-04 21:00:57.0", false, false, 1, 0},
// Amount of white space should not matter.
{"ANSIC", ANSIC, "Thu Feb 4 21:00:57 2010", false, true, 1, 0},
{"ANSIC", ANSIC, "Thu Feb 4 21:00:57 2010", false, true, 1, 0},